Post

Replies

Boosts

Views

Activity

Warning ScrollView contentOffset binding has been read
Hi, I have a very simple app code running on Watch OS 7 XCODE 12.0, generating following warning when a picker is appearing : ScrollView contentOffset binding has been read; this will cause grossly inefficient view performance as the ScrollView's content will be updated whenever its contentOffset changes. Read the contentOffset binding in a view that is not parented between the creator of the binding and the ScrollView to avoid this. Removing OnChange is solving the issue. How to fix this ? Many thanks Code is following : import SwiftUI struct ContentView : View {          @State private var speedSelected : Int = 0     @State private var toggle : Bool = false          var body: some View {         Toggle("Autolap", isOn: $toggle)                  if toggle {             Picker(selection: $speedSelected, label: Text("Whole number")) {                 ForEach(0 .. 10, id: \.self) { number in                     Text(String(format: "%02d", number))                 }             }             .onChange(of : speedSelected) { _ in                 print ("change !!!")             }         }     } }
1
2
1.4k
Mar ’21