Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic type sizes and longer timeout for required account modifier #51

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
runsonlabels: '["macOS", "self-hosted"]'
path: 'Tests/UITests'
scheme: TestApp
setupSimulators: true
uploadcoveragereport:
name: Upload Coverage Report
needs: [buildandtest, buildandtestuitests]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation.git", from: "1.0.0"),
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.0.0"),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.0.0"),
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.2.0"),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.3.0"),
.package(url: "https://github.com/StanfordBDHG/XCTRuntimeAssertions", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4")
],
Expand Down
3 changes: 2 additions & 1 deletion Sources/SpeziAccount/AccountValue/Keys/DateOfBirthKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

import SpeziViews
import SwiftUI


Expand Down Expand Up @@ -58,7 +59,7 @@
}

public var body: some View {
SimpleTextRow(name: Key.name) {
ListRow(Key.name) {

Check warning on line 62 in Sources/SpeziAccount/AccountValue/Keys/DateOfBirthKey.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/AccountValue/Keys/DateOfBirthKey.swift#L62

Added line #L62 was not covered by tests
Text(value.formatted(formatStyle))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpeziAccount/AccountValue/Keys/PersonNameKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
private let value: PersonNameComponents

public var body: some View {
SimpleTextRow(name: Key.name) {
ListRow(Key.name) {

Check warning on line 52 in Sources/SpeziAccount/AccountValue/Keys/PersonNameKey.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/AccountValue/Keys/PersonNameKey.swift#L52

Added line #L52 was not covered by tests
Text(value.formatted(.name(style: .long)))
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SpeziAccount/AccountValue/Keys/UserIdKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SpeziFoundation
import SpeziValidation
import SpeziViews
import SwiftUI


Expand Down Expand Up @@ -68,7 +69,7 @@
@Environment(\.accountServiceConfiguration) private var configuration

public var body: some View {
SimpleTextRow(name: configuration.userIdConfiguration.idType.localizedStringResource) {
ListRow(configuration.userIdConfiguration.idType.localizedStringResource) {

Check warning on line 72 in Sources/SpeziAccount/AccountValue/Keys/UserIdKey.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/AccountValue/Keys/UserIdKey.swift#L72

Added line #L72 was not covered by tests
Text(verbatim: value)
}
}
Expand Down
23 changes: 0 additions & 23 deletions Sources/SpeziAccount/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -882,29 +882,6 @@
}
}
},
"Hello" : {
"comment" : "No need to translate, only used in Previews ...",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hallo"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hello"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hola"
}
}
}
},
"MISSING_ACCOUNT_DETAILS" : {
"localizations" : {
"de" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
}
.task {
try? await Task.sleep(for: .milliseconds(500))
try? await Task.sleep(for: .seconds(2))

Check warning on line 33 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift#L33

Added line #L33 was not covered by tests
if !account.signedIn {
presentingSheet = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SpeziFoundation
import SpeziViews
import SwiftUI


Expand All @@ -17,7 +18,7 @@
private let value: Key.Value

public var body: some View {
SimpleTextRow(name: Key.name) {
ListRow(Key.name) {

Check warning on line 21 in Sources/SpeziAccount/Views/DataDisplay/LocalizableStringBasedDisplayView.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/DataDisplay/LocalizableStringBasedDisplayView.swift#L21

Added line #L21 was not covered by tests
Text(value.localizedStringResource)
}
}
Expand All @@ -37,8 +38,8 @@


#if DEBUG
struct LocalizableStringBasedDisplayView_Previews: PreviewProvider {
static var previews: some View {
#Preview {
Form {
LocalizableStringBasedDisplayView<GenderIdentityKey>(.preferNotToState)
}
}
Expand Down
43 changes: 0 additions & 43 deletions Sources/SpeziAccount/Views/DataDisplay/SimpleTextRow.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SpeziFoundation
import SpeziViews
import SwiftUI


Expand All @@ -15,7 +16,7 @@
private let value: Key.Value

public var body: some View {
SimpleTextRow(name: Key.name) {
ListRow(Key.name) {

Check warning on line 19 in Sources/SpeziAccount/Views/DataDisplay/StringBasedDisplayView.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/DataDisplay/StringBasedDisplayView.swift#L19

Added line #L19 was not covered by tests
Text(value)
}
}
Expand All @@ -27,8 +28,8 @@


#if DEBUG
struct StringDataDisplayView_Previews: PreviewProvider {
static var previews: some View {
#Preview {
List {
StringBasedDisplayView<UserIdKey>("andreas.bauer")
}
}
Expand Down
61 changes: 38 additions & 23 deletions Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

import SpeziViews
import SwiftUI


Expand All @@ -21,6 +22,8 @@
@Binding private var date: Date
@State private var dateAdded = false

@State private var layout: DynamicLayout?

private var dateRange: ClosedRange<Date> {
let calendar = Calendar.current
let startDateComponents = DateComponents(year: 1800, month: 1, day: 1)
Expand All @@ -38,7 +41,7 @@
/// - The date is configured to be required.
/// - We are NOT entering new date. Showing existing data the user might want to change.
/// - If we are entering new data and the user pressed the add button.
private var showPicker: Bool {
@MainActor private var showPicker: Bool {

Check warning on line 44 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L44

Added line #L44 was not covered by tests
account.configuration[Key.self]?.requirement == .required
|| viewType?.enteringNewData == false
|| dateAdded
Expand All @@ -47,30 +50,40 @@

public var body: some View {
HStack {
Text(titleLocalization)
.multilineTextAlignment(.leading)
Spacer()

if showPicker {
DatePicker(
selection: $date,
in: dateRange,
displayedComponents: .date
) {
Text(titleLocalization)
DynamicHStack {
Text(titleLocalization)
.multilineTextAlignment(.leading)

if layout == .horizontal {
Spacer()

Check warning on line 58 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L53-L58

Added lines #L53 - L58 were not covered by tests
}

if showPicker {
DatePicker(
selection: $date,
in: dateRange,
displayedComponents: .date
) {
Text(titleLocalization)
}

Check warning on line 68 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L60-L68

Added lines #L60 - L68 were not covered by tests
.labelsHidden()
} else {
Button(action: addDateAction) {
Text("ADD_DATE", bundle: .module)
.multilineTextAlignment(.center)
.foregroundColor(.primary)
.frame(width: 110, height: 34)
}
} else {
Button(action: addDateAction) {
Text("ADD_DATE", bundle: .module)
.multilineTextAlignment(.center)
.foregroundColor(.primary)
.padding([.leading, .trailing], 20)
.padding([.top, .bottom], 7)
}

Check warning on line 77 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L70-L77

Added lines #L70 - L77 were not covered by tests
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color(uiColor: .tertiarySystemFill))
)
}
}

if layout == .vertical {
Spacer()

Check warning on line 86 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L82-L86

Added lines #L82 - L86 were not covered by tests
}
}
.accessibilityRepresentation {
Expand All @@ -86,6 +99,9 @@
}
}
}
.onPreferenceChange(DynamicLayout.self) { value in
layout = value
}

Check warning on line 104 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L102-L104

Added lines #L102 - L104 were not covered by tests
}


Expand Down Expand Up @@ -118,11 +134,10 @@
@State private var date = Date.now

var body: some View {
Form {
DateOfBirthPicker(date: $date)
}

Check warning on line 139 in Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/DateOfBirthPicker.swift#L137-L139

Added lines #L137 - L139 were not covered by tests
VStack {
Form {
DateOfBirthPicker(date: $date)
}
.frame(height: 200)
DateOfBirthPicker(date: $date)
.padding(32)
}
Expand Down
14 changes: 6 additions & 8 deletions Sources/SpeziAccount/Views/Fields/GenderIdentityPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@


static var previews: some View {
VStack {
Form {
Grid {
GenderIdentityPicker(genderIdentity: $genderIdentity)
}
}
.frame(height: 200)
Form {

Check warning on line 52 in Sources/SpeziAccount/Views/Fields/GenderIdentityPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/GenderIdentityPicker.swift#L52

Added line #L52 was not covered by tests
Grid {
GenderIdentityPicker(genderIdentity: $genderIdentity)
}
.padding(32)
}

Grid {
GenderIdentityPicker(genderIdentity: $genderIdentity)
}
.padding(32)

Check warning on line 61 in Sources/SpeziAccount/Views/Fields/GenderIdentityPicker.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/Fields/GenderIdentityPicker.swift#L57-L61

Added lines #L57 - L61 were not covered by tests
.background(Color(.systemGroupedBackground))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpeziAccount/Views/SignupForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

@State private var presentingCloseConfirmation = false

private var accountKeyByCategory: OrderedDictionary<AccountKeyCategory, [any AccountKey.Type]> {
@MainActor private var accountKeyByCategory: OrderedDictionary<AccountKeyCategory, [any AccountKey.Type]> {

Check warning on line 61 in Sources/SpeziAccount/Views/SignupForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziAccount/Views/SignupForm.swift#L61

Added line #L61 was not covered by tests
var result = account.configuration.allCategorized(filteredBy: [.required, .collected])

// patch the user configured account values with account values additionally required by
Expand Down
10 changes: 8 additions & 2 deletions Tests/UITests/TestApp/AccountTests/AccountTestsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ struct AccountTestsView_Previews: PreviewProvider {

static var previews: some View {
AccountTestsView()
.environment(Account(TestAccountService(TestAlertModel(), .emailAddress)))
.previewWith {
AccountConfiguration {
TestAccountService(TestAlertModel(), .emailAddress)
}
}

AccountTestsView()
.environment(Account(building: details, active: TestAccountService(TestAlertModel(), .emailAddress)))
.previewWith {
AccountConfiguration(building: details, active: TestAccountService(TestAlertModel(), .emailAddress))
}

AccountTestsView()
.environment(Account())
Expand Down
2 changes: 1 addition & 1 deletion Tests/UITests/TestApp/AccountTests/TestAlertModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI


@Observable
final class TestAlertModel: Sendable {
final class TestAlertModel: @unchecked Sendable {
var presentingAlert = false
var continuation: CheckedContinuation<Void, Never>?
}
Expand Down
Loading
Loading