Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
  2.  
  3. import SwiftUI
  4. import Combine
  5.  
  6. class Settings: ObservableObject {
  7. @Published var hasAgreedToTermsAndConditions: Bool = false
  8. @Published var hasAgreedToPrivacyPolicy: Bool = false
  9.  
  10. @Published var isActive = false
  11. @Published var isNotActive = true
  12.  
  13. private var cancellable: AnyCancellable? = nil
  14.  
  15. init() {
  16. self.cancellable = Publishers.CombineLatest($hasAgreedToPrivacyPolicy, $hasAgreedToTermsAndConditions).map{
  17. return $0.0 && $0.1
  18. }.sink{
  19. self.isActive = $0
  20. self.isNotActive = !$0
  21. }
  22. }
  23. }
  24.  
  25. struct WelcomeSceneView: View {
  26. @ObservedObject var settings = Settings()
  27.  
  28. var body: some View {
  29. NavigationView {
  30. VStack {
  31. Image(uiImage: welcomeLogo)
  32.  
  33. Spacer()
  34.  
  35. Text("Welcome friend!".uppercased())
  36. //.font(.system(size: 55))
  37.  
  38. Toggle(isOn: $settings.hasAgreedToTermsAndConditions) {
  39. Text("I agree to the Terms and Conditions")
  40. }.toggleStyle(DefaultToggleStyle())
  41.  
  42. Toggle(isOn: $settings.hasAgreedToPrivacyPolicy) {
  43. Text("I agree to the Privacy Policy")
  44. }.toggleStyle(DefaultToggleStyle())
  45.  
  46.  
  47. // 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...
  48. Text("is active: (settings.isActive.description)")
  49. NavigationLink("Can proceed", destination: SignInScene(), isActive: $settings.isActive)
  50. .hidden()
  51. NavigationLink("Can not proceed", destination: PleaseConfirmView(), isActive: $settings.isNotActive)
  52. .hidden()
  53. }.padding(30)
  54. }
  55. }
  56.  
  57. let welcomeLogo = UIImage(systemName: "headphones")!
  58. }
  59.  
  60. struct SignInScene: View {
  61. var body: some View {
  62. Text("Some sign in scene")
  63. }
  64. }
  65.  
  66. struct PleaseConfirmView: View {
  67. var body: some View {
  68. Text("Please confirm")
  69. }
  70. }
  71.  
  72. /// Creates an instance that presents `destination` when active, with a
  73. /// `Text` label generated from a title string.
  74. public init(_ titleKey: LocalizedStringKey, destination: Destination, isActive: Binding<Bool>)
  75.  
  76. struct WelcomeScene: View {
  77. @State var hasAgreedToTermsAndConditions: Bool = false
  78. @State var hasAgreedToPrivacyPolicy: Bool = false
  79.  
  80. var body: some View {
  81. NavigationView {
  82. VStack {
  83.  
  84. Spacer()
  85.  
  86. Toggle(isOn: $hasAgreedToTermsAndConditions) {
  87. Text("I agree to the Terms and Conditions")
  88. }.toggleStyle(DefaultToggleStyle())
  89.  
  90. Toggle(isOn: $hasAgreedToPrivacyPolicy) {
  91. Text("I agree to the Privacy Policy")
  92. }.toggleStyle(DefaultToggleStyle())
  93.  
  94. NavigationLink("Proceed", destination: SignInScene())
  95. .disabled(!hasAgreedToTermsAndConditions || !hasAgreedToPrivacyPolicy)
  96. }.padding(30)
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement