about summary refs log tree commit diff
path: root/src/components/Dialog/sheet-wrapper.ts
blob: 37c66338379f924d13da2c18fe5eba0baefd1512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {useCallback} from 'react'

import {useDialogStateControlContext} from '#/state/dialogs'

/**
 * If we're calling a system API like the image picker that opens a sheet
 * wrap it in this function to make sure the status bar is the correct color.
 */
export function useSheetWrapper() {
  const {setFullyExpandedCount} = useDialogStateControlContext()
  return useCallback(
    async <T>(promise: Promise<T>): Promise<T> => {
      setFullyExpandedCount(c => c + 1)
      const res = await promise
      setFullyExpandedCount(c => c - 1)
      return res
    },
    [setFullyExpandedCount],
  )
}