|
With Skip Lite (installed last week), with the following code (example), the city name in the view included is refreshed on iOS but not refreshed on Android. Why? What is the best practices? import SwiftUI
struct TestView: View {
/// View properties
@State private var refreshPhrase = false
let cities: [String] = ["Paris","Bordeaux","Lyon","Cannes","Calais","Ajaccio"]
var body: some View {
@State var randomCity = cities.randomElement()!
VStack {
Text("TestView")
VStack {
Text(randomCity) // refreshed on both iOS and Android
.padding()
.background(.yellow)
.padding()
CityView(city: randomCity) // the city is refreshed on iOS and is not refreshed on Android
.border(.black)
.padding()
Button {
refreshPhrase = !refreshPhrase // turnaround for .toggle() unavailability
randomCity = cities.randomElement()!
} label: {
Text("Refresh")
}
.padding()
Spacer()
}
.border(.black)
.id(refreshPhrase)
}
}
}
struct CityView: View {
@State var city:String
var body: some View {
VStack {
Text("in City View:")
.padding()
Text(city)
.padding()
.background(.green)
.padding()
}
}
} |
Answered by
marcprux
Feb 10, 2026
Replies: 5 comments
|
Do not use @State private var. just use @State var as a @State private var won’t bridge to AndroidMay God bless you in a special way! On Oct 11, 2025, at 12:29 PM, lhoumeau ***@***.***> wrote:
With Skip Lite (installed last week), with the following code (example), the city name in the view included is refreshed on iOS but not refreshed on Android. Why? What is the best practices?
import SwiftUI
struct TestView: View {
/// View properties
@State private var refreshPhrase = false
let cities: [String] = ["Paris","Bordeaux","Lyon","Cannes","Calais","Ajaccio"]
var body: some View {
@State var randomCity = cities.randomElement()!
VStack {
Text("TestView")
VStack {
Text(randomCity) // refreshed on both iOS and Android
.padding()
.background(.yellow)
.padding()
CityView(city: randomCity) // the city is refreshed on iOS and is not refreshed on Android
.border(.black)
.padding()
Button {
refreshPhrase = !refreshPhrase // turnaround for .toggle() unavailability
randomCity = cities.randomElement()!
} label: {
Text("Refresh")
}
.padding()
Spacer()
}
.border(.black)
.id(refreshPhrase)
}
}
}
struct CityView: View {
@State var city:String
var body: some View {
VStack {
Text("in City View:")
.padding()
Text(city)
.padding()
.background(.green)
.padding()
}
}
}
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
0 replies
|
Thank you Dave. Nevertheless the @State var (without private) has no effect. |
0 replies
|
Thank you Vitor. The good way (with a counter added when the random draw of the city give the previous one) : import SwiftUI
struct TestView: View {
/// View properties
let cities: [String] = ["Paris","Bordeaux","Lyon","Cannes","Calais","Ajaccio"]
@State var refreshPhrase:Bool = false
@State var count:Int = 1
var body: some View {
@State var randomCity = cities.randomElement()!
VStack {
Text("TestView")
VStack {
Text("\(randomCity) (\(count))") // refreshed on both iOS and Android
.padding()
.background(.yellow)
.padding()
CityView(city: randomCity, count: count) // the city is refreshed on iOS and is not refreshed on Android
.border(.black)
.padding()
Button {
refreshPhrase = !refreshPhrase // turnaround for .toggle() unavailability
count += 1
randomCity = cities.randomElement()!
} label: {
Text("Refresh")
}
.padding()
Spacer()
}
.border(.black)
.id(refreshPhrase)
}
}
}
struct CityView: View {
var city:String
var count:Int
var body: some View {
VStack {
Text("in City View:")
.padding()
Text("\(city) (\(count))")
.padding()
.background(.green)
.padding()
}
}
} |
0 replies
|
This issue should be fixed by skiptools/skip-ui#330, which is currently in final review. |
0 replies
Answer selected by
marcprux
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue should be fixed by skiptools/skip-ui#330, which is currently in final review.