simplify logic

This commit is contained in:
Hailey
2024-10-02 18:21:56 -07:00
parent 7489a70735
commit 0ce5d449f7
6 changed files with 66 additions and 19 deletions
+11 -2
View File
@@ -1,4 +1,13 @@
import {BottomSheetState, BottomSheetViewProps} from './src/BottomSheet.types'
import {
BottomSheetSnapPoint,
BottomSheetState,
BottomSheetViewProps,
} from './src/BottomSheet.types'
import {BottomSheetView} from './src/BottomSheetView'
export {type BottomSheetState, BottomSheetView, type BottomSheetViewProps}
export {
BottomSheetSnapPoint,
type BottomSheetState,
BottomSheetView,
type BottomSheetViewProps,
}
+19 -12
View File
@@ -52,6 +52,22 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}
}
}
private var selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? {
didSet {
guard let selectedDetentIdentifier else {
return
}
if selectedDetentIdentifier == .large {
onSnapPointChange([
"snapPoint": 2
])
} else {
onSnapPointChange([
"snapPoint": 1
])
}
}
}
// MARK: - Lifecycle
@@ -104,11 +120,12 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}
let sheetVc = SheetViewController()
sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
if let sheet = sheetVc.sheetPresentationController {
sheet.delegate = self
sheet.preferredCornerRadius = self.cornerRadius
self.selectedDetentIdentifier = sheet.selectedDetentIdentifier
}
sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
sheetVc.view.addSubview(innerView)
self.sheetVc = sheetVc
@@ -161,16 +178,6 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}
func sheetPresentationControllerDidChangeSelectedDetentIdentifier(_ sheetPresentationController: UISheetPresentationController) {
let identifier = sheetPresentationController.selectedDetentIdentifier
if identifier == .large {
onSnapPointChange([
"snapPoint": 2,
])
} else {
onSnapPointChange([
"snapPoint": 1,
])
}
self.selectedDetentIdentifier = sheetPresentationController.selectedDetentIdentifier
}
}
+10 -1
View File
@@ -3,6 +3,12 @@ import {ColorValue, NativeSyntheticEvent} from 'react-native'
export type BottomSheetState = 'closed' | 'closing' | 'open' | 'opening'
export enum BottomSheetSnapPoint {
Hidden,
Partial,
Full,
}
export interface BottomSheetViewProps {
children: React.ReactNode
cornerRadius?: number
@@ -15,8 +21,11 @@ export interface BottomSheetViewProps {
minHeight?: number
maxHeight?: number
onAttemptDismiss?: (event: NativeSyntheticEvent<object>) => void
onSnapPointChange?: (
event: NativeSyntheticEvent<{snapPoint: BottomSheetSnapPoint}>,
) => void
onStateChange?: (
event: NativeSyntheticEvent<{state: BottomSheetState}>,
) => void
onAttemptDismiss?: (event: NativeSyntheticEvent<object>) => void
}