Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
refactor: migrate to animated
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 1, 2020
1 parent 318400b commit dbdd352
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 564 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- v1-dependencies-example-
- run: |
yarn install --frozen-lockfile --cwd example
yarn install --frozen-lockfile
yarn install --frozen-lockfile --ignore-scripts
yarn sync
- save_cache:
key: v1-dependencies-{{ checksum "yarn.lock" }}
Expand Down
1 change: 0 additions & 1 deletion example/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
'expo-asset',
'react-navigation-stack',
'react-native-gesture-handler',
'react-native-reanimated',
'react-native-vector-icons',
],
},
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-native-gesture-handler": "~1.5.0",
"react-native-maps": "0.26.1",
"react-native-paper": "^2.15.2",
"react-native-reanimated": "~1.4.0",
"react-native-reanimated": "^1.4.0",
"react-native-safe-area-context": "0.6.0",
"react-native-unimodules": "^0.7.0-rc.1",
"react-native-web": "^0.11.4",
Expand Down
5 changes: 1 addition & 4 deletions example/src/DragLimitedToModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react';
import { View, Text, StyleSheet, Dimensions } from 'react-native';
import Animated from 'react-native-reanimated';
import { NavigationStackScreenComponent } from 'react-navigation-stack';

const HEIGHT = Dimensions.get('screen').height;

const { interpolate } = Animated;

const DragLimitedToModal: NavigationStackScreenComponent = () => (
<View style={styles.modal}>
<Text style={styles.text}>Adjusts to the size of text</Text>
Expand All @@ -18,7 +15,7 @@ DragLimitedToModal.navigationOptions = {
gestureDirection: 'vertical',
gestureResponseDistance: { vertical: HEIGHT },
cardStyleInterpolator: ({ current }) => {
const translateY = interpolate(current.progress, {
const translateY = current.progress.interpolate({
inputRange: [0, 1],
outputRange: [HEIGHT, 0],
});
Expand Down
5 changes: 1 addition & 4 deletions example/src/ModalStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import {
NavigationStackScreenProps,
StackCardStyleInterpolator,
} from 'react-navigation-stack';
import Animated from 'react-native-reanimated';

const { interpolate } = Animated;

const gestureResponseDistance = {
vertical: Dimensions.get('window').height,
Expand All @@ -25,7 +22,7 @@ const forVerticalInvertedIOS: StackCardStyleInterpolator = ({
current: { progress },
layouts: { screen },
}) => {
const translateY = interpolate(progress, {
const translateY = progress.interpolate({
inputRange: [0, 1],
outputRange: [-screen.height, 0],
});
Expand Down
21 changes: 12 additions & 9 deletions example/src/StackAnimationConsumerStack.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { Button, View } from 'react-native';
import Animated from 'react-native-reanimated';
import { Animated, Button, View } from 'react-native';
import {
createStackNavigator,
NavigationStackScreenProps,
Expand All @@ -27,12 +26,12 @@ const ListScreen = (props: NavigationStackScreenProps) => (
const AnotherScreen = () => (
<StackCardAnimationContext.Consumer>
{value => {
const fontSize = value
? Animated.interpolate(value.current.progress, {
const scale = value
? value.current.progress.interpolate({
inputRange: [0, 1],
outputRange: [8, 32],
outputRange: [0.25, 1],
})
: 32;
: 1;

return (
<View
Expand All @@ -44,7 +43,11 @@ const AnotherScreen = () => (
}}
>
<Animated.Text
style={{ fontSize, opacity: value ? value.current.progress : 1 }}
style={{
fontSize: 32,
opacity: value ? value.current.progress : 1,
transform: [{ scale }],
}}
>
Animates on progress
</Animated.Text>
Expand All @@ -69,7 +72,7 @@ const YetAnotherScreen = () => (
style={{
fontSize: 24,
opacity: value
? Animated.interpolate(value.swiping, {
? value.swiping.interpolate({
inputRange: [0, 1],
outputRange: [1, 0],
})
Expand All @@ -86,7 +89,7 @@ const YetAnotherScreen = () => (
style={{
fontSize: 24,
opacity: value
? Animated.interpolate(value.closing, {
? value.closing.interpolate({
inputRange: [0, 1],
outputRange: [1, 0],
})
Expand Down
3 changes: 1 addition & 2 deletions example/src/TransparentStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
createStackNavigator,
NavigationStackScreenComponent,
} from 'react-navigation-stack';
import Animated from 'react-native-reanimated';

const ListScreen: NavigationStackScreenComponent = function(props) {
return (
Expand Down Expand Up @@ -75,7 +74,7 @@ export default createStackNavigator(
cardStyle: { backgroundColor: 'transparent' },
gestureEnabled: false,
cardStyleInterpolator: ({ current: { progress } }) => {
const opacity = Animated.interpolate(progress, {
const opacity = progress.interpolate({
inputRange: [0, 0.5, 0.9, 1],
outputRange: [0, 0.25, 0.7, 1],
});
Expand Down
2 changes: 1 addition & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9985,7 +9985,7 @@ react-native-paper@^2.15.2:
react-lifecycles-compat "^3.0.4"
react-native-safe-area-view "^0.12.0"

react-native-reanimated@~1.4.0:
react-native-reanimated@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-1.4.0.tgz#7f1acbf9be08492d834f512700570978052be2f9"
integrity sha512-tO7nSNNP+iRLVbkcSS5GXyDBb7tSI02+XuRL3/S39EAr35rnvUy2JfeLUQG+fWSObJjnMVhasUDEUwlENk8IXw==
Expand Down
4 changes: 0 additions & 4 deletions jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ jest.mock('react-native-gesture-handler', () => ({
END: 5,
},
}));

jest.mock('react-native-reanimated', () =>
require('react-native-reanimated/mock')
);
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prerelease": "yarn sync",
"release": "release-it",
"example": "yarn --cwd example",
"bootstrap": "yarn example && yarn && yarn sync",
"bootstrap": "yarn example && yarn --ignore-scripts && yarn sync",
"sync": "bash scripts/sync-stack.sh",
"patch": "diff -ruN node_modules/@react-navigation/stack/src src/vendor > scripts/stack.patch; printf ''"
},
Expand Down Expand Up @@ -50,7 +50,7 @@
"@expo/vector-icons": "^10.0.6",
"@react-native-community/bob": "^0.7.0",
"@react-native-community/masked-view": "^0.1.5",
"@react-navigation/stack": "^5.0.0-alpha.45",
"@react-navigation/stack": "^5.0.0-alpha.48",
"@release-it/conventional-changelog": "^1.1.0",
"@types/color": "^3.0.0",
"@types/jest": "^24.0.23",
Expand All @@ -68,7 +68,6 @@
"react-dom": "~16.9.0",
"react-native": "~0.61.4",
"react-native-gesture-handler": "^1.5.2",
"react-native-reanimated": "^1.4.0",
"react-native-safe-area-context": "^0.6.1",
"react-native-screens": "^1.0.0-alpha.23",
"react-navigation": "^4.0.10",
Expand All @@ -82,7 +81,6 @@
"react": "*",
"react-native": "*",
"react-native-gesture-handler": "^1.0.0",
"react-native-reanimated": "^1.3.0-alpha",
"react-native-safe-area-context": "^0.3.3",
"react-native-screens": "^1.0.0 || ^1.0.0-alpha || ^2.0.0-alpha",
"react-navigation": "^4.0.7"
Expand Down
Loading

0 comments on commit dbdd352

Please sign in to comment.