@@ -8,53 +8,47 @@ struct POSRootModalViewModifier: ViewModifier {
88 private let scaleTransitionAmount = Constants . scaleTransitionAmount
99
1010 func body( content: Content ) -> some View {
11- GeometryReader { geometry in
12- ZStack {
13- content
14- . blur ( radius: modalManager. isPresented ? 8 : 0 )
15- . disabled ( modalManager. isPresented)
16- . accessibilityElement ( children: modalManager. isPresented ? . ignore : . contain)
17-
18- if modalManager. isPresented {
19- Color . posSurfaceDim. opacity ( 0.8 )
20- . edgesIgnoringSafeArea ( . all)
21- . onTapGesture {
22- if modalManager. allowsInteractiveDismissal {
23- modalManager. dismiss ( )
24- }
11+ ZStack {
12+ content
13+ . blur ( radius: modalManager. isPresented ? 8 : 0 )
14+ . disabled ( modalManager. isPresented)
15+ . accessibilityElement ( children: modalManager. isPresented ? . ignore : . contain)
16+
17+ if modalManager. isPresented {
18+ Color . posSurfaceDim. opacity ( 0.8 )
19+ . edgesIgnoringSafeArea ( . all)
20+ . onTapGesture {
21+ if modalManager. allowsInteractiveDismissal {
22+ modalManager. dismiss ( )
2523 }
26- // Don't scale/fade in the backdrop
27- . animation ( nil , value: modalManager. isPresented)
28- ZStack {
29- modalManager. getContent ( )
30- . environment ( \. posModalParentSize, modalParentSize)
31- . background ( Color . posSurfaceBright)
32- . cornerRadius ( POSCornerRadiusStyle . extraLarge. value)
33- . posShadow ( . large, cornerRadius: POSCornerRadiusStyle . extraLarge. value)
34- . padding ( )
3524 }
36- . zIndex ( 1 )
37- // Scale the modal container in and out, fading appropriately.
38- // Unfortunately combined doesn't work on removal.
39- // The extra ZStack prevents changing modalContent from scaling and fading, but the ZIndex needs to be
40- // consistent even when animating out, which it wouldn't be if unspecified.
41- . transition ( . scale( scale: scaleTransitionAmount) . combined ( with: . opacity) )
25+ // Don't scale/fade in the backdrop
26+ . animation ( nil , value: modalManager. isPresented)
27+ ZStack {
28+ modalManager. getContent ( )
29+ . environment ( \. posModalParentSize, modalParentSize)
30+ . background ( Color . posSurfaceBright)
31+ . cornerRadius ( POSCornerRadiusStyle . extraLarge. value)
32+ . posShadow ( . large, cornerRadius: POSCornerRadiusStyle . extraLarge. value)
33+ . padding ( )
4234 }
35+ . zIndex ( 1 )
36+ // Scale the modal container in and out, fading appropriately.
37+ // Unfortunately combined doesn't work on removal.
38+ // The extra ZStack prevents changing modalContent from scaling and fading, but the ZIndex needs to be
39+ // consistent even when animating out, which it wouldn't be if unspecified.
40+ . transition ( . scale( scale: scaleTransitionAmount) . combined ( with: . opacity) )
4341 }
44- . onAppear {
45- updateModalParentSize ( from: geometry)
46- }
47- . onChange ( of: geometry. size) { _ in
48- updateModalParentSize ( from: geometry)
49- }
42+ }
43+ . measureFrame { frame in
44+ updateModalParentSize ( with: frame. size)
5045 }
5146 . animation ( . easeInOut( duration: animationDuration) , value: modalManager. isPresented)
5247 }
5348
54- private func updateModalParentSize( from geometry: GeometryProxy ) {
55- let newSize = geometry. size
56- if newSize != modalParentSize && newSize != . zero {
57- modalParentSize = newSize
49+ private func updateModalParentSize( with size: CGSize ) {
50+ if size != modalParentSize && size != . zero {
51+ modalParentSize = size
5852 }
5953 }
6054}
0 commit comments