-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Enter Vicinity Distance" setting (#102)
* "Enter Vicinity Distance" setting Adds a setting to configure the distance threshold for stopping beacon audio. Fixes #78
- Loading branch information
Showing
10 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
apps/ios/GuideDogs/Code/Visual UI/Views/Settings/Beacon/SettingStepper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// SettingStepper.swift | ||
// Soundscape | ||
// | ||
// Created by Daniel W. Steinbrook on 8/11/24. | ||
// Copyright © 2024 Soundscape community. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Defines a stepper (increment/decrement buttons) that can be used for settings like Enter Vicinity Distance. | ||
/// Takes a step size, min, max, and localization key for printing the value with units.. | ||
/// `unitsLocalization` should be a localization key like "distance.format.meters". | ||
struct SettingStepper: View { | ||
@Binding var value: Double | ||
private let unitsLocalization: String | ||
private let stepSize: Double | ||
private let minValue: Double | ||
private let maxValue: Double | ||
|
||
init(value: Binding<Double>, unitsLocalization: String, stepSize: Double, minValue: Double, maxValue: Double) { | ||
self._value = value | ||
self.unitsLocalization = unitsLocalization | ||
self.stepSize = stepSize | ||
self.minValue = minValue | ||
self.maxValue = maxValue | ||
} | ||
|
||
// Increment and Decrement actions | ||
private func increment() { | ||
let newValue = value + stepSize | ||
value = min(max(newValue, minValue), maxValue) | ||
} | ||
|
||
private func decrement() { | ||
let newValue = value - stepSize | ||
value = min(max(newValue, minValue), maxValue) | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
/// We don't use the native `Stepper` because the increment/decrement | ||
/// controls can't be styled, and the defaults are low contrast. | ||
HStack { | ||
// truncate `value` at the decimal point | ||
Text(GDLocalizedString(unitsLocalization, String(format: "%.0f", value))) | ||
.foregroundColor(.primaryForeground) | ||
.font(.body) | ||
.lineLimit(nil) | ||
|
||
Spacer() | ||
|
||
Button(action: decrement) { | ||
Text("-") | ||
.font(.title) | ||
.frame(width: 44, height: 30) | ||
.background(Color.gray.opacity(0.3)) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.accessibilityLabel(Text("Decrease")) | ||
.disabled(value <= self.minValue) | ||
|
||
Button(action: increment) { | ||
Text("+") | ||
.font(.title) | ||
.frame(width: 44, height: 30) | ||
.background(Color.gray.opacity(0.3)) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
.accessibilityLabel(Text("Increase")) | ||
.disabled(value >= self.maxValue) | ||
} | ||
.padding() | ||
.background(Color.primaryBackground) | ||
.accessibilityElement(children: .ignore) | ||
.accessibilityValue(GDLocalizedString(unitsLocalization, String(format: "%.0f", value))) | ||
.accessibilityAdjustableAction { direction in | ||
switch direction { | ||
case .increment: | ||
increment() | ||
case .decrement: | ||
decrement() | ||
@unknown default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} |