Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
- import SwiftUI
- import Combine
- class Settings: ObservableObject {
- @Published var hasAgreedToTermsAndConditions: Bool = false
- @Published var hasAgreedToPrivacyPolicy: Bool = false
- @Published var isActive = false
- @Published var isNotActive = true
- private var cancellable: AnyCancellable? = nil
- init() {
- self.cancellable = Publishers.CombineLatest($hasAgreedToPrivacyPolicy, $hasAgreedToTermsAndConditions).map{
- return $0.0 && $0.1
- }.sink{
- self.isActive = $0
- self.isNotActive = !$0
- }
- }
- }
- struct WelcomeSceneView: View {
- @ObservedObject var settings = Settings()
- var body: some View {
- NavigationView {
- VStack {
- Image(uiImage: welcomeLogo)
- Spacer()
- Text("Welcome friend!".uppercased())
- //.font(.system(size: 55))
- Toggle(isOn: $settings.hasAgreedToTermsAndConditions) {
- Text("I agree to the Terms and Conditions")
- }.toggleStyle(DefaultToggleStyle())
- Toggle(isOn: $settings.hasAgreedToPrivacyPolicy) {
- Text("I agree to the Privacy Policy")
- }.toggleStyle(DefaultToggleStyle())
- // This does not compile 'Binding<Bool> is not convertible to Bool', but I cannot figure out how to create a compupted property binding using those 2 states...
- Text("is active: (settings.isActive.description)")
- NavigationLink("Can proceed", destination: SignInScene(), isActive: $settings.isActive)
- .hidden()
- NavigationLink("Can not proceed", destination: PleaseConfirmView(), isActive: $settings.isNotActive)
- .hidden()
- }.padding(30)
- }
- }
- let welcomeLogo = UIImage(systemName: "headphones")!
- }
- struct SignInScene: View {
- var body: some View {
- Text("Some sign in scene")
- }
- }
- struct PleaseConfirmView: View {
- var body: some View {
- Text("Please confirm")
- }
- }
- /// Creates an instance that presents `destination` when active, with a
- /// `Text` label generated from a title string.
- public init(_ titleKey: LocalizedStringKey, destination: Destination, isActive: Binding<Bool>)
- struct WelcomeScene: View {
- @State var hasAgreedToTermsAndConditions: Bool = false
- @State var hasAgreedToPrivacyPolicy: Bool = false
- var body: some View {
- NavigationView {
- VStack {
- Spacer()
- Toggle(isOn: $hasAgreedToTermsAndConditions) {
- Text("I agree to the Terms and Conditions")
- }.toggleStyle(DefaultToggleStyle())
- Toggle(isOn: $hasAgreedToPrivacyPolicy) {
- Text("I agree to the Privacy Policy")
- }.toggleStyle(DefaultToggleStyle())
- NavigationLink("Proceed", destination: SignInScene())
- .disabled(!hasAgreedToTermsAndConditions || !hasAgreedToPrivacyPolicy)
- }.padding(30)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement