Skip to content

Commit

Permalink
chore: export useBottomSheetInternal, added animatedPosition and anim…
Browse files Browse the repository at this point in the history
…atedIndex to useBottomSheet
  • Loading branch information
gorhom committed Jun 3, 2021
1 parent 069c4b6 commit fb3df59
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 50 deletions.
4 changes: 4 additions & 0 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,13 +874,17 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
);
const externalContextVariables = useMemo(
() => ({
animatedIndex,
animatedPosition,
snapToIndex: handleSnapToIndex,
snapToPosition: handleSnapToPosition,
expand: handleExpand,
collapse: handleCollapse,
close: handleClose,
}),
[
animatedIndex,
animatedPosition,
handleSnapToIndex,
handleSnapToPosition,
handleExpand,
Expand Down
17 changes: 4 additions & 13 deletions src/components/bottomSheetBackdrop/types.d.ts
Original file line number Diff line number Diff line change
@@ -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<ViewProps, 'style'> {
/**
* Current sheet position index.
* @type Animated.SharedValue<number>
*/
animatedIndex: Animated.SharedValue<number>;
/**
* Current sheet position.
* @type Animated.SharedValue<number>
*/
animatedPosition: Animated.SharedValue<number>;
}
export interface BottomSheetBackdropProps
extends Pick<ViewProps, 'style'>,
BottomSheetVariables {}

export type BackdropPressBehavior = 'none' | 'close' | 'collapse' | number;

Expand Down
16 changes: 3 additions & 13 deletions src/components/bottomSheetBackground/types.d.ts
Original file line number Diff line number Diff line change
@@ -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<ViewProps, 'pointerEvents' | 'style'> {
/**
* Current sheet position index.
* @type Animated.SharedValue<number>
*/
animatedIndex: Animated.SharedValue<number>;
/**
* Current sheet position.
* @type Animated.SharedValue<number>
*/
animatedPosition: Animated.SharedValue<number>;
}
extends Pick<ViewProps, 'pointerEvents' | 'style'>,
BottomSheetVariables {}
15 changes: 2 additions & 13 deletions src/components/bottomSheetHandle/types.d.ts
Original file line number Diff line number Diff line change
@@ -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<number>
*/
animatedIndex: Animated.SharedValue<number>;
/**
* Current sheet position.
* @type Animated.Value<number>
*/
animatedPosition: Animated.SharedValue<number>;
}
export interface BottomSheetHandleProps extends BottomSheetVariables {}
5 changes: 2 additions & 3 deletions src/components/bottomSheetTextInput/types.ts
Original file line number Diff line number Diff line change
@@ -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<TextInput> {}
export interface BottomSheetTextInputProps extends TextInputProps {}
5 changes: 1 addition & 4 deletions src/components/view/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,9 +25,7 @@ const BottomSheetViewComponent = ({

// callback
const handleSettingScrollable = useCallback(() => {
runOnUI(() => {
scrollableContentOffsetY.value = 0;
})();
scrollableContentOffsetY.value = 0;
}, [scrollableContentOffsetY]);

// effects
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/external.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import type { BottomSheetMethods } from '../types';
import type { BottomSheetMethods, BottomSheetVariables } from '../types';

export const BottomSheetContext =
createContext<BottomSheetMethods | null>(null);
createContext<(BottomSheetMethods & BottomSheetVariables) | null>(null);

export const BottomSheetProvider = BottomSheetContext.Provider;
2 changes: 1 addition & 1 deletion src/hooks/useBottomSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useBottomSheetInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ export interface BottomSheetModalMethods extends BottomSheetMethods {
}
//#endregion

export interface BottomSheetVariables {
/**
* Current sheet position index.
* @type Animated.Value<number>
*/
animatedIndex: Animated.SharedValue<number>;
/**
* Current sheet position.
* @type Animated.Value<number>
*/
animatedPosition: Animated.SharedValue<number>;
}

//#region scrollables
export type Scrollable = FlatList | ScrollView | SectionList;

Expand Down

0 comments on commit fb3df59

Please sign in to comment.