This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements `MSPeoplePicker` which is used to select personas by providing a list of `suggestedPersonas` in a `MSPersonaListView` under a badge field consisting of a text field which filters the `suggestedPersonas` and a list of badges which displays the list of `pickedPersonas`. The text field can filter the `availablePersonas` or the delegate method `getSuggestedPersonasFromText` can be implemented to provide the list of `suggestedPersonas`. Once picked the personas will be displayed as an `MSBadgeView` which can be interacted with and removed. - Updates to `MSBadgeField` included to make it work better with `MSPeoplePicker`. This includes the delegate not being required since `MSPeoplePicker` when set up with sufficient data will function as intended without most delegate methods implemented, making them optional. - Small updates to `MSBadgeField` demo and clean up in `MSPersonaListView` demo.  Related work items: #663382
- Loading branch information
1 parent
5682636
commit 04dc7e7
Showing
17 changed files
with
679 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
OfficeUIFabric.Demo/OfficeUIFabric.Demo/Demos/MSPeoplePickerDemoController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import OfficeUIFabric | ||
import UIKit | ||
|
||
// MARK: PeoplePickerSampleData | ||
|
||
class PeoplePickerSampleData { | ||
struct Variant { | ||
let description: String | ||
let numberOfLines: Int | ||
let pickedPersonas: [MSPersona] | ||
let allowsPickedPersonasToAppearAsSuggested: Bool | ||
let showsSearchDirectoryButton: Bool | ||
|
||
init(description: String, numberOfLines: Int = 0, pickedPersonas: [MSPersona] = [], allowsPickedPersonasToAppearAsSuggested: Bool = true, showsSearchDirectoryButton: Bool = true) { | ||
self.description = description | ||
self.numberOfLines = numberOfLines | ||
self.pickedPersonas = pickedPersonas | ||
self.allowsPickedPersonasToAppearAsSuggested = allowsPickedPersonasToAppearAsSuggested | ||
self.showsSearchDirectoryButton = showsSearchDirectoryButton | ||
} | ||
} | ||
|
||
static let variants: [Variant] = [ | ||
Variant(description: "Standard implementation with one line of picked personas", numberOfLines: 1, pickedPersonas: [samplePersonas[0], samplePersonas[4], samplePersonas[11], samplePersonas[14]]), | ||
Variant(description: "Doesn't allow picked personas to appear as suggested", pickedPersonas: [samplePersonas[0], samplePersonas[9]], allowsPickedPersonasToAppearAsSuggested: false), | ||
Variant(description: "Hides search directory button", pickedPersonas: [samplePersonas[13]], showsSearchDirectoryButton: false), | ||
Variant(description: "Includes callback when picking a suggested persona") | ||
] | ||
} | ||
|
||
// MARK: - MSPeoplePickerDemoController | ||
|
||
class MSPeoplePickerDemoController: DemoController { | ||
var peoplePickers: [MSPeoplePicker] = [] | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
for (index, variant) in PeoplePickerSampleData.variants.enumerated() { | ||
addDescription(text: variant.description) | ||
addPeoplePicker(for: variant) | ||
if index != PeoplePickerSampleData.variants.count - 1 { | ||
container.addArrangedSubview(MSSeparator()) | ||
} | ||
} | ||
} | ||
|
||
func addPeoplePicker(for variant: PeoplePickerSampleData.Variant) { | ||
let peoplePicker = MSPeoplePicker() | ||
peoplePicker.label = "Send to:" | ||
peoplePicker.availablePersonas = samplePersonas | ||
peoplePicker.pickedPersonas = variant.pickedPersonas | ||
peoplePicker.showsSearchDirectoryButton = variant.showsSearchDirectoryButton | ||
peoplePicker.numberOfLines = variant.numberOfLines | ||
peoplePicker.allowsPickedPersonasToAppearAsSuggested = variant.allowsPickedPersonasToAppearAsSuggested | ||
peoplePicker.showsSearchDirectoryButton = variant.showsSearchDirectoryButton | ||
peoplePicker.delegate = self | ||
peoplePickers.append(peoplePicker) | ||
container.addArrangedSubview(peoplePicker) | ||
} | ||
} | ||
|
||
// MARK: - MSPeoplePickerDemoController: MSPeoplePickerDelegate | ||
|
||
extension MSPeoplePickerDemoController: MSPeoplePickerDelegate { | ||
func peoplePicker(_ peoplePicker: MSPeoplePicker, personaFromText text: String) -> MSPersona { | ||
return samplePersonas.first { return $0.name.lowercased() == text.lowercased() } ?? MSPersonaData(name: text) | ||
} | ||
|
||
func peoplePicker(_ peoplePicker: MSPeoplePicker, personaIsValid persona: MSPersona) -> Bool { | ||
let availablePersonas = samplePersonas + searchDirectoryPersonas | ||
return availablePersonas.contains { $0.name == persona.name } | ||
} | ||
|
||
func peoplePicker(_ peoplePicker: MSPeoplePicker, didPickPersona persona: MSPersona) { | ||
if peoplePicker == peoplePickers.last { | ||
showMessage("\(persona.name) was picked") | ||
} | ||
} | ||
|
||
func peoplePicker(_ peoplePicker: MSPeoplePicker, didTapSelectedPersona persona: MSPersona) { | ||
peoplePicker.badge(for: persona)?.isSelected = false | ||
showMessage("\(persona.name) was tapped") | ||
} | ||
|
||
func peoplePicker(_ peoplePicker: MSPeoplePicker, searchDirectoryWithCompletion completion: @escaping ([MSPersona], Bool) -> Void) { | ||
// Delay added for 2 seconds to demo activity indicator | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
let text = peoplePicker.textFieldContent.lowercased() | ||
let personas = searchDirectoryPersonas.filter { $0.name.lowercased().contains(text) } | ||
completion(personas, true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ let samplePersonas: [MSPersonaData] = [ | |
MSPersonaData(name: "Cecil Folk", subtitle: "Program Manager", avatarImage: UIImage(named: "avatar_cecil_folk")) | ||
] | ||
|
||
let searchDirectoryPersonas: [MSPersonaData] = [ | ||
MSPersonaData(name: "Celeste Burton", email: "[email protected]", subtitle: "Program Manager", avatarImage: UIImage(named: "avatar_celeste_burton")), | ||
MSPersonaData(name: "Erik Nason", email: "[email protected]", subtitle: "Designer"), | ||
MSPersonaData(name: "Miguel Garcia", email: "[email protected]", subtitle: "Software Engineer", avatarImage: UIImage(named: "avatar_miguel_garcia")) | ||
] | ||
|
||
class MSPersonaListViewDemoController: DemoController { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
@@ -61,12 +67,7 @@ extension MSPersonaListViewDemoController: MSPersonaListViewSearchDirectoryDeleg | |
func personaListSearchDirectory(_ personaListView: MSPersonaListView, completion: @escaping ((_ success: Bool) -> Void)) { | ||
// Delay added for 2 seconds to demo activity indicator | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
let personas: [MSPersona] = [ | ||
MSPersonaData(name: "Celeste Burton", email: "[email protected]", subtitle: "Program Manager", avatarImage: UIImage(named: "avatar_celeste_burton")), | ||
MSPersonaData(name: "Erik Nason", email: "[email protected]", subtitle: "Designer"), | ||
MSPersonaData(name: "Miguel Garcia", email: "[email protected]", subtitle: "Software Engineer", avatarImage: UIImage(named: "avatar_miguel_garcia")) | ||
] | ||
personaListView.personaList = personas | ||
personaListView.personaList = searchDirectoryPersonas | ||
completion(true) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.