Skip to content

Commit 0f1eacd

Browse files
committed
feat: added Reanimated v2 compatibility
1 parent 57b497f commit 0f1eacd

File tree

10 files changed

+68
-31
lines changed

10 files changed

+68
-31
lines changed

example/src/components/CustomView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from 'react';
22
import { View, Text, StyleSheet, Alert, ViewStyle } from 'react-native';
3-
import Animated, { interpolate, Extrapolate } from 'react-native-reanimated';
3+
import Animated, { Extrapolate } from 'react-native-reanimated';
44
import { TouchableOpacity } from 'react-native-gesture-handler';
55
import { PageContentProps } from '@gorhom/paper-onboarding';
66
import { TouchableOpacityProps } from 'react-native';
77

8+
const {
9+
interpolate: interpolateV1,
10+
interpolateNode: interpolateV2,
11+
} = require('react-native-reanimated');
12+
const interpolate = interpolateV2 || interpolateV1;
13+
814
const AnimatedTouchableOpacity: React.FC<
915
Animated.AnimateProps<ViewStyle, TouchableOpacityProps>
1016
> = Animated.createAnimatedComponent(TouchableOpacity) as any;

src/PaperOnboarding.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import React, { useMemo, useRef, useCallback, memo, useState } from 'react';
22
import { Dimensions, Insets, LayoutChangeEvent } from 'react-native';
33
import { usePanGestureHandler, useValue } from 'react-native-redash';
44
import { PanGestureHandler } from 'react-native-gesture-handler';
5-
import Animated from 'react-native-reanimated';
5+
import Animated, {
6+
add,
7+
useCode,
8+
onChange,
9+
call,
10+
} from 'react-native-reanimated';
611
import Background from './components/background';
712
import Page from './components/page';
813
import IndicatorsContainer from './components/indicatorsContainer';
@@ -32,7 +37,11 @@ Animated.addWhitelistedUIProps({
3237
pointerEvents: true,
3338
});
3439

35-
const { interpolate, add, useCode, onChange, call } = Animated;
40+
const {
41+
interpolate: interpolateV1,
42+
interpolateNode: interpolateV2,
43+
} = require('react-native-reanimated');
44+
const interpolate = interpolateV2 || interpolateV1;
3645

