Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ module.exports = {
rules: {
'no-console': ['error', { allow: ['warn', 'error'] }],
'prettier/prettier': 'error',
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks: '(useAnimatedStyle|useDerivedValue|useAnimatedProps)',
},
],
},
};
19 changes: 11 additions & 8 deletions example/src/components/customBackground/CustomBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const CustomBackgroundComponent: React.FC<CustomBackgroundProps> = ({
animatedIndex,
}) => {
//#region styles
const containerAnimatedStyle = useAnimatedStyle(() => ({
// @ts-ignore
backgroundColor: interpolateColor(
animatedIndex.value,
[0, 1],
['#ffffff', '#a8b5eb']
),
}));
const containerAnimatedStyle = useAnimatedStyle(
() => ({
// @ts-ignore
backgroundColor: interpolateColor(
animatedIndex.value,
[0, 1],
['#ffffff', '#a8b5eb']
),
}),
[animatedIndex.value]
);
const containerStyle = useMemo(
() => [styles.container, style, containerAnimatedStyle],
[style, containerAnimatedStyle]
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/customFooter/CustomFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CustomFooterComponent = ({
return {
transform: [{ rotate: `${arrowRotate}rad` }],
};
}, []);
}, [animatedIndex.value]);
const arrowStyle = useMemo(
() => [arrowAnimatedStyle, styles.arrow],
[arrowAnimatedStyle]
Expand Down
17 changes: 12 additions & 5 deletions example/src/components/customHandle/CustomHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ const CustomHandleComponent: React.FC<CustomHandleProps> = ({
}) => {
//#region animations

const indicatorTransformOriginY = useDerivedValue(() =>
interpolate(animatedIndex.value, [0, 1, 2], [-1, 0, 1], Extrapolate.CLAMP)
const indicatorTransformOriginY = useDerivedValue(
() =>
interpolate(
animatedIndex.value,
[0, 1, 2],
[-1, 0, 1],
Extrapolate.CLAMP
),
[animatedIndex.value]
);
//#endregion

Expand All @@ -40,7 +47,7 @@ const CustomHandleComponent: React.FC<CustomHandleProps> = ({
borderTopLeftRadius: borderTopRadius,
borderTopRightRadius: borderTopRadius,
};
});
}, [animatedIndex.value]);
const leftIndicatorStyle = useMemo(
() => ({
...styles.indicator,
Expand All @@ -66,7 +73,7 @@ const CustomHandleComponent: React.FC<CustomHandleProps> = ({
}
),
};
});
}, [animatedIndex.value, indicatorTransformOriginY.value]);
const rightIndicatorStyle = useMemo(
() => ({
...styles.indicator,
Expand All @@ -92,7 +99,7 @@ const CustomHandleComponent: React.FC<CustomHandleProps> = ({
}
),
};
});
}, [animatedIndex.value, indicatorTransformOriginY.value]);
//#endregion

// render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export const LocationListBottomSheet = forwardRef<
//#endregion

//#region styles
const scrollViewAnimatedStyle = useAnimatedStyle(() => ({
opacity: index.value,
}));
const scrollViewAnimatedStyle = useAnimatedStyle(
() => ({
opacity: index.value,
}),
[index.value]
);
const scrollViewStyle = useMemo(
() => [styles.scrollView, scrollViewAnimatedStyle],
[scrollViewAnimatedStyle]
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/integrations/map/Weather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Weather = ({ animatedIndex, animatedPosition }: WeatherProps) => {
},
],
};
}, [height, screenHeight]);
}, [animatedIndex.value, animatedPosition.value, height, screenHeight]);
const containerStyle = useMemo(
() => [
styles.container,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"eslint-plugin-prettier": "^4.2.1",
"husky": "^4.3.8",
"lint-staged": "^13.2.2",
"metro-react-native-babel-preset": "^0.77.0",
"prettier": "^2.8.8",
"react": "18.2.0",
"react-native": "0.73.1",
Expand Down
56 changes: 44 additions & 12 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
return $modal
? _animatedContainerHeight.value - verticalInset
: _animatedContainerHeight.value;
}, [$modal, topInset, bottomInset]);
}, [topInset, bottomInset, $modal, _animatedContainerHeight.value]);
const animatedContainerOffset = useReactiveSharedValue(
_providedContainerOffset ?? INITIAL_CONTAINER_OFFSET
) as Animated.SharedValue<Insets>;
Expand All @@ -214,7 +214,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
maxDynamicContentSize
);
const animatedHighestSnapPoint = useDerivedValue(
() => animatedSnapPoints.value[animatedSnapPoints.value.length - 1]
() => animatedSnapPoints.value[animatedSnapPoints.value.length - 1],
[animatedSnapPoints.value]
);
const animatedClosedPosition = useDerivedValue(() => {
let closedPosition = animatedContainerHeight.value;
Expand All @@ -224,9 +225,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
}

return closedPosition;
}, [$modal, detached, bottomInset]);
}, [animatedContainerHeight.value, $modal, detached, bottomInset]);
const animatedSheetHeight = useDerivedValue(
() => animatedContainerHeight.value - animatedHighestSnapPoint.value
() => animatedContainerHeight.value - animatedHighestSnapPoint.value,
[animatedContainerHeight.value, animatedHighestSnapPoint.value]
);
const animatedCurrentIndex = useReactiveSharedValue(
animateOnMount ? -1 : _providedIndex
Expand Down Expand Up @@ -274,7 +276,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
isHandleHeightCalculated &&
isSnapPointsNormalized
);
});
}, [
_providedContainerHeight,
animatedContainerHeight.value,
animatedHandleHeight,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask when shall we use .value?

animatedSnapPoints.value,
handleComponent,
]);
const isInTemporaryPosition = useSharedValue(false);
const isForcedClosing = useSharedValue(false);

