Skip to content

Commit

Permalink
Integrated dynamic type sizing accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nriedman committed May 22, 2024
1 parent 1ead774 commit 377ac4c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 53 deletions.
19 changes: 13 additions & 6 deletions ENGAGEHF/Bluetooth/MeasurementManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ class MeasurementManager: Module, EnvironmentAccessible {
return manager
}

Check warning on line 34 in ENGAGEHF/Bluetooth/MeasurementManager.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/MeasurementManager.swift#L29-L34

Added lines #L29 - L34 were not covered by tests

var showSheet: Bool {
get {
newMeasurement != nil
}
set {
if !newValue {
self.newMeasurement = nil
}
}

Check warning on line 44 in ENGAGEHF/Bluetooth/MeasurementManager.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/MeasurementManager.swift#L40-L44

Added lines #L40 - L44 were not covered by tests
}


@ObservationIgnored @StandardActor private var standard: ENGAGEHFStandard
private let logger = Logger(subsystem: "ENGAGEHF", category: "MeasurementManager")

Expand All @@ -42,10 +54,6 @@ class MeasurementManager: Module, EnvironmentAccessible {

var newMeasurement: HKQuantitySample?

var showSheet: Bool {
newMeasurement != nil
}


init() {
MeasurementManager._manager = self
Expand All @@ -60,7 +68,6 @@ class MeasurementManager: Module, EnvironmentAccessible {
self.deviceName = nil
}

Check warning on line 69 in ENGAGEHF/Bluetooth/MeasurementManager.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/MeasurementManager.swift#L64-L69

Added lines #L64 - L69 were not covered by tests


// Called by WeightScaleDevice on change of WeightMeasurement Characteristic
func loadMeasurement(_ measurement: WeightMeasurement) {
// Convert to HKQuantitySample after downloading from Firestore
Expand All @@ -71,7 +78,7 @@ class MeasurementManager: Module, EnvironmentAccessible {
// Called by UI Sheet View to save the newMeasurement to firestore
func saveMeasurement() async throws {
if ProcessInfo.processInfo.isPreviewSimulator {
try await Task.sleep(nanoseconds: 10_000_000_000)
try await Task.sleep(for: .seconds(5))
return
}

Expand Down
3 changes: 2 additions & 1 deletion ENGAGEHF/Bluetooth/Views/ConfirmMeasurementButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct DiscardButton: View {


struct ConfirmMeasurementButton: View {
@ScaledMetric private var buttonHeight: CGFloat = 38

Check warning on line 34 in ENGAGEHF/Bluetooth/Views/ConfirmMeasurementButton.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/ConfirmMeasurementButton.swift#L34

Added line #L34 was not covered by tests
@Binding var viewState: ViewState


Expand All @@ -43,7 +44,7 @@ struct ConfirmMeasurementButton: View {
},
label: {
Text("Save")
.frame(maxWidth: .infinity, maxHeight: 38)
.frame(maxWidth: .infinity, maxHeight: buttonHeight)
.font(.title2)
.bold()
}
Expand Down
40 changes: 21 additions & 19 deletions ENGAGEHF/Bluetooth/Views/MeasurementLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@
import SwiftUI


private struct PreviewWrapperMeasurementLayer: View {
@Environment(MeasurementManager.self) private var measurementManager


var body: some View {
MeasurementLayer()
.onAppear {
measurementManager.loadMockMeasurement()
}
}
}


struct MeasurementLayer: View {
@Environment(MeasurementManager.self) private var measurementManager
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
@ScaledMetric private var measurementTextSize: CGFloat = 60

Check warning on line 15 in ENGAGEHF/Bluetooth/Views/MeasurementLayer.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/MeasurementLayer.swift#L15

Added line #L15 was not covered by tests


var body: some View {
VStack(spacing: 15) {
Text(measurementManager.newMeasurement?.quantity.description ?? "???")
Text(measurementManager.newMeasurement?.quantity.description ?? "")
.font(.system(size: measurementTextSize, weight: .bold, design: .rounded))
.multilineTextAlignment(.center)
Text("Measurement Recorded")
.font(.title3)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
if dynamicTypeSize < .accessibility4 {
Text("Measurement Recorded")
.font(.title3)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
}
}

Check warning on line 30 in ENGAGEHF/Bluetooth/Views/MeasurementLayer.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/MeasurementLayer.swift#L18-L30

Added lines #L18 - L30 were not covered by tests
}


#Preview {
PreviewWrapperMeasurementLayer()
struct PreviewWrapperMeasurementLayer: View {
@Environment(MeasurementManager.self) private var measurementManager


var body: some View {
MeasurementLayer()
.onAppear {
measurementManager.loadMockMeasurement()
}
}
}

return PreviewWrapperMeasurementLayer()
.previewWith(standard: ENGAGEHFStandard()) {
MeasurementManager()
}
Expand Down
53 changes: 34 additions & 19 deletions ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@ import SpeziViews
import SwiftUI


private struct MeasurementRecordedViewPreviewWrapper: View {
@Environment(MeasurementManager.self) private var measurementManager
@State private var viewState: ViewState = .idle


var body: some View {
@Bindable var measurementManager = measurementManager

Button("Mock Measurement") {
measurementManager.loadMockMeasurement()
struct MeasurementRecordedView: View {
private var dynamicDetente: PresentationDetent {
switch dynamicTypesize {
case .xSmall, .small:
return .fraction(0.35)
case .medium, .large:
return .fraction(0.45)
case .xLarge, .xxLarge, .xxxLarge:
return .fraction(0.65)
case .accessibility1, .accessibility2, .accessibility3, .accessibility4, .accessibility5:
return .large
default:
return .fraction(0.45)
}
.sheet(isPresented: $measurementManager.showSheet) {
MeasurementRecordedView()
.presentationDetents([.fraction(0.4)])
}
}

Check warning on line 29 in ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift#L16-L29

Added lines #L16 - L29 were not covered by tests
}



struct MeasurementRecordedView: View {
@Environment(\.dynamicTypeSize) private var dynamicTypesize
@State var viewState = ViewState.idle

Check warning on line 33 in ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift#L33

Added line #L33 was not covered by tests


Expand All @@ -42,15 +40,32 @@ struct MeasurementRecordedView: View {
MeasurementLayer()
Spacer()
ConfirmMeasurementButton(viewState: $viewState)
.padding()
}
.presentationDetents([dynamicDetente])
.interactiveDismissDisabled(viewState != .idle)
}

Check warning on line 46 in ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/MeasurementRecordedView.swift#L36-L46

Added lines #L36 - L46 were not covered by tests
}


#Preview {
MeasurementRecordedViewPreviewWrapper()
struct MeasurementRecordedViewPreviewWrapper: View {
@Environment(MeasurementManager.self) private var measurementManager
@State private var viewState: ViewState = .idle


var body: some View {
@Bindable var measurementManager = measurementManager

Button("Mock Measurement") {
measurementManager.loadMockMeasurement()
}
.sheet(isPresented: $measurementManager.showSheet) {
MeasurementRecordedView()
}
}
}

return MeasurementRecordedViewPreviewWrapper()
.previewWith(standard: ENGAGEHFStandard()) {
MeasurementManager()
}
Expand Down
2 changes: 2 additions & 0 deletions ENGAGEHF/Bluetooth/Views/ViewElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct CloseButtonLayer: View {
@Environment(\.dismiss) private var dismiss
@Binding private var viewState: ViewState


var body: some View {
HStack {
Button(action: {
Expand All @@ -30,6 +31,7 @@ struct CloseButtonLayer: View {
.padding()
}

Check warning on line 32 in ENGAGEHF/Bluetooth/Views/ViewElements.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/ViewElements.swift#L18-L32

Added lines #L18 - L32 were not covered by tests


init(viewState: Binding<ViewState>) {
self._viewState = viewState
}

Check warning on line 37 in ENGAGEHF/Bluetooth/Views/ViewElements.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Bluetooth/Views/ViewElements.swift#L35-L37

Added lines #L35 - L37 were not covered by tests
Expand Down
20 changes: 12 additions & 8 deletions ENGAGEHF/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct HomeView: View {
private var bluetoothEnabled: Bool {
!ProcessInfo.processInfo.isPreviewSimulator
}



@Environment(MeasurementManager.self) private var measurementManager
@Environment(WeightScaleDevice.self) private var weightScale: WeightScaleDevice?
@Environment(Bluetooth.self) private var bluetooth
Expand All @@ -43,20 +44,23 @@ struct HomeView: View {
Label("Home", systemImage: "house")
}
}
.autoConnect(enabled: weightScale == nil && bluetoothEnabled, with: bluetooth)
.autoConnect(enabled: bluetoothEnabled, with: bluetooth)
.sheet(isPresented: $presentingAccount) {
AccountSheet()
}
.accountRequired(Self.accountEnabled) {
AccountSheet()
}
.verifyRequiredAccountDetails(Self.accountEnabled)
.sheet(isPresented: $measurementManager.showSheet, onDismiss: {
MeasurementManager.manager.clear()
}) {
MeasurementRecordedView()
.presentationDetents([.fraction(0.45)])
}
.sheet(
isPresented: $measurementManager.showSheet,
onDismiss: {
measurementManager.clear()
},

Check warning on line 59 in ENGAGEHF/Home.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Home.swift#L58-L59

Added lines #L58 - L59 were not covered by tests
content: {
MeasurementRecordedView()
}

Check warning on line 62 in ENGAGEHF/Home.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Home.swift#L61-L62

Added lines #L61 - L62 were not covered by tests
)
}
}

Expand Down

0 comments on commit 377ac4c

Please sign in to comment.