import * as React from 'react' import { Dimensions, NativeSyntheticEvent, Platform, StyleProp, View, ViewStyle, } from 'react-native' import {requireNativeModule, requireNativeViewManager} from 'expo-modules-core' import {BottomSheetState, BottomSheetViewProps} from './BottomSheet.types' import {BottomSheetPortalProvider} from './BottomSheetPortal' const screenHeight = Dimensions.get('screen').height const NativeView: React.ComponentType< BottomSheetViewProps & { ref: React.RefObject style: StyleProp } > = requireNativeViewManager('BottomSheet') const NativeModule = requireNativeModule('BottomSheet') export class BottomSheetNativeComponent extends React.Component< BottomSheetViewProps, { open: boolean } > { ref = React.createRef() constructor(props: BottomSheetViewProps) { super(props) this.state = { open: false, } } present() { this.setState({open: true}) } dismiss() { this.ref.current?.dismiss() } private onStateChange = ( event: NativeSyntheticEvent<{state: BottomSheetState}>, ) => { const {state} = event.nativeEvent const isOpen = state !== 'closed' this.setState({open: isOpen}) this.props.onStateChange?.(event) } private updateLayout = () => { this.ref.current?.updateLayout() } static dismissAll = async () => { await NativeModule.dismissAll() } render() { const {children, backgroundColor, ...rest} = this.props const cornerRadius = rest.cornerRadius ?? 0 if (!this.state.open) { return null } return ( {children} ) } }