Skip to content

Commit 246e512

Browse files
yedidyakethansharM-i-k-e-l
committed
Update version of react-native-reanimated to 2.4.0 (#1821)
* Update versions of react-native-reanimated and react-native-gesture-handler * Update reanimated to 2.3.1 * Fix exposed issue with interpolateColors can't handle undefined values * Bumped reanimated to 2.4.0 * Fix TabController on Android Swipe the carousel, label does not change color. * Fix tests (workarounds) * Remove expect errors * Change function name See https://github.com/software-mansion/react-native-reanimated/pull/2792/files * Remove setup which seems to be no longer needed * Revert to old function (for users who use older versions of reanimated) * Change to noop * Allow overriding onMomentumScrollEnd * Fix types Co-authored-by: Ethan Sharabi <[email protected]> Co-authored-by: Miki Leib <[email protected]> (cherry picked from commit 1a8a07a)
1 parent 75b3aae commit 246e512

File tree

11 files changed

+36
-22
lines changed

11 files changed

+36
-22
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/// <reference types="react" />
2+
import { ScrollViewProps } from 'react-native';
23
/**
34
* @description: TabController's Page Carousel
45
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
56
* @notes: You must pass `asCarousel` flag to TabController and render your TabPages inside a PageCarousel
67
*/
7-
declare function PageCarousel({ ...props }: {
8-
[x: string]: any;
9-
}): JSX.Element;
8+
declare function PageCarousel(props: ScrollViewProps): JSX.Element;
109
export default PageCarousel;

generatedTypes/src/incubator/TransitionView/useAnimatedTranslator.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export default function useAnimatedTranslator(props: TranslatorProps): {
88
init: (to: {
99
x: number;
1010
y: number;
11-
}, animationDirection: TransitionViewDirection, callback: (isFinished: boolean) => void) => void;
11+
}, animationDirection: TransitionViewDirection, callback: (isFinished?: boolean | undefined) => void) => void;
1212
animate: (to: {
1313
x: number;
1414
y: number;
15-
}, animationDirection: TransitionViewDirection, callback: (isFinished: boolean) => void) => void;
15+
}, animationDirection: TransitionViewDirection, callback: (isFinished?: boolean | undefined) => void) => void;
1616
animatedStyle: {
1717
transform: ({
1818
translateX: number;

generatedTypes/src/incubator/TransitionView/useAnimationEndNotifier.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export interface AnimationNotifierEndProps {
66
onAnimationEnd?: (animationType: TransitionViewAnimationType) => void;
77
}
88
export default function useAnimationEndNotifier(props: AnimationNotifierEndProps): {
9-
onEnterAnimationEnd: (isFinished: boolean) => void;
10-
onExitAnimationEnd: (isFinished: boolean) => void;
9+
onEnterAnimationEnd: (isFinished?: boolean | undefined) => void;
10+
onExitAnimationEnd: (isFinished?: boolean | undefined) => void;
1111
};

jest-setup.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import {NativeModules, AccessibilityInfo} from 'react-native';
22

3-
require('./node_modules/react-native-reanimated/src/reanimated2/jestUtils').setUpTests();
4-
53
NativeModules.StatusBarManager = {getHeight: jest.fn()};
64
jest.spyOn(AccessibilityInfo, 'isScreenReaderEnabled').mockImplementation(() => new Promise.resolve(false));
75

86
// mock native modules
97
jest.mock('@react-native-community/blur', () => {});
108
jest.mock('@react-native-community/netinfo', () => {});
11-
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
9+
// TODO: Adding here a todo for package.json: need to remove moduleNameMapper, see this: https://github.com/software-mansion/react-native-reanimated/issues/1196
10+
jest.mock('react-native-reanimated', () => {
11+
const reactNativeReanimated = require('react-native-reanimated/mock');
12+
reactNativeReanimated.interpolateColor = jest.fn(v => v); // TODO: See this https://github.com/software-mansion/react-native-reanimated/issues/2749
13+
return reactNativeReanimated;
14+
});
1215
global.__reanimatedWorkletInit = jest.fn();
1316
jest.mock('react-native-gesture-handler', () => {});
1417
jest.mock('@react-native-picker/picker', () => ({Picker: {Item: {}}}));

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"react-native-keyboard-tracking-view": "^5.6.1",
105105
"react-native-linear-gradient": "2.5.6",
106106
"react-native-navigation": "^7.19.1",
107-
"react-native-reanimated": "2.2.4",
107+
"react-native-reanimated": "2.4.0",
108108
"react-native-shimmer-placeholder": "^2.0.6",
109109
"react-native-svg": "^12.1.0",
110110
"react-native-svg-transformer": "^0.14.3",
@@ -133,6 +133,9 @@
133133
"setupFiles": [
134134
"./jest-setup.js"
135135
],
136+
"moduleNameMapper": {
137+
"^react-native-reanimated$": "<rootDir>/node_modules/react-native-reanimated/src/Animated.js"
138+
},
136139
"transform": {
137140
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
138141
}

src/components/segmentedControl/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Reanimated, {
77
useAnimatedStyle,
88
useSharedValue,
99
withTiming,
10+
WithTimingConfig,
1011
runOnJS
1112
} from 'react-native-reanimated';
1213
import {Colors, BorderRadiuses, Spacings} from '../../style';
@@ -16,8 +17,9 @@ import Segment, {SegmentedControlItemProps as SegmentProps} from './segment';
1617
import {useOrientation} from 'hooks';
1718

1819
const BORDER_WIDTH = 1;
19-
const TIMING_CONFIG = {
20+
const TIMING_CONFIG: WithTimingConfig = {
2021
duration: 300,
22+
// @ts-expect-error TODO: change this to bezierFn or to the new implementation
2123
easing: Easing.bezier(0.33, 1, 0.68, 1)
2224
};
2325

src/components/tabController/PageCarousel.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {useCallback, useContext, useMemo, useEffect} from 'react';
2+
import {NativeSyntheticEvent, NativeScrollEvent, ScrollViewProps} from 'react-native';
23
import TabBarContext from './TabBarContext';
34
import Reanimated, {
45
runOnJS,
@@ -16,7 +17,8 @@ const FIX_RTL = Constants.isRTL && Constants.isAndroid;
1617
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
1718
* @notes: You must pass `asCarousel` flag to TabController and render your TabPages inside a PageCarousel
1819
*/
19-
function PageCarousel({...props}) {
20+
function PageCarousel(props: ScrollViewProps) {
21+
const {onMomentumScrollEnd, ...others} = props;
2022
const carousel = useAnimatedRef<Reanimated.ScrollView>();
2123
const {
2224
itemsCount,
@@ -73,7 +75,6 @@ function PageCarousel({...props}) {
7375
}
7476

7577
const actualIndex = FIX_RTL ? itemsCount - index - 1 : index;
76-
// @ts-expect-error
7778
carousel.current?.scrollTo({x: actualIndex * pageWidth, animated: false});
7879
},
7980
[pageWidth, itemsCount]);
@@ -88,13 +89,16 @@ function PageCarousel({...props}) {
8889
});
8990

9091
useEffect(() => {
91-
// @ts-expect-error
9292
carousel.current?.scrollTo({x: currentPage.value * pageWidth, animated: false});
9393
}, [pageWidth]);
9494

95+
const handleOnMomentumScrollEnd = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
96+
onMomentumScrollEnd?.(event);
97+
}, [onMomentumScrollEnd]);
98+
9599
return (
96100
<Reanimated.ScrollView
97-
{...props}
101+
{...others}
98102
ref={carousel}
99103
horizontal
100104
pagingEnabled
@@ -103,6 +107,7 @@ function PageCarousel({...props}) {
103107
scrollEventThrottle={16}
104108
contentOffset={initialOffset} // iOS only
105109
onLayout={scrollToInitial} // Android only
110+
onMomentumScrollEnd={handleOnMomentumScrollEnd} // TODO: workaround for useAnimatedScrollHandler.onMomentumEnd not being called (https://github.com/software-mansion/react-native-reanimated/issues/2735)
106111
/>
107112
);
108113
}

src/incubator/TouchableOpacity.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ function TouchableOpacity(props: Props) {
135135
const scale = interpolate(isActive.value, [0, 1], [1, activeScale]);
136136

137137
return {
138-
backgroundColor: interpolateColor(isActive.value, [0, 1], [backgroundColor, activeColor]),
138+
backgroundColor: !feedbackColor
139+
? backgroundColor
140+
: interpolateColor(isActive.value, [0, 1], [backgroundColor, activeColor]),
139141
opacity,
140142
transform: [{scale}]
141143
};

src/incubator/TransitionView/useAnimatedTranslator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function useAnimatedTranslator(props: TranslatorProps) {
2222

2323
const init = useCallback((to: {x: number; y: number},
2424
animationDirection: TransitionViewDirection,
25-
callback: (isFinished: boolean) => void) => {
25+
callback: (isFinished?: boolean) => void) => {
2626
'worklet';
2727
// @ts-expect-error
2828
if ([TransitionViewDirectionEnum.LEFT, TransitionViewDirectionEnum.RIGHT].includes(animationDirection)) {
@@ -39,7 +39,7 @@ export default function useAnimatedTranslator(props: TranslatorProps) {
3939

4040
const animate = useCallback((to: {x: number; y: number},
4141
animationDirection: TransitionViewDirection,
42-
callback: (isFinished: boolean) => void) => {
42+
callback: (isFinished?: boolean) => void) => {
4343
'worklet';
4444
// @ts-expect-error
4545
if ([TransitionViewDirectionEnum.LEFT, TransitionViewDirectionEnum.RIGHT].includes(animationDirection)) {

src/incubator/TransitionView/useAnimationEndNotifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export interface AnimationNotifierEndProps {
1313
export default function useAnimationEndNotifier(props: AnimationNotifierEndProps) {
1414
const {onAnimationEnd} = props;
1515

16-
const onEnterAnimationEnd = useCallback((isFinished: boolean) => {
16+
const onEnterAnimationEnd = useCallback((isFinished?: boolean) => {
1717
'worklet';
1818
if (onAnimationEnd && isFinished) {
1919
runOnJS(onAnimationEnd)('enter');
2020
}
2121
},
2222
[onAnimationEnd]);
2323

24-
const onExitAnimationEnd = useCallback((isFinished: boolean) => {
24+
const onExitAnimationEnd = useCallback((isFinished?: boolean) => {
2525
'worklet';
2626
if (onAnimationEnd && isFinished) {
2727
runOnJS(onAnimationEnd)('exit');

src/incubator/panView/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const PanView = (props: Props) => {
111111
translationY.value = result.y;
112112
};
113113

114-
const dismiss = useCallback((isFinished: boolean) => {
114+
const dismiss = useCallback((isFinished?: boolean) => {
115115
'worklet';
116116
if (isFinished && waitingForDismiss.value && onDismiss) {
117117
waitingForDismiss.value = false;

0 commit comments

Comments
 (0)