Skip to content

Commit

Permalink
feat(iOS): elevator alert UI (#702)
Browse files Browse the repository at this point in the history
* feat(iOS): elevator alert UI

* update Android strings

* fix alert period display structure

* fix pre-Xcode 16 preview macro bug or whatever

i wish very much that Apple hadn't randomly broken Xcode 15 on macOS Sequoia
  • Loading branch information
boringcactus authored Jan 31, 2025
1 parent 8c0d050 commit 30bd4f7
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ class NearbyStopViewTest {
showElevatorAccessibility = true
)
}
composeTestRule.onNodeWithText("1 elevator closure").assertIsDisplayed()
composeTestRule.onNodeWithText("1 elevator closed").assertIsDisplayed()
}
}
6 changes: 3 additions & 3 deletions androidApp/src/main/res/values-b+es/strings_ios_converted.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<string name="eastbound">En dirección este</string>
<string name="electrical_work">Trabajo eléctrico</string>
<plurals name="elevator_closure_count">
<item quantity="one">%1$d cierre de ascensor</item>
<item quantity="many">%1$d cierres de ascensor</item>
<item quantity="other">%1$d cierres de ascensor</item>
<item quantity="one">%1$d ascensor cerrado</item>
<item quantity="many">%1$d ascensores cerrados</item>
<item quantity="other">%1$d ascensores cerrados</item>
</plurals>
<string name="end">Fin</string>
<string name="error_loading_data">Error al cargar datos</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<string name="eastbound">Sentido leste</string>
<string name="electrical_work">Obra elétrica</string>
<plurals name="elevator_closure_count">
<item quantity="one">%1$d fechamento de elevador</item>
<item quantity="many">%1$d fechamentos de elevador</item>
<item quantity="other">%1$d fechamentos de elevador</item>
<item quantity="one">%1$d elevador fechado</item>
<item quantity="many">%1$d elevadores fechados</item>
<item quantity="other">%1$d elevadores fechados</item>
</plurals>
<string name="end">Fim</string>
<string name="error_loading_data">Erro ao carregar dados</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<string name="eastbound">东行</string>
<string name="electrical_work">电力作业</string>
<plurals name="elevator_closure_count">
<item quantity="other">%1$d 电梯关闭</item>
<item quantity="other">%1$d部电梯关闭</item>
</plurals>
<string name="end">结束日期</string>
<string name="error_loading_data">加载数据时出错</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<string name="eastbound">東行</string>
<string name="electrical_work">電力作業</string>
<plurals name="elevator_closure_count">
<item quantity="other">%1$d 電梯關閉</item>
<item quantity="other">%1$d部電梯關閉</item>
</plurals>
<string name="end">結束日期</string>
<string name="error_loading_data">載入資料時發生錯誤</string>
Expand Down
4 changes: 2 additions & 2 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<string name="eastbound">Eastbound</string>
<string name="electrical_work">Electrical Work</string>
<plurals name="elevator_closure_count">
<item quantity="one">%1$d elevator closure</item>
<item quantity="other">%1$d elevator closures</item>
<item quantity="one">%1$d elevator closed</item>
<item quantity="other">%1$d elevators closed</item>
</plurals>
<string name="end">End</string>
<string name="error_loading_data">Error loading data</string>
Expand Down
29 changes: 22 additions & 7 deletions iosApp/iosApp/ComponentViews/AlertCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ struct AlertCard: View {
let onViewDetails: (() -> Void)?

@ScaledMetric var majorIconSize = 48
@ScaledMetric var elevatorIconSize = 28
@ScaledMetric var miniIconSize = 20
@ScaledMetric var infoIconSize = 16

var iconSize: Double {
switch spec {
case .major: majorIconSize
case .elevator: elevatorIconSize
default: miniIconSize
}
}
Expand All @@ -53,13 +55,15 @@ struct AlertCard: View {
@ViewBuilder
var card: some View {
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 16) {
AlertIcon(alertState: alert.alertState, color: color)
.frame(width: iconSize, height: iconSize)
.frame(maxHeight: spec == .elevator ? .infinity : iconSize, alignment: .top)
Text(headerString)
.font(spec == .major ? Typography.title2Bold : Typography.bodySemibold)
.multilineTextAlignment(.leading)
HStack {
HStack(alignment: .top, spacing: 16) {
AlertIcon(alertState: alert.alertState, color: color)
.scaledToFit()
.frame(width: iconSize, height: iconSize, alignment: .top)
Text(headerString)
.font(spec == .major ? Typography.title2Bold : Typography.bodySemibold)
.multilineTextAlignment(.leading)
}
if spec != .major {
Spacer()
InfoIcon(size: infoIconSize)
Expand Down Expand Up @@ -128,5 +132,16 @@ struct AlertCard: View {
)
.padding(32)
.background(Color.fill2)

AlertCard(
alert: ObjectCollectionBuilder.Single.shared.alert { alert in
alert.effect = .elevatorClosure
alert.header = "Ruggles elevator 321 (Orange Line Platform to lobby) unavailable due to maintenance"
},
spec: .elevator,
color: Color(hex: "ED8B00"), textColor: Color(hex: "FFFFFF"), onViewDetails: {}
)
.padding(32)
.background(Color.fill2)
}
}
33 changes: 25 additions & 8 deletions iosApp/iosApp/ComponentViews/AlertIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,40 @@ import SwiftUI
struct AlertIcon: View {
var alertState: StopAlertState
var color: Color
let elevatorClosureIcon: ElevatorClosureIconType

init(alertState: StopAlertState, color: Color? = nil) {
init(alertState: StopAlertState, color: Color? = nil, elevatorClosureIcon: ElevatorClosureIconType = .color) {
self.alertState = alertState
self.color = color ?? .text
self.elevatorClosureIcon = elevatorClosureIcon
}

private static let iconNames: [StopAlertState: String] = [
.elevator: "accessibility-icon-inaccessible",
.issue: "alert-borderless-issue",
.shuttle: "alert-borderless-shuttle",
.suspension: "alert-borderless-suspension",
]
private var iconName: String? {
switch alertState {
case .elevator: elevatorClosureIcon.iconName
case .issue: "alert-borderless-issue"
case .shuttle: "alert-borderless-shuttle"
case .suspension: "alert-borderless-suspension"
case .normal: nil
}
}

var body: some View {
Image(AlertIcon.iconNames[alertState] ?? "")
Image(iconName ?? "")
.resizable()
.foregroundStyle(color)
.accessibilityLabel(Text("Alert"))
}

enum ElevatorClosureIconType {
case color
case mono

var iconName: String {
switch self {
case .color: "accessibility-icon-alert"
case .mono: "accessibility-icon-alert-mono"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images": [
{
"filename": "elevator-alert-mono.svg",
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
},
"properties": {
"template-rendering-intent": "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images": [
{
"filename": "accessibility-icon-inaccessible.svg",
"filename": "elevator-alert-light.svg",
"idiom": "universal"
},
{
Expand All @@ -11,7 +11,7 @@
"value": "dark"
}
],
"filename": "accessibility-icon-inaccessible-dark.svg",
"filename": "elevator-alert-dark.svg",
"idiom": "universal"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

64 changes: 52 additions & 12 deletions iosApp/iosApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1099,23 +1099,22 @@
"%1$@ to %2$@ has departed %3$@" : {
"comment" : "Screen reader text that is announced when a trip disappears from the screen.,\nin the format \"[train/bus/ferry] to [destination] has departed [stop name]\",\nex. \"[train] to [Alewife] has departed [Central]\", \"[bus] to [Nubian] has departed [Harvard]\""
},
"%ld elevator closures" : {
"%ld elevators closed" : {
"comment" : "Header displayed when elevators are not working at a station",
"extractionState" : "manual",
"localizations" : {
"en" : {
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld elevator closure"
"state" : "translated",
"value" : "%ld elevator closed"
}
},
"other" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld elevator closures"
"state" : "translated",
"value" : "%ld elevators closed"
}
}
}
Expand All @@ -1127,13 +1126,13 @@
"one" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld cierre de ascensor"
"value" : "%ld ascensor cerrado"
}
},
"other" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld cierres de ascensor"
"value" : "%ld ascensores cerrados"
}
}
}
Expand Down Expand Up @@ -1181,13 +1180,13 @@
"one" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld fechamento de elevador"
"value" : "%ld elevador fechado"
}
},
"other" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld fechamentos de elevador"
"value" : "%ld elevadores fechados"
}
}
}
Expand All @@ -1211,7 +1210,7 @@
"other" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld 电梯关闭"
"value" : "%ld部电梯关闭"
}
}
}
Expand All @@ -1223,7 +1222,7 @@
"other" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%ld 電梯關閉"
"value" : "%ld部電梯關閉"
}
}
}
Expand Down Expand Up @@ -1655,6 +1654,47 @@
}
}
},
"Alternative path" : {
"comment" : "Header for the details of an elevator closure",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Camino alternativo"
}
},
"ht" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Chemen altènatif"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Caminho alternativo"
}
},
"vi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Đường dẫn thay thế"
}
},
"zh-Hans-CN" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "替代路径"
}
},
"zh-Hant-TW" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "替代路徑"
}
}
}
},
"Amtrak" : {
"comment" : "Possible alert cause",
"localizations" : {
Expand Down
Loading

0 comments on commit 30bd4f7

Please sign in to comment.