@@ -33,48 +33,70 @@ struct AddDynamicEntityLayerView: View {
3333 model. streamService. connectionStatus == . connected
3434 }
3535
36+ /// The horizontal size class of the environment.
37+ @Environment ( \. horizontalSizeClass) private var horizontalSizeClass
38+
39+ /// The vertical size class of the environment.
40+ @Environment ( \. verticalSizeClass) private var verticalSizeClass
41+
3642 var body : some View {
3743 // Creates a map view to display the map.
38- GeometryReader { geometry in
39- MapView ( map: model. map, viewpoint: viewpoint)
40- . contentInsets ( EdgeInsets ( top: 0 , leading: 0 , bottom: geometry. size. height / 2 , trailing: 0 ) )
41- . toolbar {
42- ToolbarItemGroup ( placement: . bottomBar) {
43- Button ( isConnected ? " Disconnect " : " Connect " ) {
44- Task {
45- if isConnected {
46- await model. streamService. disconnect ( )
47- } else {
48- try ? await model. streamService. connect ( )
49- }
44+ MapView ( map: model. map, viewpoint: viewpoint)
45+ . toolbar {
46+ ToolbarItemGroup ( placement: . bottomBar) {
47+ Button ( isConnected ? " Disconnect " : " Connect " ) {
48+ Task {
49+ if isConnected {
50+ await model. streamService. disconnect ( )
51+ } else {
52+ try ? await model. streamService. connect ( )
5053 }
5154 }
52- Spacer ( )
53- Button ( " Dynamic Entity Settings " ) {
54- isShowingSettings = true
55- }
56- . sheet ( isPresented: $isShowingSettings, detents: [ . medium] , dragIndicatorVisibility: . visible) {
57- SettingsView ( )
58- . environmentObject ( model)
59- }
6055 }
56+ Spacer ( )
57+ settingsSheet
6158 }
62- . overlay ( alignment: . top) {
63- HStack {
64- Text ( " Status: " )
65- Text ( model. connectionStatus)
66- . italic ( )
67- }
68- . frame ( maxWidth: . infinity)
69- . padding ( . vertical, 6 )
70- . background ( . thinMaterial, ignoresSafeAreaEdges: . horizontal)
59+ }
60+ . overlay ( alignment: . top) {
61+ HStack {
62+ Text ( " Status: " )
63+ Text ( model. connectionStatus)
64+ . italic ( )
7165 }
72- . task {
73- // This will update `connectionStatus` when the stream service
74- // connection status changes.
75- for await status in model. streamService. $connectionStatus {
76- model. connectionStatus = status. description
77- }
66+ . frame ( maxWidth: . infinity)
67+ . padding ( . vertical, 6 )
68+ . background ( . thinMaterial, ignoresSafeAreaEdges: . horizontal)
69+ }
70+ . task {
71+ // This will update `connectionStatus` when the stream service
72+ // connection status changes.
73+ for await status in model. streamService. $connectionStatus {
74+ model. connectionStatus = status. description
75+ }
76+ }
77+ }
78+
79+ @ViewBuilder private var settingsButton : some View {
80+ Button ( " Dynamic Entity Settings " ) {
81+ isShowingSettings = true
82+ }
83+ }
84+
85+ @ViewBuilder private var settingsSheet : some View {
86+ if #available( iOS 16 , * ) ,
87+ horizontalSizeClass == . compact,
88+ verticalSizeClass == . regular {
89+ settingsButton
90+ . sheet ( isPresented: $isShowingSettings) {
91+ SettingsView ( )
92+ . environmentObject ( model)
93+ . presentationDetents ( [ . fraction( 0.4 ) ] )
94+ }
95+ } else {
96+ settingsButton
97+ . sheet ( isPresented: $isShowingSettings, detents: [ . medium] ) {
98+ SettingsView ( )
99+ . environmentObject ( model)
78100 }
79101 }
80102 }
0 commit comments