Why watchOS picker always shows "ScrollView contentOffset binding has been read" warning?
Asked Answered
A

0

7

Bare minimum picker test app for watchOS.

import SwiftUI    
@main
    struct PickerTestApp: App {
        var body: some Scene {
            WindowGroup {
               NavigationView {
                    ContentView()
                }
            }
        }
    }

ContentView

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            NavigationLink(destination: DistanceSelectView()) {
                Text("Next screen")
            }
        }
    }
}

DistanceSelectView

import SwiftUI

struct DistanceSelectView: View {
    
    @State var Age = 1
    
    var body: some View {
        
        VStack {
            Picker(selection: $Age, label: Text("Select your age.[\(Age)]")) {
                ForEach(10 ..< 100, id: \.self) { num in
                    Text("\(num)")
                }
            }
        }
    }
}

When run, and "Next screen" NavigationLink is pressed, it always displays the following warning:

"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."

What I'm doing wrong here?

Acne answered 7/11, 2021 at 15:13 Comment(3)
Did you manage to resolve this, also getting this and can't find a way to avoid itMargemargeaux
No, it seems to be Apple bug. Had to stop use pickersAcne
I have the same issue, didn't matter how I modified the Picker, put it inside List, ScrollView, Form, etc. Same warning. Seems to me as you mention it is a bug on SwiftUI for watchOS, but I would think is harmless to ignore the warning (I hope...)Apparel

© 2022 - 2025 — McMap. All rights reserved.