This commit is contained in:
Hailey
2024-10-10 17:45:04 -07:00
parent 016f71ffa1
commit b36f7dcfea
3 changed files with 53 additions and 25 deletions
+1 -7
View File
@@ -23,13 +23,7 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
// React view props // React view props
var preventDismiss = false var preventDismiss = false
var preventExpansion = false { var preventExpansion = false
didSet {
if #unavailable(iOS 16.0) {
preventExpansion = false
}
}
}
var cornerRadius: CGFloat? var cornerRadius: CGFloat?
var minHeight = 0.0 var minHeight = 0.0
var maxHeight: CGFloat! { var maxHeight: CGFloat! {
@@ -27,26 +27,36 @@ class SheetViewController: UIViewController {
return return
} }
if contentHeight > screenHeight - 100 { if #available(iOS 16.0, *) {
sheet.detents = [ if contentHeight > screenHeight - 100 {
.large() sheet.detents = [
] .large()
sheet.selectedDetentIdentifier = .large ]
} else { sheet.selectedDetentIdentifier = .large
if #available(iOS 16.0, *) { } else {
sheet.detents = [ sheet.detents = [
.custom { _ in .custom { _ in
return contentHeight return contentHeight
} }
] ]
if !preventExpansion {
sheet.detents.append(.large())
}
sheet.selectedDetentIdentifier = .medium
}
} else {
if contentHeight > screenHeight / 2 {
sheet.detents = [
.large()
]
sheet.selectedDetentIdentifier = .large
} else { } else {
sheet.detents = [ sheet.detents = [
.medium() .medium()
] ]
} if !preventExpansion {
sheet.detents.append(.large())
if !preventExpansion { }
sheet.detents.append(.large())
} }
sheet.selectedDetentIdentifier = .medium sheet.selectedDetentIdentifier = .medium
} }
@@ -23,10 +23,13 @@ const NativeView: React.ComponentType<
const NativeModule = requireNativeModule('BottomSheet') const NativeModule = requireNativeModule('BottomSheet')
const isIOS15 = Platform.OS === 'ios' && Number(Platform.Version) < 16
export class BottomSheetNativeComponent extends React.Component< export class BottomSheetNativeComponent extends React.Component<
BottomSheetViewProps, BottomSheetViewProps,
{ {
open: boolean open: boolean
viewHeight?: number
} }
> { > {
ref = React.createRef<any>() ref = React.createRef<any>()
@@ -67,6 +70,19 @@ export class BottomSheetNativeComponent extends React.Component<
const {children, backgroundColor, ...rest} = this.props const {children, backgroundColor, ...rest} = this.props
const cornerRadius = rest.cornerRadius ?? 0 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) { if (!this.state.open) {
return null return null
} }
@@ -76,11 +92,13 @@ export class BottomSheetNativeComponent extends React.Component<
{...rest} {...rest}
onStateChange={this.onStateChange} onStateChange={this.onStateChange}
ref={this.ref} ref={this.ref}
style={{ style={[
position: 'absolute', {
height: screenHeight, position: 'absolute',
width: '100%', height: screenHeight,
}} width: '100%',
},
]}
containerBackgroundColor={backgroundColor}> containerBackgroundColor={backgroundColor}>
<View <View
style={[ style={[
@@ -92,8 +110,14 @@ export class BottomSheetNativeComponent extends React.Component<
borderTopLeftRadius: cornerRadius, borderTopLeftRadius: cornerRadius,
borderTopRightRadius: 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> <BottomSheetPortalProvider>{children}</BottomSheetPortalProvider>
</View> </View>
</View> </View>