Skip to content

Commit 0087028

Browse files
authored
chore: updated props naming (#89)
* chore: updated current props * chore: updated examples
1 parent 0bc1a47 commit 0087028

File tree

16 files changed

+134
-84
lines changed

16 files changed

+134
-84
lines changed

example/src/components/handle/Handle.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ interface HandleProps extends BottomSheetHandleProps {
88
style?: StyleProp<ViewStyle>;
99
}
1010

11-
const Handle: React.FC<HandleProps> = ({ style, animatedPositionIndex }) => {
11+
const Handle: React.FC<HandleProps> = ({ style, animatedIndex }) => {
1212
//#region animations
1313
const borderTopRadius = useMemo(
1414
() =>
15-
interpolate(animatedPositionIndex, {
15+
interpolate(animatedIndex, {
1616
inputRange: [1, 2],
1717
outputRange: [20, 0],
1818
extrapolate: Extrapolate.CLAMP,
1919
}),
20-
[animatedPositionIndex]
20+
[animatedIndex]
2121
);
2222
const indicatorTransformOriginY = useMemo(
2323
() =>
24-
interpolate(animatedPositionIndex, {
24+
interpolate(animatedIndex, {
2525
inputRange: [0, 1, 2],
2626
outputRange: [-1, 0, 1],
2727
extrapolate: Extrapolate.CLAMP,
2828
}),
29-
[animatedPositionIndex]
29+
[animatedIndex]
3030
);
3131
const leftIndicatorRotate = useMemo(
3232
() =>
33-
interpolate(animatedPositionIndex, {
33+
interpolate(animatedIndex, {
3434
inputRange: [0, 1, 2],
3535
outputRange: [toRad(-30), 0, toRad(30)],
3636
extrapolate: Extrapolate.CLAMP,
3737
}),
38-
[animatedPositionIndex]
38+
[animatedIndex]
3939
);
40-
const rightIndicatorRotate = interpolate(animatedPositionIndex, {
40+
const rightIndicatorRotate = interpolate(animatedIndex, {
4141
inputRange: [0, 1, 2],
4242
outputRange: [toRad(30), 0, toRad(-30)],
4343
extrapolate: Extrapolate.CLAMP,

example/src/screens/advanced/CustomHandleExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ const CustomHandleExample = () => {
6969
/>
7070
<BottomSheet
7171
ref={bottomSheetRef}
72+
index={1}
7273
snapPoints={snapPoints}
73-
initialSnapIndex={1}
7474
handleComponent={Handle}
7575
>
7676
<ContactList type="View" count={3} header={renderHeader} />

example/src/screens/advanced/DynamicSnapPointExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ const DynamicSnapPointExample = () => {
7979
/>
8080
<BottomSheet
8181
ref={bottomSheetRef}
82+
index={1}
8283
snapPoints={snapPoints}
83-
initialSnapIndex={1}
8484
animateOnMount={true}
8585
animationEasing={Easing.out(Easing.quad)}
8686
animationDuration={250}

example/src/screens/advanced/MapExample.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const MapExample = () => {
4545
);
4646
const animatedPosition = useValue<number>(0);
4747
const animatedModalPosition = useValue<number>(0);
48-
const animatedPositionIndex = useValue<number>(0);
48+
const animatedIndex = useValue<number>(0);
4949
const animatedOverlayOpacity = useMemo(
5050
() =>
5151
interpolate(animatedPosition, {
@@ -87,7 +87,7 @@ const MapExample = () => {
8787
present(
8888
<LocationDetails onClose={handleCloseLocationDetails} {...item} />,
8989
{
90-
initialSnapIndex: 1,
90+
index: 1,
9191
snapPoints,
9292
topInset: topSafeArea,
9393
animatedPosition: animatedModalPosition,
@@ -115,7 +115,7 @@ const MapExample = () => {
115115
() => [
116116
styles.contentContainerStyle,
117117
{
118-
opacity: interpolate(animatedPositionIndex, {
118+
opacity: interpolate(animatedIndex, {
119119
inputRange: [0, 1],
120120
outputRange: [0, 1],
121121
extrapolate: Extrapolate.CLAMP,
@@ -168,16 +168,16 @@ const MapExample = () => {
168168
/>
169169
<BottomSheet
170170
ref={bottomSheetRef}
171+
index={1}
171172
snapPoints={snapPoints}
172-
initialSnapIndex={1}
173173
topInset={topSafeArea}
174174
animatedPosition={animatedPosition}
175-
animatedPositionIndex={animatedPositionIndex}
175+
animatedIndex={animatedIndex}
176176
animationDuration={500}
177177
animationEasing={Easing.out(Easing.exp)}
178+
onChange={handleSheetChanges}
178179
handleComponent={SearchHandle}
179180
backgroundComponent={BlurredBackground}
180-
onChange={handleSheetChanges}
181181
>
182182
<BottomSheetScrollView
183183
keyboardDismissMode="on-drag"

example/src/screens/advanced/NavigatorExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ const NavigatorExample = () => {
127127
/>
128128
<BottomSheet
129129
ref={bottomSheetRef}
130+
index={1}
130131
snapPoints={snapPoints}
131-
initialSnapIndex={1}
132132
onChange={handleSheetChange}
133133
>
134134
<Navigator />

example/src/screens/advanced/OverlayExample.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const OverlayExample = () => {
1212

1313
// variables
1414
const snapPoints = useMemo(() => ['25%', '50%', '90%'], []);
15-
const animatedPositionIndex = useValue<number>(0);
15+
const animatedIndex = useValue<number>(0);
1616

1717
// styles
1818
const shadowOverlayStyle = useMemo(
1919
() => ({
2020
...styles.shadowOverlay,
21-
opacity: interpolate(animatedPositionIndex, {
21+
opacity: interpolate(animatedIndex, {
2222
inputRange: [0, 2],
2323
outputRange: [0, 1],
2424
extrapolate: Extrapolate.CLAMP,
@@ -89,9 +89,9 @@ const OverlayExample = () => {
8989
<Animated.View pointerEvents="none" style={shadowOverlayStyle} />
9090
<BottomSheet
9191
ref={bottomSheetRef}
92+
index={1}
9293
snapPoints={snapPoints}
93-
initialSnapIndex={1}
94-
animatedPositionIndex={animatedPositionIndex}
94+
animatedIndex={animatedIndex}
9595
onChange={handleSheetChanges}
9696
>
9797
<ContactList type="View" count={3} header={renderHeader} />

example/src/screens/modal/StackExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const StackExample = () => {
3535
}, [dismissB]);
3636
const handlePresentCPress = useCallback(() => {
3737
presentC(<ContactListContainer title="Modal C" type="SectionList" />, {
38+
index: 1,
3839
snapPoints: ['25%', '50%'],
39-
initialSnapIndex: 1,
4040
animationDuration: 250,
4141
dismissOnScrollDown: false,
4242
});

example/src/screens/static/BasicExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const BasicExample = () => {
6363
<ReText text={concat('Position from bottom: ', position)} />
6464
<BottomSheet
6565
ref={bottomSheetRef}
66+
index={1}
6667
snapPoints={snapPoints}
67-
initialSnapIndex={1}
6868
topInset={topSafeArea}
6969
animatedPosition={position}
7070
onChange={handleSheetChanges}

example/src/screens/static/BasicExamples.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ const createExampleScreen = ({ type, count = 20 }: ExampleScreenProps) =>
109109
/>
110110
<BottomSheet
111111
ref={bottomSheetRef}
112+
index={1}
112113
snapPoints={snapPoints}
113-
initialSnapIndex={1}
114114
animateOnMount={true}
115115
enableContentPanningGesture={enableContentPanningGesture}
116116
enableHandlePanningGesture={enableHandlePanningGesture}

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ Animated.addWhitelistedUIProps({
7474
const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
7575
(
7676
{
77-
// animations
77+
// animations configurations
7878
animationDuration = DEFAULT_ANIMATION_DURATION,
7979
animationEasing = DEFAULT_ANIMATION_EASING,
8080
// configurations
81-
initialSnapIndex = 0,
81+
index: initialSnapIndex = 0,
8282
snapPoints: _snapPoints,
8383
handleHeight: _handleHeight,
8484
topInset = 0,
@@ -90,8 +90,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
9090
containerTapGestureRef,
9191
containerTapGestureState,
9292
// animated nodes callback
93-
animatedPosition: _animatedPosition,
94-
animatedPositionIndex: _animatedPositionIndex,
93+
animatedPosition: _animatedPositionCallbackNode,
94+
animatedIndex: _animatedIndexCallbackNode,
9595
// callbacks
9696
onChange: _onChange,
9797
// components
@@ -219,7 +219,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
219219
initialPosition,
220220
});
221221

222-
const animatedPositionIndex = useMemo(
222+
// animated values
223+
const animatedIndex = useMemo(
223224
() =>
224225
interpolate(position, {
225226
inputRange: snapPoints.slice().reverse(),
@@ -231,6 +232,12 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
231232
}),
232233
[position, snapPoints]
233234
);
235+
236+
const animatedPosition = useMemo(
237+
() => abs(sub(containerHeight, position)),
238+
[containerHeight, position]
239+
);
240+
234241
/**
235242
* Scrollable animated props.
236243
*/
@@ -453,18 +460,25 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
453460
const renderBackground = useCallback(
454461
() =>
455462
BackgroundComponent ? (
456-
<BackgroundComponent pointerEvents="none" />
463+
<BackgroundComponent
464+
pointerEvents="none"
465+
animatedIndex={animatedIndex}
466+
animatedPosition={animatedPosition}
467+
/>
457468
) : null,
458-
[BackgroundComponent]
469+
[BackgroundComponent, animatedIndex, animatedPosition]
459470
);
460471
const renderHandle = useCallback(
461472
() =>
462473
HandleComponent === null ? null : HandleComponent === undefined ? (
463474
<DefaultHandle />
464475
) : (
465-
<HandleComponent animatedPositionIndex={animatedPositionIndex} />
476+
<HandleComponent
477+
animatedIndex={animatedIndex}
478+
animatedPosition={animatedPosition}
479+
/>
466480
),
467-
[HandleComponent, animatedPositionIndex]
481+
[HandleComponent, animatedIndex, animatedPosition]
468482
);
469483
return (
470484
<>
@@ -491,15 +505,15 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
491505
</BottomSheetProvider>
492506
</Animated.View>
493507

494-
{_animatedPosition && (
508+
{_animatedPositionCallbackNode && (
495509
<Animated.Code
496-
exec={set(_animatedPosition, abs(sub(containerHeight, position)))}
510+
exec={set(_animatedPositionCallbackNode, animatedPosition)}
497511
/>
498512
)}
499513

500-
{_animatedPositionIndex && (
514+
{_animatedIndexCallbackNode && (
501515
<Animated.Code
502-
exec={set(_animatedPositionIndex, animatedPositionIndex)}
516+
exec={set(_animatedIndexCallbackNode, animatedIndex)}
503517
/>
504518
)}
505519
{/* <Animated.View pointerEvents="none" style={styles.debug}>

0 commit comments

Comments
 (0)