Skip to content

Commit 0ec4b21

Browse files
committed
Fix toolbar safe area issue
1 parent 630e0d8 commit 0ec4b21

File tree

1 file changed

+58
-43
lines changed

1 file changed

+58
-43
lines changed

Shared/Samples/Augment reality to navigate route/AugmentRealityToNavigateRouteView.swift

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,57 +51,72 @@ struct AugmentRealityToNavigateRouteView: View {
5151
}
5252

5353
var body: some View {
54-
if isShowingRoutePlanner {
55-
RoutePlannerView(isShowing: $isShowingRoutePlanner)
56-
.onDidSelectRoute { routeGraphic, routeResult in
57-
self.routeResult = routeResult
58-
graphicsOverlay = makeRouteOverlay(
59-
routeResult: routeResult,
60-
routeGraphic: routeGraphic
61-
)
54+
if #available(iOS 16, *) {
55+
NavigationStack {
56+
augmentRealityToNavigateRouteView
57+
}
58+
} else {
59+
NavigationView {
60+
augmentRealityToNavigateRouteView
61+
}
62+
}
63+
}
64+
65+
@MainActor @ViewBuilder var augmentRealityToNavigateRouteView: some View {
66+
VStack(spacing: 0) {
67+
if isShowingRoutePlanner {
68+
RoutePlannerView(isShowing: $isShowingRoutePlanner)
69+
.onDidSelectRoute { routeGraphic, routeResult in
70+
self.routeResult = routeResult
71+
graphicsOverlay = makeRouteOverlay(
72+
routeResult: routeResult,
73+
routeGraphic: routeGraphic
74+
)
75+
}
76+
.task {
77+
try? await elevationSource.load()
78+
}
79+
} else {
80+
WorldScaleSceneView { _ in
81+
SceneView(scene: scene, graphicsOverlays: [graphicsOverlay])
82+
}
83+
.calibrationButtonAlignment(.bottomLeading)
84+
.onCalibratingChanged { isPresented in
85+
scene.baseSurface.opacity = isPresented ? 0.6 : 0
6286
}
6387
.task {
64-
try? await elevationSource.load()
88+
try? await locationDataSource.start()
89+
90+
for await location in locationDataSource.locations {
91+
try? await routeDataModel.routeTracker?.track(location)
92+
}
6593
}
66-
} else {
67-
WorldScaleSceneView { _ in
68-
SceneView(scene: scene, graphicsOverlays: [graphicsOverlay])
69-
}
70-
.calibrationButtonAlignment(.bottomLeading)
71-
.onCalibratingChanged { isPresented in
72-
scene.baseSurface.opacity = isPresented ? 0.6 : 0
73-
}
74-
.task {
75-
try? await locationDataSource.start()
76-
77-
for await location in locationDataSource.locations {
78-
try? await routeDataModel.routeTracker?.track(location)
94+
.overlay(alignment: .top) {
95+
Text(statusText)
96+
.multilineTextAlignment(.center)
97+
.frame(maxWidth: .infinity, alignment: .center)
98+
.padding(8)
99+
.background(.regularMaterial, ignoresSafeAreaEdges: .horizontal)
100+
}
101+
.onDisappear {
102+
Task { await locationDataSource.stop() }
79103
}
80104
}
81-
.overlay(alignment: .top) {
82-
Text(statusText)
83-
.multilineTextAlignment(.center)
84-
.frame(maxWidth: .infinity, alignment: .center)
85-
.padding(8)
86-
.background(.regularMaterial, ignoresSafeAreaEdges: .horizontal)
87-
}
88-
.toolbar {
89-
ToolbarItemGroup(placement: .bottomBar) {
90-
Button("Start") {
91-
isNavigating = true
92-
Task {
93-
do {
94-
try await startNavigation()
95-
} catch {
96-
print("Failed to start navigation.")
97-
}
105+
Divider()
106+
}
107+
.toolbar {
108+
ToolbarItemGroup(placement: .bottomBar) {
109+
Button("Start") {
110+
isNavigating = true
111+
Task {
112+
do {
113+
try await startNavigation()
114+
} catch {
115+
print("Failed to start navigation.")
98116
}
99117
}
100-
.disabled(isNavigating)
101118
}
102-
}
103-
.onDisappear {
104-
Task { await locationDataSource.stop() }
119+
.disabled(isNavigating)
105120
}
106121
}
107122
}

0 commit comments

Comments
 (0)