SwiftUI SafeAreaInsets not propagated to UIScrollView in UIViewRepresentable

Originator:bryn.bodayle
Number:rdar://FB13591720 Date Originated:2/6/24
Status:Open Resolved:
Product:SwiftUI Product Version:iOS 17.3 (21D50)
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
Safe areas are not propagated to bridged UIKit scroll views when using the `safeAreaInset(edge:alignment:spacing:content:)` modifier in SwiftUI. Using this modifier does propagate the safe area insets do SwiftUI ScrollView and List. See the attached file for a simple repro case. You'll notice that the scroll view is not inset by the safe area, it just remains below it.


struct ContentView: View {
  var body: some View {
    ScrollViewRepresentable()
    .safeAreaInset(edge: .top) {
      Rectangle()
        .foregroundColor(.red)
        .frame(height: 100)
    }
  }
}

struct ScrollViewRepresentable: UIViewRepresentable {

  func makeUIView(context: Context) -> UIScrollView {
    let scrollView = UIScrollView(frame: .zero)
    scrollView.contentSize = CGSize(width: 300, height: 1000)
    return scrollView
  }

  func updateUIView(_ uiView: UIScrollView, context: Context) { }
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!