diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 3492146ba..9c83cd763 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -874,6 +874,8 @@ const BottomSheetComponent = forwardRef( ); const externalContextVariables = useMemo( () => ({ + animatedIndex, + animatedPosition, snapToIndex: handleSnapToIndex, snapToPosition: handleSnapToPosition, expand: handleExpand, @@ -881,6 +883,8 @@ const BottomSheetComponent = forwardRef( close: handleClose, }), [ + animatedIndex, + animatedPosition, handleSnapToIndex, handleSnapToPosition, handleExpand, diff --git a/src/components/bottomSheetBackdrop/types.d.ts b/src/components/bottomSheetBackdrop/types.d.ts index 5472507c2..7cfcb4dbf 100644 --- a/src/components/bottomSheetBackdrop/types.d.ts +++ b/src/components/bottomSheetBackdrop/types.d.ts @@ -1,18 +1,9 @@ import type { ViewProps } from 'react-native'; -import type Animated from 'react-native-reanimated'; +import type { BottomSheetVariables } from '../../types'; -export interface BottomSheetBackdropProps extends Pick { - /** - * Current sheet position index. - * @type Animated.SharedValue - */ - animatedIndex: Animated.SharedValue; - /** - * Current sheet position. - * @type Animated.SharedValue - */ - animatedPosition: Animated.SharedValue; -} +export interface BottomSheetBackdropProps + extends Pick, + BottomSheetVariables {} export type BackdropPressBehavior = 'none' | 'close' | 'collapse' | number; diff --git a/src/components/bottomSheetBackground/types.d.ts b/src/components/bottomSheetBackground/types.d.ts index 8ed0d7343..37d2e20db 100644 --- a/src/components/bottomSheetBackground/types.d.ts +++ b/src/components/bottomSheetBackground/types.d.ts @@ -1,16 +1,6 @@ -import type Animated from 'react-native-reanimated'; import type { ViewProps } from 'react-native'; +import type { BottomSheetVariables } from '../../types'; export interface BottomSheetBackgroundProps - extends Pick { - /** - * Current sheet position index. - * @type Animated.SharedValue - */ - animatedIndex: Animated.SharedValue; - /** - * Current sheet position. - * @type Animated.SharedValue - */ - animatedPosition: Animated.SharedValue; -} + extends Pick, + BottomSheetVariables {} diff --git a/src/components/bottomSheetHandle/types.d.ts b/src/components/bottomSheetHandle/types.d.ts index 3fd378600..b80113f2b 100644 --- a/src/components/bottomSheetHandle/types.d.ts +++ b/src/components/bottomSheetHandle/types.d.ts @@ -1,14 +1,3 @@ -import type Animated from 'react-native-reanimated'; +import type { BottomSheetVariables } from '../../types'; -export interface BottomSheetHandleProps { - /** - * Current sheet position index. - * @type Animated.Value - */ - animatedIndex: Animated.SharedValue; - /** - * Current sheet position. - * @type Animated.Value - */ - animatedPosition: Animated.SharedValue; -} +export interface BottomSheetHandleProps extends BottomSheetVariables {} diff --git a/src/components/bottomSheetTextInput/types.ts b/src/components/bottomSheetTextInput/types.ts index 0fc642f72..a64f90b89 100644 --- a/src/components/bottomSheetTextInput/types.ts +++ b/src/components/bottomSheetTextInput/types.ts @@ -1,4 +1,3 @@ -import type { ComponentProps } from 'react'; -import type { TextInput } from 'react-native-gesture-handler'; +import type { TextInputProps } from 'react-native'; -export interface BottomSheetTextInputProps extends ComponentProps {} +export interface BottomSheetTextInputProps extends TextInputProps {} diff --git a/src/components/view/View.tsx b/src/components/view/View.tsx index 208dd9a26..261f8a98e 100644 --- a/src/components/view/View.tsx +++ b/src/components/view/View.tsx @@ -3,7 +3,6 @@ import { View as RNView } from 'react-native'; import { useBottomSheetInternal } from '../../hooks'; import type { BottomSheetViewProps } from './types'; import { styles } from './styles'; -import { runOnUI } from 'react-native-reanimated'; const BottomSheetViewComponent = ({ style, @@ -26,9 +25,7 @@ const BottomSheetViewComponent = ({ // callback const handleSettingScrollable = useCallback(() => { - runOnUI(() => { - scrollableContentOffsetY.value = 0; - })(); + scrollableContentOffsetY.value = 0; }, [scrollableContentOffsetY]); // effects diff --git a/src/contexts/external.ts b/src/contexts/external.ts index 8f70eae2f..3b3ec6d2b 100644 --- a/src/contexts/external.ts +++ b/src/contexts/external.ts @@ -1,7 +1,7 @@ import { createContext } from 'react'; -import type { BottomSheetMethods } from '../types'; +import type { BottomSheetMethods, BottomSheetVariables } from '../types'; export const BottomSheetContext = - createContext(null); + createContext<(BottomSheetMethods & BottomSheetVariables) | null>(null); export const BottomSheetProvider = BottomSheetContext.Provider; diff --git a/src/hooks/useBottomSheet.ts b/src/hooks/useBottomSheet.ts index a24fe548a..e4fcfdaac 100644 --- a/src/hooks/useBottomSheet.ts +++ b/src/hooks/useBottomSheet.ts @@ -5,7 +5,7 @@ export const useBottomSheet = () => { const context = useContext(BottomSheetContext); if (context === null) { - throw "'BottomSheetContext' cannot be null!"; + throw "'useBottomSheet' cannot be used out of the BottomSheet!"; } return context; diff --git a/src/hooks/useBottomSheetInternal.ts b/src/hooks/useBottomSheetInternal.ts index e849df538..f0980087d 100644 --- a/src/hooks/useBottomSheetInternal.ts +++ b/src/hooks/useBottomSheetInternal.ts @@ -5,7 +5,7 @@ export const useBottomSheetInternal = () => { const context = useContext(BottomSheetInternalContext); if (context === null) { - throw "'BottomSheetInternalContext' cannot be null!"; + throw "'useBottomSheetInternal' cannot be used out of the BottomSheet!"; } return context; diff --git a/src/index.ts b/src/index.ts index aa70442e0..03b84cb9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ export { useBottomSheet } from './hooks/useBottomSheet'; export { useBottomSheetModal } from './hooks/useBottomSheetModal'; export { useBottomSheetSpringConfigs } from './hooks/useBottomSheetSpringConfigs'; export { useBottomSheetTimingConfigs } from './hooks/useBottomSheetTimingConfigs'; +export { useBottomSheetInternal } from './hooks/useBottomSheetInternal'; //#endregion //#region components diff --git a/src/types.d.ts b/src/types.d.ts index eda152d30..8cec9ccdd 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -77,6 +77,19 @@ export interface BottomSheetModalMethods extends BottomSheetMethods { } //#endregion +export interface BottomSheetVariables { + /** + * Current sheet position index. + * @type Animated.Value + */ + animatedIndex: Animated.SharedValue; + /** + * Current sheet position. + * @type Animated.Value + */ + animatedPosition: Animated.SharedValue; +} + //#region scrollables export type Scrollable = FlatList | ScrollView | SectionList;