Skip to content

Commit

Permalink
feat: added Reanimated v2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jun 16, 2021
1 parent 57b497f commit 0f1eacd
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 31 deletions.
8 changes: 7 additions & 1 deletion example/src/components/CustomView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react';
import { View, Text, StyleSheet, Alert, ViewStyle } from 'react-native';
import Animated, { interpolate, Extrapolate } from 'react-native-reanimated';
import Animated, { Extrapolate } from 'react-native-reanimated';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { PageContentProps } from '@gorhom/paper-onboarding';
import { TouchableOpacityProps } from 'react-native';

const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const AnimatedTouchableOpacity: React.FC<
Animated.AnimateProps<ViewStyle, TouchableOpacityProps>
> = Animated.createAnimatedComponent(TouchableOpacity) as any;
Expand Down
13 changes: 11 additions & 2 deletions src/PaperOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import React, { useMemo, useRef, useCallback, memo, useState } from 'react';
import { Dimensions, Insets, LayoutChangeEvent } from 'react-native';
import { usePanGestureHandler, useValue } from 'react-native-redash';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated from 'react-native-reanimated';
import Animated, {
add,
useCode,
onChange,
call,
} from 'react-native-reanimated';
import Background from './components/background';
import Page from './components/page';
import IndicatorsContainer from './components/indicatorsContainer';
Expand Down Expand Up @@ -32,7 +37,11 @@ Animated.addWhitelistedUIProps({
pointerEvents: true,
});

const { interpolate, add, useCode, onChange, call } = Animated;
const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const PaperOnboardingComponent = ({
data,
Expand Down
2 changes: 1 addition & 1 deletion src/components/background/Background.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { memo, useMemo } from 'react';
import Svg from 'react-native-svg';
import BackgroundCircle from '../backgroundCircle';
import { calculateRectangleCircleRadius } from '../../utils/math';
import { BackgroundProps } from '../../types';
import { styles } from './styles';
import type { BackgroundProps } from '../../types';

const BackgroundComponent = ({
animatedIndex,
Expand Down
14 changes: 8 additions & 6 deletions src/components/backgroundCircle/BackgroundCircle.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { memo } from 'react';
import { ViewStyle } from 'react-native';
import { Circle, CircleProps } from 'react-native-svg';
import Animated, {
interpolate,
add,
Extrapolate,
} from 'react-native-reanimated';
import { BackgroundCircleProps } from '../../types';
import Animated, { add, Extrapolate } from 'react-native-reanimated';
import type { BackgroundCircleProps } from '../../types';

const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const AnimatedCircle = Animated.createAnimatedComponent(
Circle
Expand Down
6 changes: 2 additions & 4 deletions src/components/closeButton/CloseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { useMemo, memo, useRef } from 'react';
import { Text, TouchableOpacity } from 'react-native';
import Animated from 'react-native-reanimated';
import Animated, { round } from 'react-native-reanimated';
import { useValues, get } from 'react-native-redash';
import { CloseButtonProps } from '../../types';
import { styles } from './styles';

const { round } = Animated;
import type { CloseButtonProps } from '../../types';

export const CloseButtonComponent = ({
data,
Expand Down
10 changes: 7 additions & 3 deletions src/components/indicator/Indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { useMemo, useCallback, memo } from 'react';
import { ViewStyle } from 'react-native';
import Animated from 'react-native-reanimated';
import Animated, { Extrapolate } from 'react-native-reanimated';
import { Svg, Circle, CircleProps } from 'react-native-svg';
import { IndicatorProps } from '../../types';
import { styles } from './styles';
import type { IndicatorProps } from '../../types';

const { interpolate, Extrapolate } = Animated;
const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const AnimatedCircle = Animated.createAnimatedComponent(
Circle
Expand Down
2 changes: 1 addition & 1 deletion src/components/indicatorsContainer/IndicatorsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useMemo, useCallback, memo } from 'react';
import Animated from 'react-native-reanimated';
import Indicator from '../indicator';
import { IndicatorsContainerProps } from '../../types';
import { styles } from './styles';
import type { IndicatorsContainerProps } from '../../types';

const IndicatorsContainerComponent = ({
data,
Expand Down
10 changes: 7 additions & 3 deletions src/components/page/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, { useMemo, useCallback, memo } from 'react';
import Animated from 'react-native-reanimated';
import Animated, { Extrapolate } from 'react-native-reanimated';
import PageContent from '../pageContent/PageContent';
import { PageProps } from '../../types';
import { styles } from './styles';
import type { PageProps } from '../../types';

const { interpolate, Extrapolate } = Animated;
const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const PageComponent = ({
index,
Expand Down
10 changes: 7 additions & 3 deletions src/components/pageContent/PageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, { useMemo, memo } from 'react';
import { Text, Dimensions } from 'react-native';
import Animated from 'react-native-reanimated';
import { PageContentProps } from '../../types';
import Animated, { Extrapolate } from 'react-native-reanimated';
import { styles } from './styles';
import type { PageContentProps } from '../../types';

const { interpolate, Extrapolate } = Animated;
const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

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

Expand Down
24 changes: 17 additions & 7 deletions src/useTiming.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Animated, { Easing, sub } from 'react-native-reanimated';
import { State } from 'react-native-gesture-handler';
import { useClock, useValue } from 'react-native-redash';

const {
import Animated, {
sub,
add,
or,
block,
Expand All @@ -16,10 +13,23 @@ const {
startClock,
lessThan,
greaterThan,
interpolate,
abs,
timing,
} = Animated;
} from 'react-native-reanimated';
import { State } from 'react-native-gesture-handler';
import { useClock, useValue } from 'react-native-redash';

const {
interpolate: interpolateV1,
interpolateNode: interpolateV2,
} = require('react-native-reanimated');
const interpolate = interpolateV2 || interpolateV1;

const {
Easing: EasingV1,
EasingNode: EasingV2,
} = require('react-native-reanimated');
const Easing = EasingV2 || EasingV1;

interface useTimingProps {
value: Animated.Adaptable<number>;
Expand Down

0 comments on commit 0f1eacd

Please sign in to comment.