Skip to content

Commit 73361e0

Browse files
authored
Use reanimatedv2 API in our components (#1224)
* Use reanimatedv2 API in our components * ignore ts error correctly
1 parent 54b7cca commit 73361e0

File tree

9 files changed

+48
-13
lines changed

9 files changed

+48
-13
lines changed

generatedTypes/components/view/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifier
1010
* Use Animate.View as a container
1111
*/
1212
animated?: boolean;
13+
/**
14+
* Use Animate.View (from react-native-reanimated) as a container
15+
*/
16+
reanimated?: boolean;
1317
/**
1418
* Turn off accessibility for this view and its nested children
1519
*/

src/components/sharedTransition/SharedArea.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React, {Component} from 'react';
22
import {StyleSheet} from 'react-native';
3-
import Animated, {Easing} from 'react-native-reanimated';
3+
import Animated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
44
import PropTypes from 'prop-types';
55
import _ from 'lodash';
66
import TouchableOpacity from '../touchableOpacity';
77
import {Colors} from '../../style';
88
import ShareTransitionContext from './ShareTransitionContext';
99

10+
const {interpolate: _interpolate, interpolateNode} = Animated;
11+
const Easing = EasingNode || _Easing;
12+
const interpolate = interpolateNode || _interpolate;
13+
1014
class SharedArea extends Component {
1115
displayName = 'IGNORE';
1216
static propTypes = {
@@ -37,14 +41,14 @@ class SharedArea extends Component {
3741
return {
3842
...StyleSheet.absoluteFillObject,
3943
backgroundColor: Colors.white,
40-
opacity: Animated.interpolate(this.transition, {inputRange: [0, 1], outputRange: [0, 1]})
44+
opacity: interpolate(this.transition, {inputRange: [0, 1], outputRange: [0, 1]})
4145
};
4246
}
4347

4448
getDetailsStyle() {
4549
return {
4650
...StyleSheet.absoluteFillObject,
47-
opacity: Animated.interpolate(this.transition, {inputRange: [90, 100], outputRange: [0, 1]})
51+
opacity: interpolate(this.transition, {inputRange: [90, 100], outputRange: [0, 1]})
4852
};
4953
}
5054

@@ -53,19 +57,19 @@ class SharedArea extends Component {
5357
if (sourceLayout && this.transition) {
5458
return {
5559
position: 'absolute',
56-
width: Animated.interpolate(this.transition, {
60+
width: interpolate(this.transition, {
5761
inputRange: [0, 100],
5862
outputRange: [sourceLayout.width, targetLayout.width]
5963
}),
60-
height: Animated.interpolate(this.transition, {
64+
height: interpolate(this.transition, {
6165
inputRange: [0, 100],
6266
outputRange: [sourceLayout.height, targetLayout.height]
6367
}),
64-
top: Animated.interpolate(this.transition, {
68+
top: interpolate(this.transition, {
6569
inputRange: [0, 100],
6670
outputRange: [sourceLayout.y, targetLayout.y]
6771
}),
68-
left: Animated.interpolate(this.transition, {
72+
left: interpolate(this.transition, {
6973
inputRange: [0, 100],
7074
outputRange: [sourceLayout.x, targetLayout.x]
7175
})

src/components/tabController/TabBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import FadedScrollView from './FadedScrollView';
1616

1717
import {useScrollToItem} from '../../hooks';
1818

19-
const {Code, Value, interpolate, block, set} = Reanimated;
19+
// @ts-expect-error
20+
const {Code, Value, interpolate: _interpolate, interpolateNode, block, set} = Reanimated;
21+
const interpolate = interpolateNode || _interpolate;
2022

2123
const DEFAULT_HEIGHT = 48;
2224
const INDICATOR_INSET = Spacings.s4;

src/components/tabController/TabBarItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export default class TabBarItem extends PureComponent<Props> {
259259
{icon && (
260260
<Reanimated.Image
261261
source={icon}
262+
// @ts-ignore reanimated2
262263
style={[!_.isUndefined(label) && styles.tabItemIconWithLabel, this.getIconStyle()]}
263264
/>
264265
)}

src/components/tabController/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// TODO: support commented props
22
import React, {Component} from 'react';
33
import _ from 'lodash';
4-
import Reanimated, {Easing} from 'react-native-reanimated';
4+
// @ts-expect-error
5+
import Reanimated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
56
import {State} from 'react-native-gesture-handler';
67
import {timing, fract, between} from 'react-native-redash';
78
import {Constants} from '../../helpers';
@@ -32,11 +33,16 @@ const {
3233
Value,
3334
block,
3435
onChange,
35-
interpolate,
36+
interpolate: _interpolate,
37+
// @ts-expect-error
38+
interpolateNode,
3639
round,
3740
multiply
3841
} = Reanimated;
3942

43+
const Easing = EasingNode || _Easing;
44+
const interpolate = interpolateNode || _interpolate;
45+
4046
export interface TabControllerProps {
4147
/**
4248
* The list of tab bar items
@@ -193,6 +199,7 @@ class TabController extends Component<TabControllerProps, StateProps> {
193199
cond(neq(currentPage, toPage), [
194200
set(isAnimating, 1),
195201
set(currentPage,
202+
// @ts-ignore reanimated2
196203
timing({clock, from: fromPage, to: toPage, duration: 280, easing: Easing.bezier(0.34, 1.3, 0.64, 1)}))
197204
]),
198205
// Set isAnimating flag off

src/components/view/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {PureComponent} from 'react';
22
import {View as RNView, SafeAreaView, Animated, ViewProps as RNViewProps, StyleProp, ViewStyle} from 'react-native';
3+
import Reanimated from 'react-native-reanimated';
34
import {
45
asBaseComponent,
56
forwardRef,
@@ -9,6 +10,7 @@ import {
910
} from '../../commons/new';
1011
import Constants from '../../helpers/Constants';
1112

13+
1214
export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifiers {
1315
/**
1416
* If true, will render as SafeAreaView
@@ -18,6 +20,10 @@ export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifier
1820
* Use Animate.View as a container
1921
*/
2022
animated?: boolean;
23+
/**
24+
* Use Animate.View (from react-native-reanimated) as a container
25+
*/
26+
reanimated?: boolean;
2127
/**
2228
* Turn off accessibility for this view and its nested children
2329
*/
@@ -62,7 +68,9 @@ class View extends PureComponent<PropsTypes, ViewState> {
6268
super(props);
6369

6470
this.Container = props.useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
65-
if (props.animated) {
71+
if (props.reanimated) {
72+
this.Container = Reanimated.createAnimatedComponent(this.Container);
73+
} else if (props.animated) {
6674
this.Container = Animated.createAnimatedComponent(this.Container);
6775
}
6876

src/incubator/TouchableOpacity.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import React, {PureComponent} from 'react';
33
import {processColor, StyleSheet, LayoutChangeEvent} from 'react-native';
44
import _ from 'lodash';
5-
import Reanimated, {Easing} from 'react-native-reanimated';
5+
// @ts-expect-error
6+
import Reanimated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
67
import {TapGestureHandler, LongPressGestureHandler, State, LongPressGestureHandlerGestureEvent} from 'react-native-gesture-handler';
78
import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../commons/new';
89
import {ViewProps} from '../components/view';
@@ -15,7 +16,9 @@ const {
1516
or,
1617
eq,
1718
neq,
18-
interpolate,
19+
interpolate: _interpolate,
20+
// @ts-expect-error
21+
interpolateNode,
1922
Extrapolate,
2023
Value,
2124
call,
@@ -27,6 +30,9 @@ const {
2730
stopClock
2831
} = Reanimated;
2932

33+
const Easing = EasingNode || _Easing;
34+
const interpolate = interpolateNode || _interpolate;
35+
3036
export type TouchableOpacityProps = {
3137
/**
3238
* Background color

src/incubator/WheelPicker/Item.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ export default ({
5959
key={index}
6060
center
6161
onPress={selectItem}
62+
// @ts-ignore reanimated2
6263
index={index}
6364
>
65+
{/* @ts-ignore reanimated2*/}
6466
<AnimatedText text60R style={{color, ...style}}>
6567
{text}
6668
</AnimatedText>

src/incubator/WheelPicker/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const WheelPicker = ({items, itemHeight = 48, activeTextColor, inactiveTextColor
107107
<View width={250} height={height} br20>
108108
<AnimatedFlatList
109109
data={items}
110+
// @ts-ignore reanimated2
110111
keyExtractor={keyExtractor}
111112
scrollEventThrottle={100}
112113
onScroll={onScroll}

0 commit comments

Comments
 (0)