Expand Down Expand Up @@ -399,7 +407,12 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
}

return SCROLLABLE_STATE.LOCKED;
});
}, [
animatedAnimationState.value,
animatedKeyboardState.value,
animatedScrollableOverrideState.value,
animatedSheetState.value,
]);
// dynamic
const animatedContentHeightMax = useDerivedValue(() => {
const keyboardHeightInContainer = animatedKeyboardHeightInContainer.value;
Expand Down Expand Up @@ -513,7 +526,18 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
}

return currentIndex;
}, [android_keyboardInputMode]);
}, [
android_keyboardInputMode,
animatedAnimationSource.value,
animatedAnimationState.value,
animatedContainerHeight.value,
animatedCurrentIndex.value,
animatedNextPositionIndex.value,
animatedPosition.value,
animatedSnapPoints.value,
isInTemporaryPosition.value,
isLayoutCalculated.value,
]);
//#endregion

//#region private methods
Expand Down Expand Up @@ -1258,7 +1282,12 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
configs: _providedAnimationConfigs,
}),
};
}, [animatedContentHeightMax, enableDynamicSizing, animatedContentHeight]);
}, [
enableDynamicSizing,
animatedContentHeight.value,
animatedContentHeightMax.value,
_providedAnimationConfigs,
]);
const contentContainerStyle = useMemo(
() => [styles.contentContainer, contentContainerAnimatedStyle],
[contentContainerAnimatedStyle]
Expand All @@ -1277,7 +1306,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
return {
paddingBottom: animatedContainerHeight.value,
};
}, [detached]);
}, [animatedContainerHeight.value, detached]);
const contentMaskContainerStyle = useMemo(
() => [styles.contentMaskContainer, contentMaskContainerAnimatedStyle],
[contentMaskContainerAnimatedStyle]
Expand Down Expand Up @@ -1424,7 +1453,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
}
}
animateToPosition(nextPosition, animationSource, 0, animationConfig);
}
},
[]
);

/**
Expand Down Expand Up @@ -1547,7 +1577,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
if (_providedAnimatedPosition) {
_providedAnimatedPosition.value = _animatedPosition + topInset;
}
}
},
[]
);

/**
Expand All @@ -1559,7 +1590,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
if (_providedAnimatedIndex) {
_providedAnimatedIndex.value = _animatedIndex;
}
}
},
[]
);

/**
Expand Down
21 changes: 12 additions & 9 deletions src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ const BottomSheetBackdropComponent = ({
//#endregion

//#region styles
const containerAnimatedStyle = useAnimatedStyle(() => ({
opacity: interpolate(
animatedIndex.value,
[-1, disappearsOnIndex, appearsOnIndex],
[0, 0, opacity],
Extrapolation.CLAMP
),
flex: 1,
}));
const containerAnimatedStyle = useAnimatedStyle(
() => ({
opacity: interpolate(
animatedIndex.value,
[-1, disappearsOnIndex, appearsOnIndex],
[0, 0, opacity],
Extrapolation.CLAMP
),
flex: 1,
}),
[animatedIndex.value, appearsOnIndex, disappearsOnIndex, opacity]
);
const containerStyle = useMemo(
() => [styles.container, style, containerAnimatedStyle],
[style, containerAnimatedStyle]
Expand Down
5 changes: 3 additions & 2 deletions src/components/bottomSheetDebugView/ReText.webx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ReText = (props: TextProps) => {
: _providedValue.value;

return `${text}: ${value}`;
});
}, [_providedValue, text]);

//region effects
useAnimatedReaction(
Expand All @@ -35,7 +35,8 @@ const ReText = (props: TextProps) => {
textRef.current?.setNativeProps({
text: result,
});
}
},
[]
);
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ function BottomSheetRefreshControlComponent({
//#endregion

//#region variables
const animatedProps = useAnimatedProps(() => ({
enabled: animatedScrollableState.value === SCROLLABLE_STATE.UNLOCKED,
}));
const animatedProps = useAnimatedProps(
() => ({
enabled: animatedScrollableState.value === SCROLLABLE_STATE.UNLOCKED,
}),
[animatedScrollableState.value]
);
const gesture = useMemo(
() =>
Gesture.Simultaneous(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function createBottomSheetScrollableComponent<T, P>(
? animatedFooterHeight.value
: 0,
}),
[enableFooterMarginAdjustment]
[animatedFooterHeight.value, enableFooterMarginAdjustment]
);
const containerStyle = useMemo(() => {
return enableFooterMarginAdjustment
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export const useKeyboard = () => {
if (result && params.length > 0) {
handleKeyboardEvent(params[0], params[1], params[2], params[3]);
}
}
},
[]
);
//#endregion

Expand Down
10 changes: 9 additions & 1 deletion src/hooks/useNormalizedSnapPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export const useNormalizedSnapPoints = (
_normalizedSnapPoints.indexOf(dynamicSnapPoint);

return _normalizedSnapPoints;
}, [snapPoints, enableDynamicSizing, maxDynamicContentSize]);
}, [
containerHeight.value,
snapPoints,
enableDynamicSizing,
handleHeight.value,
contentHeight.value,
maxDynamicContentSize,
dynamicSnapPointIndex,
]);
return [normalizedSnapPoints, dynamicSnapPointIndex];
};
Loading