From b36f7dcfeab2ba628d3a61bca72b5589b86a5b73 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 10 Oct 2024 17:45:04 -0700 Subject: [PATCH] full fix --- modules/bottom-sheet/ios/SheetView.swift | 8 +---- .../ios/SheetViewController.swift | 34 +++++++++++------- .../src/BottomSheetNativeComponent.tsx | 36 +++++++++++++++---- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/modules/bottom-sheet/ios/SheetView.swift b/modules/bottom-sheet/ios/SheetView.swift index fea5814833..2223a5a8ca 100644 --- a/modules/bottom-sheet/ios/SheetView.swift +++ b/modules/bottom-sheet/ios/SheetView.swift @@ -23,13 +23,7 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { // React view props var preventDismiss = false - var preventExpansion = false { - didSet { - if #unavailable(iOS 16.0) { - preventExpansion = false - } - } - } + var preventExpansion = false var cornerRadius: CGFloat? var minHeight = 0.0 var maxHeight: CGFloat! { diff --git a/modules/bottom-sheet/ios/SheetViewController.swift b/modules/bottom-sheet/ios/SheetViewController.swift index 7b6606980d..ef0087877b 100644 --- a/modules/bottom-sheet/ios/SheetViewController.swift +++ b/modules/bottom-sheet/ios/SheetViewController.swift @@ -26,27 +26,37 @@ class SheetViewController: UIViewController { else { return } - - if contentHeight > screenHeight - 100 { - sheet.detents = [ - .large() - ] - sheet.selectedDetentIdentifier = .large - } else { - if #available(iOS 16.0, *) { + + if #available(iOS 16.0, *) { + if contentHeight > screenHeight - 100 { + sheet.detents = [ + .large() + ] + sheet.selectedDetentIdentifier = .large + } else { sheet.detents = [ .custom { _ in return contentHeight } ] + if !preventExpansion { + sheet.detents.append(.large()) + } + sheet.selectedDetentIdentifier = .medium + } + } else { + if contentHeight > screenHeight / 2 { + sheet.detents = [ + .large() + ] + sheet.selectedDetentIdentifier = .large } else { sheet.detents = [ .medium() ] - } - - if !preventExpansion { - sheet.detents.append(.large()) + if !preventExpansion { + sheet.detents.append(.large()) + } } sheet.selectedDetentIdentifier = .medium } diff --git a/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx b/modules/bottom-sheet/src/BottomSheetNativeComponent.tsx index eadd9b4a1d..f2b97fc631 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() @@ -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 } @@ -76,11 +92,13 @@ export class BottomSheetNativeComponent extends React.Component< {...rest} onStateChange={this.onStateChange} ref={this.ref} - style={{ - position: 'absolute', - height: screenHeight, - width: '100%', - }} + style={[ + { + position: 'absolute', + height: screenHeight, + width: '100%', + }, + ]} containerBackgroundColor={backgroundColor}> - + { + const {height} = e.nativeEvent.layout + this.setState({viewHeight: height}) + this.updateLayout() + }}> {children}