3746
const PaperOnboardingComponent = ({
3847
data,

src/components/background/Background.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { memo, useMemo } from 'react';
22
import Svg from 'react-native-svg';
33
import BackgroundCircle from '../backgroundCircle';
44
import { calculateRectangleCircleRadius } from '../../utils/math';
5-
import { BackgroundProps } from '../../types';
65
import { styles } from './styles';
6+
import type { BackgroundProps } from '../../types';
77

88
const BackgroundComponent = ({
99
animatedIndex,

src/components/backgroundCircle/BackgroundCircle.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { memo } from 'react';
22
import { ViewStyle } from 'react-native';
33
import { Circle, CircleProps } from 'react-native-svg';
4-
import Animated, {
5-
interpolate,
6-
add,
7-
Extrapolate,
8-
} from 'react-native-reanimated';
9-
import { BackgroundCircleProps } from '../../types';
4+
import Animated, { add, Extrapolate } from 'react-native-reanimated';
5+
import type { BackgroundCircleProps } from '../../types';
6+
7+
const {
8+
interpolate: interpolateV1,
9+
interpolateNode: interpolateV2,
10+
} = require('react-native-reanimated');
11+
const interpolate = interpolateV2 || interpolateV1;
1012

1113
const AnimatedCircle = Animated.createAnimatedComponent(
1214
Circle

src/components/closeButton/CloseButton.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React, { useMemo, memo, useRef } from 'react';
22
import { Text, TouchableOpacity } from 'react-native';
3-
import Animated from 'react-native-reanimated';
3+
import Animated, { round } from 'react-native-reanimated';
44
import { useValues, get } from 'react-native-redash';
5-
import { CloseButtonProps } from '../../types';
65
import { styles } from './styles';
7-
8-
const { round } = Animated;
6+
import type { CloseButtonProps } from '../../types';
97

108
export const CloseButtonComponent = ({
119
data,

src/components/indicator/Indicator.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React, { useMemo, useCallback, memo } from 'react';
22
import { ViewStyle } from 'react-native';
3-
import Animated from 'react-native-reanimated';
3+
import Animated, { Extrapolate } from 'react-native-reanimated';
44
import { Svg, Circle, CircleProps } from 'react-native-svg';
5-
import { IndicatorProps } from '../../types';
65
import { styles } from './styles';
6+
import type { IndicatorProps } from '../../types';
77

8-
const { interpolate, Extrapolate } = Animated;
8+
const {
9+
interpolate: interpolateV1,
10+
interpolateNode: interpolateV2,
11+
} = require('react-native-reanimated');
12+
const interpolate = interpolateV2 || interpolateV1;
913

1014
const AnimatedCircle = Animated.createAnimatedComponent(
1115
Circle

src/components/indicatorsContainer/IndicatorsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useMemo, useCallback, memo } from 'react';
22
import Animated from 'react-native-reanimated';
33
import Indicator from '../indicator';
4-
import { IndicatorsContainerProps } from '../../types';
54
import { styles } from './styles';
5+
import type { IndicatorsContainerProps } from '../../types';
66

77
const IndicatorsContainerComponent = ({
88
data,

src/components/page/Page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React, { useMemo, useCallback, memo } from 'react';
2-
import Animated from 'react-native-reanimated';
2+
import Animated, { Extrapolate } from 'react-native-reanimated';
33
import PageContent from '../pageContent/PageContent';
4-
import { PageProps } from '../../types';
54
import { styles } from './styles';
5+
import type { PageProps } from '../../types';
66

7-
const { interpolate, Extrapolate } = Animated;
7+
const {
8+
interpolate: interpolateV1,
9+
interpolateNode: interpolateV2,
10+
} = require('react-native-reanimated');
11+
const interpolate = interpolateV2 || interpolateV1;
812

913
const PageComponent = ({
1014
index,

src/components/pageContent/PageContent.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React, { useMemo, memo } from 'react';
22
import { Text, Dimensions } from 'react-native';
3-
import Animated from 'react-native-reanimated';
4-
import { PageContentProps } from '../../types';
3+
import Animated, { Extrapolate } from 'react-native-reanimated';
54
import { styles } from './styles';
5+
import type { PageContentProps } from '../../types';
66

7-
const { interpolate, Extrapolate } = Animated;
7+
const {
8+
interpolate: interpolateV1,
9+
interpolateNode: interpolateV2,
10+
} = require('react-native-reanimated');
11+
const interpolate = interpolateV2 || interpolateV1;
812

913
const SCREEN_HEIGHT = Dimensions.get('window').height;
1014

src/useTiming.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import Animated, { Easing, sub } from 'react-native-reanimated';
2-
import { State } from 'react-native-gesture-handler';
3-
import { useClock, useValue } from 'react-native-redash';
4-
5-
const {
1+
import Animated, {
2+
sub,
63
add,
74
or,
85
block,
@@ -16,10 +13,23 @@ const {
1613
startClock,
1714
lessThan,
1815
greaterThan,
19-
interpolate,
2016
abs,
2117
timing,
22-
} = Animated;
18+
} from 'react-native-reanimated';
19+
import { State } from 'react-native-gesture-handler';
20+
import { useClock, useValue } from 'react-native-redash';
21+
22+
const {
23+
interpolate: interpolateV1,
24+
interpolateNode: interpolateV2,
25+
} = require('react-native-reanimated');
26+
const interpolate = interpolateV2 || interpolateV1;
27+
28+
const {
29+
Easing: EasingV1,
30+
EasingNode: EasingV2,
31+
} = require('react-native-reanimated');
32+
const Easing = EasingV2 || EasingV1;
2333

2434
interface useTimingProps {
2535
value: Animated.Adaptable<number>;

0 commit comments

Comments
 (0)