I am creating a home screen widget for iOS. On long press, you can edit the widget:
I've set up an IntentHandler
class and everything works great. The only thing that doesn't, is, that I cannot reset certain chosen configuration. For instance, below, List
is dependent on Workspace
(List is a child of Workspace), and if the user changes the Workspace
, I would like to reset the List
to nil. This is because some a specific list only exists in one workspace. Instead, if the user changes the workspace, the list stays the same, and because Show If Parent
is set to has any value
, it shows the same config, which is inaccurate.
I've tried showing/hiding the value based on a parent/child relationship, but since Workspace
is dynamic, I can only hide the child if parent has no value:
It doesn't allow me to hide the child if the parent property is equal to a certain value. (In my case, show list if list.workspaceID === workspace.id.
Is there any way to set this up? Or maybe programmatically update the widget extension value with some function I am unaware of?
class IntentHandler: INExtension, ConfigurationIntentHandling {
func provideTeamOptionsCollection(for intent: ConfigurationIntent, with completion: @escaping (INObjectCollection<Team>?, Error?) -> Void) {
RequestManager.getTeams() {
(response, error) in
if let response = response, let responseDictionary = response["response"] as? [JSONDictionary] {
let teams = responseDictionary.map { (team) -> Team in
return Team(identifier: (team["id"] as! String), display: team["name"] as! String)
}
let collection = INObjectCollection(items: teams)
completion(collection, nil)
}
}
}
func provideSubcategoryOptionsCollection(for intent: ConfigurationIntent, with completion: @escaping (INObjectCollection<SubCategory>?, Error?) -> Void) {
var subcategoryArray = [SubCategory]()
if let team = intent.team, let teamID = team.identifier {
RequestManager.getSubcategories(teamID: teamID, queryString: nil){
(response, error) in
if let response = response, let projects = response["projects"] as? [JSONDictionary] {
let subcategories = responseDictionary.map { (subcategory) -> Team in
return Sub(identifier: (subcategory["id"] as! String), display: subcategory["name"] as! String)
}
let collection = INObjectCollection(items: subcategoryArray)
completion(collection, nil)
}
}
}else{
let collection = INObjectCollection(items: subcategoryArray)
completion(collection, nil)
}
}
}