0

When I use a GeometryReader around views that contain controls such as Stepper or Toggle which are bound to an AppStorage var, the controls do not work in the app or preview.

If I remove the GeometryReader, or use a State var instead of AppStorage, then the controls work perfectly.

This was working well before; I believe it broke with iPadOS 16.5:

Sample below:


import SwiftUI

struct ContentView: View {
    /*
     To make the Stepper object function:
     Either,
         Comment out the stepperValue @AppStorage var and uncomment the @State stepperValue var
     Or,
         Comment out all references to the GeometryReader
         (which breaks the requirement of using the entire vertical viewport) 
     */
    
    @AppStorage("stepperValue") var stepperValue = 5
    //@State var stepperValue = 5
    
    var body: some View {
        GeometryReader { reader in
            ScrollView {
                ZStack {
                    Rectangle()
                        .fill(.blue.gradient)
                        .frame(minHeight: reader.size.height)
                    VStack {
                        Stepper(value: $stepperValue, in: 1...10) {
                            Text("Value:\t \(stepperValue)").font(.title3)
                        }
                    }.padding()
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Jace
  • 1,445
  • 9
  • 20
  • 1
    This seems to be a bug in iOS 16, @AppStorage seems to not trigger the update inside the GeometryReader, see related question here: https://stackoverflow.com/questions/69073841/swiftui-appstorage-doesnt-work-with-geometryreader – Răzvan Rujoiu Jun 22 '23 at 20:21
  • Wow, ok, thanks. I thought it might be a bug as well. Seems that people have seen this bug since iPadOS 15, although it seemed to be working for me in earlier iPadOS 16 builds… – Jace Jun 22 '23 at 21:36
  • I have formally reported this as a defect to Apple from my developer account using a TSI. I don’t know if that will help or not. At this point SwiftUI seems to be a Google beta project or something. I’ve found so many bugs. – Jace Jun 22 '23 at 21:38

0 Answers0