I have a custom modal view (using a ZStack) That has a ScrollView. This Modal view is spring animated open to full screen ignoring all safe areas.
However, while animating as the top of my modal view reaches the top safe area (y:40)ish. The scroll view inside jumps from being at the top of its parent view as desired to the top of the device which makes the animation look bad.
Any ideas on how to get around this?
This demonstrates what I'm working with in it's simplest form...
import SwiftUI
struct ModalView: View {
@Binding var padding: CGFloat
@Binding var cornerRadius: CGFloat
@Binding var imageHeightMultiple: CGFloat
var body: some View {
ZStack {
ScrollView(.vertical, showsIndicators: false) {
GeometryReader { geo in
Image("image_1")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: geo.size.width, height: geo.size.height)
.background(Color.gray)
.clipped(antialiased: true)
}
.frame(height: UIScreen.main.bounds.width * imageHeightMultiple)
}
}
.background(Color.white)
.cornerRadius(cornerRadius)
.padding(.horizontal, padding)
}
}
#if DEBUG
struct ModalView_Previews: PreviewProvider {
@State static var padding: CGFloat = 16
@State static var cornerRadius: CGFloat = 20
@State static var imageHeightMultiple: CGFloat = 0.7
static var previews: some View {
return ZStack {
Color(.gray)
.edgesIgnoringSafeArea(.all)
ModalView(padding: $padding, cornerRadius: $cornerRadius, imageHeightMultiple: $imageHeightMultiple)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 80)
.position(x: UIScreen.main.bounds.width/2, y: UIScreen.main.bounds.height/2)
.edgesIgnoringSafeArea(.all)
}
.previewDevice(PreviewDevice(rawValue: "iPhone 11 Pro"))
}
}
#endif