Skip to content

Commit

Permalink
chore: updated props naming (#89)
Browse files Browse the repository at this point in the history
* chore: updated current props

* chore: updated examples
  • Loading branch information
gorhom committed Nov 30, 2020
1 parent 0bc1a47 commit 0087028
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 84 deletions.
16 changes: 8 additions & 8 deletions example/src/components/handle/Handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ interface HandleProps extends BottomSheetHandleProps {
style?: StyleProp<ViewStyle>;
}

const Handle: React.FC<HandleProps> = ({ style, animatedPositionIndex }) => {
const Handle: React.FC<HandleProps> = ({ style, animatedIndex }) => {
//#region animations
const borderTopRadius = useMemo(
() =>
interpolate(animatedPositionIndex, {
interpolate(animatedIndex, {
inputRange: [1, 2],
outputRange: [20, 0],
extrapolate: Extrapolate.CLAMP,
}),
[animatedPositionIndex]
[animatedIndex]
);
const indicatorTransformOriginY = useMemo(
() =>
interpolate(animatedPositionIndex, {
interpolate(animatedIndex, {
inputRange: [0, 1, 2],
outputRange: [-1, 0, 1],
extrapolate: Extrapolate.CLAMP,
}),
[animatedPositionIndex]
[animatedIndex]
);
const leftIndicatorRotate = useMemo(
() =>
interpolate(animatedPositionIndex, {
interpolate(animatedIndex, {
inputRange: [0, 1, 2],
outputRange: [toRad(-30), 0, toRad(30)],
extrapolate: Extrapolate.CLAMP,
}),
[animatedPositionIndex]
[animatedIndex]
);
const rightIndicatorRotate = interpolate(animatedPositionIndex, {
const rightIndicatorRotate = interpolate(animatedIndex, {
inputRange: [0, 1, 2],
outputRange: [toRad(30), 0, toRad(-30)],
extrapolate: Extrapolate.CLAMP,
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/advanced/CustomHandleExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const CustomHandleExample = () => {
/>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
handleComponent={Handle}
>
<ContactList type="View" count={3} header={renderHeader} />
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/advanced/DynamicSnapPointExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const DynamicSnapPointExample = () => {
/>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
animateOnMount={true}
animationEasing={Easing.out(Easing.quad)}
animationDuration={250}
Expand Down
12 changes: 6 additions & 6 deletions example/src/screens/advanced/MapExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const MapExample = () => {
);
const animatedPosition = useValue<number>(0);
const animatedModalPosition = useValue<number>(0);
const animatedPositionIndex = useValue<number>(0);
const animatedIndex = useValue<number>(0);
const animatedOverlayOpacity = useMemo(
() =>
interpolate(animatedPosition, {
Expand Down Expand Up @@ -87,7 +87,7 @@ const MapExample = () => {
present(
<LocationDetails onClose={handleCloseLocationDetails} {...item} />,
{
initialSnapIndex: 1,
index: 1,
snapPoints,
topInset: topSafeArea,
animatedPosition: animatedModalPosition,
Expand Down Expand Up @@ -115,7 +115,7 @@ const MapExample = () => {
() => [
styles.contentContainerStyle,
{
opacity: interpolate(animatedPositionIndex, {
opacity: interpolate(animatedIndex, {
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: Extrapolate.CLAMP,
Expand Down Expand Up @@ -168,16 +168,16 @@ const MapExample = () => {
/>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
topInset={topSafeArea}
animatedPosition={animatedPosition}
animatedPositionIndex={animatedPositionIndex}
animatedIndex={animatedIndex}
animationDuration={500}
animationEasing={Easing.out(Easing.exp)}
onChange={handleSheetChanges}
handleComponent={SearchHandle}
backgroundComponent={BlurredBackground}
onChange={handleSheetChanges}
>
<BottomSheetScrollView
keyboardDismissMode="on-drag"
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/advanced/NavigatorExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ const NavigatorExample = () => {
/>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
onChange={handleSheetChange}
>
<Navigator />
Expand Down
8 changes: 4 additions & 4 deletions example/src/screens/advanced/OverlayExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const OverlayExample = () => {

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

// styles
const shadowOverlayStyle = useMemo(
() => ({
...styles.shadowOverlay,
opacity: interpolate(animatedPositionIndex, {
opacity: interpolate(animatedIndex, {
inputRange: [0, 2],
outputRange: [0, 1],
extrapolate: Extrapolate.CLAMP,
Expand Down Expand Up @@ -89,9 +89,9 @@ const OverlayExample = () => {
<Animated.View pointerEvents="none" style={shadowOverlayStyle} />
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
animatedPositionIndex={animatedPositionIndex}
animatedIndex={animatedIndex}
onChange={handleSheetChanges}
>
<ContactList type="View" count={3} header={renderHeader} />
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/modal/StackExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const StackExample = () => {
}, [dismissB]);
const handlePresentCPress = useCallback(() => {
presentC(<ContactListContainer title="Modal C" type="SectionList" />, {
index: 1,
snapPoints: ['25%', '50%'],
initialSnapIndex: 1,
animationDuration: 250,
dismissOnScrollDown: false,
});
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/static/BasicExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const BasicExample = () => {
<ReText text={concat('Position from bottom: ', position)} />
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
topInset={topSafeArea}
animatedPosition={position}
onChange={handleSheetChanges}
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/static/BasicExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const createExampleScreen = ({ type, count = 20 }: ExampleScreenProps) =>
/>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
initialSnapIndex={1}
animateOnMount={true}
enableContentPanningGesture={enableContentPanningGesture}
enableHandlePanningGesture={enableHandlePanningGesture}
Expand Down
40 changes: 27 additions & 13 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ Animated.addWhitelistedUIProps({
const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
(
{
// animations
// animations configurations
animationDuration = DEFAULT_ANIMATION_DURATION,
animationEasing = DEFAULT_ANIMATION_EASING,
// configurations
initialSnapIndex = 0,
index: initialSnapIndex = 0,
snapPoints: _snapPoints,
handleHeight: _handleHeight,
topInset = 0,
Expand All @@ -90,8 +90,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
containerTapGestureRef,
containerTapGestureState,
// animated nodes callback
animatedPosition: _animatedPosition,
animatedPositionIndex: _animatedPositionIndex,
animatedPosition: _animatedPositionCallbackNode,
animatedIndex: _animatedIndexCallbackNode,
// callbacks
onChange: _onChange,
// components
Expand Down Expand Up @@ -219,7 +219,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
initialPosition,
});

const animatedPositionIndex = useMemo(
// animated values
const animatedIndex = useMemo(
() =>
interpolate(position, {
inputRange: snapPoints.slice().reverse(),
Expand All @@ -231,6 +232,12 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
}),
[position, snapPoints]
);

const animatedPosition = useMemo(
() => abs(sub(containerHeight, position)),
[containerHeight, position]
);

/**
* Scrollable animated props.
*/
Expand Down Expand Up @@ -453,18 +460,25 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
const renderBackground = useCallback(
() =>
BackgroundComponent ? (
<BackgroundComponent pointerEvents="none" />
<BackgroundComponent
pointerEvents="none"
animatedIndex={animatedIndex}
animatedPosition={animatedPosition}
/>
) : null,
[BackgroundComponent]
[BackgroundComponent, animatedIndex, animatedPosition]
);
const renderHandle = useCallback(
() =>
HandleComponent === null ? null : HandleComponent === undefined ? (
<DefaultHandle />
) : (
<HandleComponent animatedPositionIndex={animatedPositionIndex} />
<HandleComponent
animatedIndex={animatedIndex}
animatedPosition={animatedPosition}
/>
),
[HandleComponent, animatedPositionIndex]
[HandleComponent, animatedIndex, animatedPosition]
);
return (
<>
Expand All @@ -491,15 +505,15 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
</BottomSheetProvider>
</Animated.View>

{_animatedPosition && (
{_animatedPositionCallbackNode && (
<Animated.Code
exec={set(_animatedPosition, abs(sub(containerHeight, position)))}
exec={set(_animatedPositionCallbackNode, animatedPosition)}
/>
)}

{_animatedPositionIndex && (
{_animatedIndexCallbackNode && (
<Animated.Code
exec={set(_animatedPositionIndex, animatedPositionIndex)}
exec={set(_animatedIndexCallbackNode, animatedIndex)}
/>
)}
{/* <Animated.View pointerEvents="none" style={styles.debug}>
Expand Down
Loading

0 comments on commit 0087028

Please sign in to comment.