Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
fix: make lib compatible with reanimated2 (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk committed Jun 4, 2020
1 parent 795f90f commit 0996cdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Pager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
InteractionManager,
} from 'react-native';
import { PanGestureHandler, State } from 'react-native-gesture-handler';
import Animated, { Easing } from 'react-native-reanimated';
import Animated, {
Easing as OldEasing,
// @ts-ignore
EasingNode,
} from 'react-native-reanimated';
import memoize from './memoize';

import {
Expand All @@ -21,6 +25,8 @@ import {

type Binary = 0 | 1;

const Easing = EasingNode || OldEasing;

export type Props<T extends Route> = PagerCommonProps & {
onIndexChange: (index: number) => void;
navigationState: NavigationState<T>;
Expand Down
13 changes: 11 additions & 2 deletions src/TabBarIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as React from 'react';
import { StyleSheet, I18nManager, StyleProp, ViewStyle } from 'react-native';
import Animated, { Easing } from 'react-native-reanimated';
import Animated, {
Easing as OldEasing,
// @ts-ignore
EasingNode,
} from 'react-native-reanimated';

import memoize from './memoize';
import { Route, SceneRendererProps, NavigationState } from './types';

const Easing = EasingNode || OldEasing;

export type GetTabWidth = (index: number) => number;

export type Props<T extends Route> = SceneRendererProps & {
Expand All @@ -14,7 +20,10 @@ export type Props<T extends Route> = SceneRendererProps & {
getTabWidth: GetTabWidth;
};

const { interpolate, multiply, Extrapolate } = Animated;
const { multiply, Extrapolate } = Animated;

// @ts-ignore
const interpolate = Animated.interpolateNode || Animated.interpolate;

export default class TabBarIndicator<T extends Route> extends React.Component<
Props<T>
Expand Down
7 changes: 5 additions & 2 deletions src/TabBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Scene, Route, NavigationState } from './types';
import Animated from 'react-native-reanimated';
import memoize from './memoize';

// @ts-ignore
const AnimatedInterpolate = Animated.interpolateNode || Animated.interpolate;

type Props<T extends Route> = {
position: Animated.Node<number>;
route: T;
Expand Down Expand Up @@ -53,7 +56,7 @@ export default class TabBarItem<T extends Route> extends React.Component<
if (routes.length > 1) {
const inputRange = routes.map((_, i) => i);

return Animated.interpolate(position, {
return AnimatedInterpolate(position, {
inputRange,
outputRange: inputRange.map((i) => (i === tabIndex ? 1 : 0)),
});
Expand All @@ -67,7 +70,7 @@ export default class TabBarItem<T extends Route> extends React.Component<
if (routes.length > 1) {
const inputRange = routes.map((_: Route, i: number) => i);

return Animated.interpolate(position, {
return AnimatedInterpolate(position, {
inputRange,
outputRange: inputRange.map((i: number) => (i === tabIndex ? 0 : 1)),
});
Expand Down

0 comments on commit 0996cdf

Please sign in to comment.