Skip to content

Commit

Permalink
Add AccessoryTabView
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Mar 4, 2024
1 parent db6ca87 commit 681e253
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Xcode/BluetoothAccessory/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import BluetoothAccessoryKit

struct ContentView: View {

@EnvironmentObject
var store: AccessoryManager

var body: some View {
NavigationView {
NearbyDevicesView()
}
#if os(iOS)
AccessoryTabView()
#else
AccessoryTabView()
#endif
}
}

Expand Down
91 changes: 91 additions & 0 deletions Xcode/BluetoothAccessory/TabView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// TabView.swift
// BluetoothAccessoryApp
//
// Created by Alsey Coleman Miller on 3/4/24.
//

import SwiftUI
import SFSafeSymbols
import BluetoothAccessoryKit

struct AccessoryTabView: View {

@EnvironmentObject
var store: AccessoryManager

@State
var selection: TabItem?

var body: some View {
TabView(selection: $selection) {

// Devices
NavigationView {
AccessoriesView()
}
.tabItem { Label("Devices", systemSymbol: devicesTabSymbol) }
.tag(TabItem.devices)

#if DEBUG
// Nearby
NavigationView {
NearbyDevicesView()
}
.tabItem { Label("Nearby", systemSymbol: .antennaRadiowavesLeftAndRight) }
.tag(TabItem.nearby)
#endif

// Contacts
NavigationView {
EmptyView()
}
.tabItem { Label("Users", systemSymbol: .personCircle) }
.tag(TabItem.contacts)

// Settings
NavigationView {
EmptyView()
}
.tabItem { Label("Settings", systemSymbol: settingsTabSymbol) }
.tag(TabItem.settings)
}
.task {
try? await store.wait(for: .poweredOn)
}
}
}

internal extension AccessoryTabView {

enum TabItem {

case devices
case nearby
case contacts
case settings
}
}

private extension AccessoryTabView {

var devicesTabSymbol: SFSymbol {
if #available(iOS 16, *) {
return selection == .devices ? .sensor : .sensorFill
} else {
return selection == .devices ? .lightbulbFill : .lightbulb
}
}

var settingsTabSymbol: SFSymbol {
return selection == .settings ? .gearshape : .gearshapeFill
}
}

#if DEBUG
struct AccessoryTabView_Previews: PreviewProvider {
static var previews: some View {
AccessoryTabView()
}
}
#endif

0 comments on commit 681e253

Please sign in to comment.