Skip to content

Commit a36551e

Browse files
Revises the onboarding UI
* Change the hardcoded regions data format to include `URL` and `CLLocationCoordinate2D` objects, so that we don't have to construct them manually later * Change the background color of the view to match the `List`'s background color * Use a built-in button style for the "Submit" button and change its title to "OK"
1 parent e78e83e commit a36551e

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

+42-46
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,32 @@ struct OnboardingView: View {
1111

1212
private let regions = [
1313
"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)
1716
],
1817
"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)
2220
],
2321
"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)
2724
]
2825
]
2926

3027
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()
3332
.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 {
4038
selectedRegion = key
41-
}) {
39+
} label: {
4240
HStack {
4341
Text(key)
4442
Spacer()
@@ -50,36 +48,34 @@ struct OnboardingView: View {
5048
}
5149
.foregroundColor(.primary)
5250
}
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)
8074
}
75+
.buttonStyle(BorderedProminentButtonStyle())
76+
.padding()
8177
}
82-
.padding()
78+
.background(Color(UIColor.systemGroupedBackground))
8379
}
8480
}
8581

0 commit comments

Comments
 (0)