@@ -5,10 +5,32 @@ import {
5
5
BottomSheetMachine ,
6
6
type BottomSheetEvent ,
7
7
} from '@bottom-sheet/state-machine'
8
+ import {
9
+ assignSnapPoints ,
10
+ assignInitialHeight ,
11
+ defaultInitialHeight ,
12
+ defaultSnapPoints ,
13
+ } from '@bottom-sheet/state-machine'
14
+ import type { GetInitialHeight , GetSnapPoints } from '@bottom-sheet/types'
15
+
16
+ export interface BottomSheetMachineProps {
17
+ initialHeight ?: GetInitialHeight
18
+ snapPoints ?: GetSnapPoints
19
+ }
8
20
9
- function createStore ( ) {
21
+ function createStore ( {
22
+ initialHeight = defaultInitialHeight ,
23
+ snapPoints = defaultSnapPoints ,
24
+ } : BottomSheetMachineProps = { } ) {
10
25
console . debug ( 'createStore' )
11
- const service = interpret ( BottomSheetMachine )
26
+ const service = interpret (
27
+ BottomSheetMachine . withConfig ( {
28
+ actions : {
29
+ setInitialHeight : assignInitialHeight ( initialHeight ) ,
30
+ setSnapPoints : assignSnapPoints ( snapPoints ) ,
31
+ } ,
32
+ } )
33
+ )
12
34
let snapshot = service . initialState
13
35
// transient is updated more frequently than the snapshot, outside of react render cycles
14
36
let transient = snapshot
@@ -44,8 +66,8 @@ function createStore() {
44
66
}
45
67
}
46
68
47
- export function useBottomSheetMachine ( ) {
48
- const [ store ] = useState ( ( ) => createStore ( ) )
69
+ export function useBottomSheetMachine ( props : BottomSheetMachineProps = { } ) {
70
+ const [ store ] = useState ( ( ) => createStore ( props ) )
49
71
/*
50
72
// useState lets us create the store exactly once, which is a guarantee that useMemo doesn't provide
51
73
const [store] = useState(() => {
0 commit comments