@@ -11,34 +11,32 @@ struct OnboardingView: View {
11
11
12
12
private let regions = [
13
13
" Puget Sound " : [
14
- " url " : " https://otp.prod.sound.obaweb.org/otp/routers/default/ " ,
15
- " lat " : 47.64585 ,
16
- " lon " : - 122.2963
14
+ " url " : URL ( string: " https://otp.prod.sound.obaweb.org/otp/routers/default/ " ) !,
15
+ " center " : CLLocationCoordinate2D ( latitude: 47.64585 , longitude: - 122.2963 )
17
16
] ,
18
17
" San Diego " : [
19
- " url " : " https://realtime.sdmts.com:9091/otp/routers/default/ " ,
20
- " lat " : 32.731591 ,
21
- " lon " : - 117.1896335
18
+ " url " : URL ( string: " https://realtime.sdmts.com:9091/otp/routers/default/ " ) !,
19
+ " center " : CLLocationCoordinate2D ( latitude: 32.731591 , longitude: - 117.1896335 )
22
20
] ,
23
21
" Tampa " : [
24
- " url " : " https://otp.prod.obahart.org/otp/routers/default/ " ,
25
- " lat " : 27.9769105 ,
26
- " lon " : - 82.445851
22
+ " url " : URL ( string: " https://otp.prod.obahart.org/otp/routers/default/ " ) !,
23
+ " center " : CLLocationCoordinate2D ( latitude: 27.9769105 , longitude: - 82.445851 )
27
24
]
28
25
]
29
26
30
27
var body : some View {
31
- VStack ( spacing: 20 ) {
32
- Text ( " Hello! Welcome to OTPKitDemo! " )
28
+ VStack {
29
+ Spacer ( minLength: 20 )
30
+ Text ( " Welcome to OTPKitDemo! " )
31
+ . bold ( )
33
32
. font ( . title)
34
-
35
- Text ( " Please choose your initial region. " )
36
- . font ( . subheadline)
37
-
38
- List ( Array ( regions. keys) , id: \. self) { key in
39
- Button ( action: {
33
+
34
+ Text ( " Please choose your region. " )
35
+
36
+ List ( Array ( regions. keys. sorted ( ) ) , id: \. self) { key in
37
+ Button {
40
38
selectedRegion = key
41
- } ) {
39
+ } label : {
42
40
HStack {
43
41
Text ( key)
44
42
Spacer ( )
@@ -50,36 +48,34 @@ struct OnboardingView: View {
50
48
}
51
49
. foregroundColor ( . primary)
52
50
}
53
- . frame ( height: 200 )
54
-
55
- Button ( action: {
56
- if let urlString = regions [ selectedRegion] ? [ " url " ] as? String ,
57
- let url = URL ( string: urlString) ,
58
- let latitude = regions [ selectedRegion] ? [ " lat " ] as? Double ,
59
- let longitude = regions [ selectedRegion] ? [ " lon " ] as? Double {
60
-
61
- selectedRegionURL = url
62
-
63
- print ( urlString)
64
- tripPlannerService = TripPlannerService (
65
- apiClient: RestAPI ( baseURL: url) ,
66
- locationManager: CLLocationManager ( ) ,
67
- searchCompleter: MKLocalSearchCompleter ( )
68
- )
69
-
70
- let locationCoordinate = CLLocationCoordinate2D ( latitude: latitude, longitude: longitude)
71
- tripPlannerService? . changeMapCamera ( to: locationCoordinate)
72
- hasCompletedOnboarding = true
73
- }
74
- } ) {
75
- Text ( " Submit " )
76
- . padding ( )
77
- . background ( Color . blue)
78
- . foregroundColor ( . white)
79
- . cornerRadius ( 10 )
51
+
52
+ Button {
53
+ let selection = regions [ selectedRegion] !
54
+
55
+ // swiftlint:disable force_cast
56
+ let url = selection [ " url " ] as! URL
57
+ let center = selection [ " center " ] as! CLLocationCoordinate2D
58
+ // swiftlint:enable force_cast
59
+
60
+ selectedRegionURL = url
61
+
62
+ tripPlannerService = TripPlannerService (
63
+ apiClient: RestAPI ( baseURL: url) ,
64
+ locationManager: CLLocationManager ( ) ,
65
+ searchCompleter: MKLocalSearchCompleter ( )
66
+ )
67
+
68
+ tripPlannerService? . changeMapCamera ( to: center)
69
+ hasCompletedOnboarding = true
70
+
71
+ } label: {
72
+ Text ( " OK " )
73
+ . frame ( maxWidth: . infinity, minHeight: 44 )
80
74
}
75
+ . buttonStyle ( BorderedProminentButtonStyle ( ) )
76
+ . padding ( )
81
77
}
82
- . padding ( )
78
+ . background ( Color ( UIColor . systemGroupedBackground ) )
83
79
}
84
80
}
85
81
0 commit comments