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

Use slider instead of button to Deactivate Pod #102

Merged
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
10 changes: 9 additions & 1 deletion OmniBLE/PumpManagerUI/ViewModels/DeactivatePodViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DeactivatePodViewModel: ObservableObject, Identifiable {
var actionButtonDescription: String {
switch self {
case .active:
return LocalizedString("Deactivate Pod", comment: "Action button description for deactivate while pod still active")
return LocalizedString("Slide to Deactivate Pod", comment: "Action button description for deactivate while pod still active")
case .resultError:
return LocalizedString("Retry", comment: "Action button description for deactivate after failed attempt")
case .deactivating:
Expand Down Expand Up @@ -110,6 +110,14 @@ class DeactivatePodViewModel: ObservableObject, Identifiable {
}

@Published var state: DeactivatePodViewModelState = .active
public var stateNeedsDeliberateUserAcceptance : Bool {
switch state {
case .active:
true
default:
false
}
}

var error: DeactivationError? {
if case .resultError(let error) = self.state {
Expand Down
38 changes: 29 additions & 9 deletions OmniBLE/PumpManagerUI/Views/DeactivatePodView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SwiftUI
import LoopKitUI
import SlideButton

struct DeactivatePodView: View {

Expand Down Expand Up @@ -65,15 +66,8 @@ struct DeactivatePodView: View {
}
.disabled(viewModel.state.isProcessing)
}
Button(action: {
viewModel.continueButtonTapped()
}) {
Text(viewModel.state.actionButtonDescription)
.accessibility(identifier: "button_next_action")
.accessibility(label: Text(viewModel.state.actionButtonAccessibilityLabel))
.actionButtonStyle(viewModel.state.actionButtonStyle)
}
.disabled(viewModel.state.isProcessing)
actionButton
.disabled(viewModel.state.isProcessing)
}
.padding()
}
Expand All @@ -94,4 +88,30 @@ struct DeactivatePodView: View {
secondaryButton: .default(FrameworkLocalText("Continue", comment: "Title of button to continue discard"), action: { viewModel.discardPod() })
)
}

var actionText: some View {
Text(self.viewModel.state.actionButtonDescription)
.accessibility(identifier: "button_next_action")
.accessibility(label: Text(self.viewModel.state.actionButtonAccessibilityLabel))
.font(.headline)
}

@ViewBuilder
var actionButton: some View {
if self.viewModel.stateNeedsDeliberateUserAcceptance {
SlideButton(styling: .init(indicatorSize: 60, indicatorColor: Color.red), action: {
self.viewModel.continueButtonTapped()
}) {
actionText
}
} else {
Button(action: {
self.viewModel.continueButtonTapped()
}) {
actionText
.actionButtonStyle(.primary)
}
}
}

}