diff options
author | Hailey <me@haileyok.com> | 2024-10-10 18:16:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 18:16:25 -0700 |
commit | 88f326b37f6ca35efbb8e5133cd99104d8855bf0 (patch) | |
tree | 01c18d4d15150cf2831e97af132d9de85deff3f3 /modules/bottom-sheet/src | |
parent | 34a0007679311e2745ff7162a7ce2ae54f503125 (diff) | |
download | voidsky-88f326b37f6ca35efbb8e5133cd99104d8855bf0.tar.zst |
Fix sheets to work nicely on ios 15 (#5685)
Diffstat (limited to 'modules/bottom-sheet/src')
-rw-r--r-- | modules/bottom-sheet/src/BottomSheetNativeComponent.tsx | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx b/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx index eadd9b4a1..fa2b163bf 100644 --- a/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx +++ b/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx @@ -23,10 +23,13 @@ const NativeView: React.ComponentType< const NativeModule = requireNativeModule('BottomSheet') +const isIOS15 = Platform.OS === 'ios' && Number(Platform.Version) < 16 + export class BottomSheetNativeComponent extends React.Component< BottomSheetViewProps, { open: boolean + viewHeight?: number } > { ref = React.createRef<any>() @@ -67,6 +70,19 @@ export class BottomSheetNativeComponent extends React.Component< const {children, backgroundColor, ...rest} = this.props const cornerRadius = rest.cornerRadius ?? 0 + let extraStyles + if (isIOS15 && this.state.viewHeight) { + const {viewHeight} = this.state + if (viewHeight < screenHeight / 2) { + extraStyles = { + height: viewHeight, + marginTop: screenHeight / 2 - viewHeight, + borderTopLeftRadius: cornerRadius, + borderTopRightRadius: cornerRadius, + } + } + } + if (!this.state.open) { return null } @@ -92,8 +108,14 @@ export class BottomSheetNativeComponent extends React.Component< borderTopLeftRadius: cornerRadius, borderTopRightRadius: cornerRadius, }, + extraStyles, ]}> - <View onLayout={this.updateLayout}> + <View + onLayout={e => { + const {height} = e.nativeEvent.layout + this.setState({viewHeight: height}) + this.updateLayout() + }}> <BottomSheetPortalProvider>{children}</BottomSheetPortalProvider> </View> </View> |