As shown by the video linked below, when I move off of the main page, the selected picker always defaults back to the 'select exercise' picker. However, I would like it to be able to remember which picker was last selected, and keep the picker selected when moving back to the main page.
Is there any way to programmatically control the selected picker in a view?
Video: https://streamable.com/djmvso
Example of one picker:
var body: some View {
VStack(spacing: -15) {
Text("Exercise")
.font(.system(size: 10))
.if(controlSelection == .exercise) {
$0.bold()
}
Picker("", selection: $workout.currentExerciseChoice) {
ForEach(filteredExercises, id: \.self) { exercise in
HStack {
// Current exercise in the workout.
CircleImageExercise(exercise: exercise,
size: 24,
showDetails: true)
Spacer()
// Current exercise name.
Text(exercise.name ?? "")
.font(.system(size: 14))
.multilineTextAlignment(.center)
.scaledToFit()
.minimumScaleFactor(0.5)
.lineLimit(1)
Spacer()
}
.padding(.leading, 5)
.tag(exercise as Exercise?)
}
}
.frame(height: WKInterfaceDevice.current().screenBounds.height / 4)
.onTapGesture {
controlSelection = .exercise
}
// Update time, weight and reps values to current exercise defaults.
.onChange(of: workout.currentExerciseChoice) { exerciseChoice in
if (exerciseChoice?.isHold ?? false) {
workout.currentTimeChoice = exerciseChoice?.defaultHold ?? 30.0
} else {
workout.currentWeightChoice = exerciseChoice?.defaultWeight ?? 5.0
workout.currentRepChoice = exerciseChoice?.defaultReps ?? 5.0
}
}
}
}