This is my code with swiftui, when I click button = change tradingMode inside sheet = after show keyboard from ContentView = app crash. Please help me and thanks!
enum TradingMode {
case Derivatives, Equities
}
struct ContentView: View {
@State var tradingMode : TradingMode = TradingMode.Equities
@State var isShowSecondView = false
var body: some View {
VStack(content: {
Button("show second view") {
isShowSecondView.toggle()
}
TabView {
switch tradingMode {
case .Equities:
VStack(content: {
Text("Tab 1 Un")
.padding()
TextField("ple", text: .constant(""))
})
.tabItem {
Text("tab 1")
}.tag(0)
case .Derivatives:
VStack(content: {
Text("Tab 1 Der")
.padding()
TextField("ple", text: .constant(""))
})
.tabItem {
Text("tab 1")
}.tag(0)
}
switch tradingMode {
case .Equities:
VStack(content: {
Text("Tab 2 Un")
.padding()
TextField("ple", text: .constant(""))
})
.tabItem {
Text("tab 2")
}.tag(1)
case .Derivatives:
VStack(content: {
Text("Tab 2 Der")
.padding()
TextField("ple", text: .constant(""))
})
.tabItem {
Text("tab 2")
}.tag(1)
}
}
})
.sheet(isPresented: $isShowSecondView, content: {
SecondView(tradingMode: $tradingMode)
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewLayout(.device)
}
}
struct SecondView: View {
@Environment(\.presentationMode) var presentation
@Binding var tradingMode : TradingMode
var body: some View {
VStack(content: {
Button("Change state") {
if tradingMode == .Derivatives {
tradingMode = .Equities
} else {
tradingMode = .Derivatives
}
self.presentation.wrappedValue.dismiss()
}
})
}
}
and video bug
drive.google.com/file/d/18eXCmlByGqJylEhCZbtJ4Rn0wmI0bb/view
Post
Replies
Boosts
Views
Activity
I have a List and about 1000 item of Array, and my item update realtime (100 messenger updated/s). My List is very very lag.
I see ForEach run full (1000 turn)/ (1 item update) => crazy
Can you help me a solution like a reloadRows in UIKit with UITableView.
Thank so much!
This my test code (I try with List and LazyVStack):
struct PriceBoardView2 : View {
@EnvironmentObject var loadingEnv : LoadingEnv
@State var listUser : [UserModel]
var body: some View {
VStack(content: {
Button(action: {
updateData() //fake data realtime update
}, label: {
Text("Fake data realtime update")
})
List(content: {
ForEach(listUser.indices, id: \.self) { i in
RowPriceBoardView2(userModel: listUser[i])
}
})
// ScrollView(content: {
// LazyVStack(content: {
// ForEach(listUser.indices, id: \.self) { i in
// RowPriceBoardView2(userModel: listUser[i])
// }
// })
// })
})
.onAppear(perform: {
for i in 0..<1000 {
listUser.append(UserModel(number: i, name: "-", age: 0))
}
})
}
func updateData() {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.01, execute: {
let i = Int.random(in: 0..<1000)
self.listUser[i] = UserModel(number: i, name: "Pla pla", age: Int.random(in: 0..<1000))
updateData()
})
}
}
struct UserModel {
var number : Int
var name : String
var age : Int
}
struct RowPriceBoardView2: View {
var userModel : UserModel
var body: some View {
HStack(content: {
Text("\(userModel.number)")
Spacer()
Text("\(userModel.name)")
Spacer()
Text("\(userModel.age)")
})
.frame(width: .infinity, height: 30, alignment: .center)
}
}
Like a title, I updated taget version but my App on Store still compatibility is "Ios 11 or later". How to update compatibility? Thank!