Skip to content

Instantly share code, notes, and snippets.

@iDevPro
Created August 15, 2019 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iDevPro/af5f7369832c9f4ef9dc2c4676331ede to your computer and use it in GitHub Desktop.
Save iDevPro/af5f7369832c9f4ef9dc2c4676331ede to your computer and use it in GitHub Desktop.
@State issue in SwifUI :)
//
// 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