Created
August 15, 2019 21:20
-
-
Save iDevPro/af5f7369832c9f4ef9dc2c4676331ede to your computer and use it in GitHub Desktop.
@State issue in SwifUI :)
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
// | |
// ContentView.swift | |
// TestIssue | |
// | |
// Created by iqqator on 15.08.2019. | |
// Copyright © 2019 iqqator. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State var isPopUpShown = false | |
@State var test = false | |
var firstText = "123" | |
var secondText = "321" | |
var body: some View { | |
VStack { | |
Button(action: { | |
self.test = true | |
self.isPopUpShown.toggle() | |
}) { | |
Text("ShowPopUpOne") | |
}.padding() | |
Button(action: { | |
self.test = false | |
self.isPopUpShown.toggle() | |
}) { | |
Text("ShowPopUpTwo") | |
}.padding() | |
}.sheet(isPresented: $isPopUpShown) { | |
PopUpView(someString: self.test ? | |
self.firstText : self.secondText) | |
} | |
} | |
} | |
struct PopUpView: View { | |
// Need for change in popUp :) | |
@State var someString: String | |
var body: some View { | |
VStack { | |
Text(someString) | |
.padding() | |
TextField("", text: $someString) | |
.padding() | |
} | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment