@@ -305,7 +305,11 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
305305
306306 let transition = ContainedViewLayoutTransition . animated ( duration: 0.4 , curve: . spring)
307307 let targetPosition = self . scrollView. center
308- self . scrollView. center = targetPosition. offsetBy ( dx: 0.0 , dy: self . scrollView. contentSize. height)
308+ var offset : CGFloat = self . scrollView. contentSize. height
309+ if self . isCentered {
310+ offset = self . frame. height + self . scrollView. frame. height * 0.5
311+ }
312+ self . scrollView. center = targetPosition. offsetBy ( dx: 0.0 , dy: offset)
309313 transition. animateView ( allowUserInteraction: true , {
310314 self . scrollView. center = targetPosition
311315 } )
@@ -338,18 +342,27 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
338342 let contentOffset = ( self . scrollView. contentOffset. y + self . scrollView. contentInset. top - self . scrollView. contentSize. height) * - 1.0
339343 let dismissalOffset = self . scrollView. contentSize. height + abs( contentView. frame. minY)
340344 let delta = dismissalOffset - contentOffset
345+ var targetPosition = self . scrollView. center. y + delta
346+ if self . isCentered {
347+ targetPosition = self . frame. height + self . scrollView. frame. height * 0.5
348+ }
341349
342- transition. updatePosition ( layer: self . scrollView. layer, position: CGPoint ( x: self . scrollView. center. x, y: self . scrollView . center . y + delta ) , completion: { _ in
350+ transition. updatePosition ( layer: self . scrollView. layer, position: CGPoint ( x: self . scrollView. center. x, y: targetPosition ) , completion: { _ in
343351 completion ( )
344352 } )
345353 } else {
346- self . scrollView. layer. animatePosition ( from: CGPoint ( ) , to: CGPoint ( x: 0.0 , y: self . scrollView. contentSize. height + abs( contentView. frame. minY) ) , duration: 0.25 , timingFunction: CAMediaTimingFunctionName . easeInEaseOut. rawValue, removeOnCompletion: false , additive: true , completion: { _ in
354+ var targetOffset : CGFloat = self . scrollView. contentSize. height + abs( contentView. frame. minY)
355+ if self . isCentered {
356+ targetOffset = self . frame. height + self . scrollView. frame. height * 0.5
357+ }
358+ self . scrollView. layer. animatePosition ( from: CGPoint ( ) , to: CGPoint ( x: 0.0 , y: targetOffset) , duration: 0.25 , timingFunction: CAMediaTimingFunctionName . easeInEaseOut. rawValue, removeOnCompletion: false , additive: true , completion: { _ in
347359 completion ( )
348360 } )
349361 }
350362 }
351363
352364 private var currentHasInputHeight = false
365+ private var isCentered = false
353366 private var currentAvailableSize : CGSize ?
354367 func update( component: SheetComponent < ChildEnvironmentType > , availableSize: CGSize , state: EmptyComponentState , environment: Environment < EnvironmentType > , transition: ComponentTransition ) -> CGSize {
355368 let previousHasInputHeight = self . currentHasInputHeight
@@ -364,6 +377,7 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
364377 }
365378
366379 self . component = component
380+ self . isCentered = sheetEnvironment. isCentered
367381 self . currentHasInputHeight = sheetEnvironment. hasInputHeight
368382
369383 if self . isAnimatingOut {
0 commit comments