Skip to content

Use reanimatedv2 API in our components #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions generatedTypes/components/view/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifier
* Use Animate.View as a container
*/
animated?: boolean;
/**
* Use Animate.View (from react-native-reanimated) as a container
*/
reanimated?: boolean;
/**
* Turn off accessibility for this view and its nested children
*/
Expand Down
18 changes: 11 additions & 7 deletions src/components/sharedTransition/SharedArea.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import Animated, {Easing} from 'react-native-reanimated';
import Animated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
import PropTypes from 'prop-types';
import _ from 'lodash';
import TouchableOpacity from '../touchableOpacity';
import {Colors} from '../../style';
import ShareTransitionContext from './ShareTransitionContext';

const {interpolate: _interpolate, interpolateNode} = Animated;
const Easing = EasingNode || _Easing;
const interpolate = interpolateNode || _interpolate;

class SharedArea extends Component {
displayName = 'IGNORE';
static propTypes = {
Expand Down Expand Up @@ -37,14 +41,14 @@ class SharedArea extends Component {
return {
...StyleSheet.absoluteFillObject,
backgroundColor: Colors.white,
opacity: Animated.interpolate(this.transition, {inputRange: [0, 1], outputRange: [0, 1]})
opacity: interpolate(this.transition, {inputRange: [0, 1], outputRange: [0, 1]})
};
}

getDetailsStyle() {
return {
...StyleSheet.absoluteFillObject,
opacity: Animated.interpolate(this.transition, {inputRange: [90, 100], outputRange: [0, 1]})
opacity: interpolate(this.transition, {inputRange: [90, 100], outputRange: [0, 1]})
};
}

Expand All @@ -53,19 +57,19 @@ class SharedArea extends Component {
if (sourceLayout && this.transition) {
return {
position: 'absolute',
width: Animated.interpolate(this.transition, {
width: interpolate(this.transition, {
inputRange: [0, 100],
outputRange: [sourceLayout.width, targetLayout.width]
}),
height: Animated.interpolate(this.transition, {
height: interpolate(this.transition, {
inputRange: [0, 100],
outputRange: [sourceLayout.height, targetLayout.height]
}),
top: Animated.interpolate(this.transition, {
top: interpolate(this.transition, {
inputRange: [0, 100],
outputRange: [sourceLayout.y, targetLayout.y]
}),
left: Animated.interpolate(this.transition, {
left: interpolate(this.transition, {
inputRange: [0, 100],
outputRange: [sourceLayout.x, targetLayout.x]
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/tabController/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import FadedScrollView from './FadedScrollView';

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

const {Code, Value, interpolate, block, set} = Reanimated;
const {Code, Value, interpolate: _interpolate, interpolateNode, block, set} = Reanimated;
const interpolate = interpolateNode || _interpolate;

const DEFAULT_HEIGHT = 48;
const INDICATOR_INSET = Spacings.s4;
Expand Down
1 change: 1 addition & 0 deletions src/components/tabController/TabBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export default class TabBarItem extends PureComponent<Props> {
{icon && (
<Reanimated.Image
source={icon}
// @ts-expect-error TODO: not sure if this is us or reanimated
style={[!_.isUndefined(label) && styles.tabItemIconWithLabel, this.getIconStyle()]}
/>
)}
Expand Down
9 changes: 7 additions & 2 deletions src/components/tabController/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: support commented props
import React, {Component} from 'react';
import _ from 'lodash';
import Reanimated, {Easing} from 'react-native-reanimated';
import Reanimated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
import {State} from 'react-native-gesture-handler';
import {timing, fract, between} from 'react-native-redash';
import {Constants} from '../../helpers';
Expand Down Expand Up @@ -32,11 +32,15 @@ const {
Value,
block,
onChange,
interpolate,
interpolate: _interpolate,
interpolateNode,
round,
multiply
} = Reanimated;

const Easing = EasingNode || _Easing;
const interpolate = interpolateNode || _interpolate;

export interface TabControllerProps {
/**
* The list of tab bar items
Expand Down Expand Up @@ -193,6 +197,7 @@ class TabController extends Component<TabControllerProps, StateProps> {
cond(neq(currentPage, toPage), [
set(isAnimating, 1),
set(currentPage,
// @ts-expect-error
timing({clock, from: fromPage, to: toPage, duration: 280, easing: Easing.bezier(0.34, 1.3, 0.64, 1)}))
]),
// Set isAnimating flag off
Expand Down
10 changes: 9 additions & 1 deletion src/components/view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {PureComponent} from 'react';
import {View as RNView, SafeAreaView, Animated, ViewProps as RNViewProps, StyleProp, ViewStyle} from 'react-native';
import Reanimated from 'react-native-reanimated';
import {
asBaseComponent,
forwardRef,
Expand All @@ -9,6 +10,7 @@ import {
} from '../../commons/new';
import Constants from '../../helpers/Constants';


export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifiers {
/**
* If true, will render as SafeAreaView
Expand All @@ -18,6 +20,10 @@ export interface ViewProps extends Omit<RNViewProps, 'style'>, ContainerModifier
* Use Animate.View as a container
*/
animated?: boolean;
/**
* Use Animate.View (from react-native-reanimated) as a container
*/
reanimated?: boolean;
/**
* Turn off accessibility for this view and its nested children
*/
Expand Down Expand Up @@ -62,7 +68,9 @@ class View extends PureComponent<PropsTypes, ViewState> {
super(props);

this.Container = props.useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
if (props.animated) {
if (props.reanimated) {
this.Container = Reanimated.createAnimatedComponent(this.Container);
} else if (props.animated) {
this.Container = Animated.createAnimatedComponent(this.Container);
}

Expand Down
8 changes: 6 additions & 2 deletions src/incubator/TouchableOpacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, {PureComponent} from 'react';
import {processColor, StyleSheet, LayoutChangeEvent} from 'react-native';
import _ from 'lodash';
import Reanimated, {Easing} from 'react-native-reanimated';
import Reanimated, {Easing as _Easing, EasingNode} from 'react-native-reanimated';
import {TapGestureHandler, LongPressGestureHandler, State, LongPressGestureHandlerGestureEvent} from 'react-native-gesture-handler';
import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../commons/new';
import {ViewProps} from '../components/view';
Expand All @@ -15,7 +15,8 @@ const {
or,
eq,
neq,
interpolate,
interpolate: _interpolate,
interpolateNode,
Extrapolate,
Value,
call,
Expand All @@ -27,6 +28,9 @@ const {
stopClock
} = Reanimated;

const Easing = EasingNode || _Easing;
const interpolate = interpolateNode || _interpolate;

export type TouchableOpacityProps = {
/**
* Background color
Expand Down
2 changes: 2 additions & 0 deletions src/incubator/WheelPicker/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export default ({
key={index}
center
onPress={selectItem}
// @ts-expect-error
index={index}
>
{/* @ts-expect-error */}
<AnimatedText text60R style={{color, ...style}}>
{text}
</AnimatedText>
Expand Down
1 change: 1 addition & 0 deletions src/incubator/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const WheelPicker = ({items, itemHeight = 48, activeTextColor, inactiveTextColor
<View width={250} height={height} br20>
<AnimatedFlatList
data={items}
// @ts-expect-error
keyExtractor={keyExtractor}
scrollEventThrottle={100}
onScroll={onScroll}
Expand Down