Skip to content

Commit

Permalink
Fixed deep linking
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Mar 4, 2024
1 parent dbd7432 commit 3348b9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions Xcode/BluetoothAccessory/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private extension AccessoryTabView {
}

func openURL(_ accessoryURL: AccessoryURL) {
print("Open URL \(accessoryURL)")
let accessory = accessoryURL.accessory
// check if accessory is already paired
let resolvedURL: AccessoryURL
Expand Down
18 changes: 11 additions & 7 deletions Xcode/BluetoothAccessoryKit/Views/List/AccessoriesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public struct AccessoriesView: View {

public init(url: Binding<AccessoryURL?>) {
_selection = Binding(get: {
return url.wrappedValue?.accessory
switch url.wrappedValue {
case let .accessory(id):
return id
default:
return nil
}
}, set: { newValue in
url.wrappedValue = newValue.flatMap { .accessory($0) }
})
Expand All @@ -44,10 +49,10 @@ public struct AccessoriesView: View {
List {
ForEach(accessories) { accessory in
NavigationLink(
isActive: isActiveBinding(for: accessory.id),
destination: {
AccessoryDetailView(accessory: accessory.id)
}, label: {
destination: AccessoryDetailView(accessory: accessory.id),
tag: accessory.id,
selection: $selection,
label: {
AccessoryRow(accessory: accessory)
}
)
Expand All @@ -69,8 +74,7 @@ private extension AccessoriesView {

func isActiveBinding(for destination: UUID) -> Binding<Bool> {
Binding(get: {
guard let selection = self.selection else { return false }
return destination == selection
return self.selection == destination
}, set: { isActive in
if isActive {
self.selection = destination
Expand Down

0 comments on commit 3348b9d

Please sign in to comment.