Closed emma-k-alexandra closed 4 years ago
That's a really neat idea and definitely where SwiftUI Router could shine. I am however wondering whether SwiftUI Router should be responsible for handling any NSUserActivity logic. I'd rather keep SwiftUI Router pretty basic (and abstract) so developers can build and attach their needs easily around it.
A possible way to use NSUserActivity is using onChange(of:)
while keeping an eye on HistoryData.path
:
struct RootView: View {
var body: some View {
Router {
ContentView()
}
}
}
struct ContentView: View {
@EnvironmentObject private var historyData: HistoryData
var body: some View {
Group {
// Routes etc.
}
.onChange(of: historyData.path) { newPath in
let activity = NSUserActivity()
activity.userInfo = ["path": newPath]
activity.becomeCurrent()
}
}
}
Thanks for your comment!
Very cool idea. Looking forward to seeing this project grow.
Since routes know exactly what the user is doing at any given time, it would be pretty awesome to have some automatic integration with NSUserActivity to provide apps using SwiftUIRouter with some low effort integration with Siri and such on platforms that support NSUserActivity