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

Commit

Permalink
wip: rewrite based on reanimated
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jun 4, 2019
1 parent 10fe551 commit 2ae1ea5
Show file tree
Hide file tree
Showing 46 changed files with 1,994 additions and 4,621 deletions.
2 changes: 1 addition & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import { useScreens } from 'react-native-screens';
I18nManager.forceRTL(false);

const data = [
{ component: SimpleStack, title: 'Simple', routeName: 'SimpleStack' },
{ component: HeaderPreset, title: 'UIKit Preset', routeName: 'UIKit' },
{ component: SimpleStack, title: 'Wipe Preset', routeName: 'SimpleStack' },
{ component: ImageStack, title: 'Image', routeName: 'ImageStack' },
{ component: ModalStack, title: 'Modal', routeName: 'ModalStack' },
{ component: FullScreen, title: 'Full Screen', routeName: 'FullScreen' },
Expand Down
2 changes: 1 addition & 1 deletion example/src/FullScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createStackNavigator } from 'react-navigation-stack';

class Screen extends React.Component {
static navigationOptions = {
header: null,
header: () => null,
};

render() {
Expand Down
4 changes: 2 additions & 2 deletions example/src/HeaderBackgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Login Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#FF0066' }} />
),
},
Expand All @@ -38,7 +38,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Games Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#3388FF' }} />
),
},
Expand Down
9 changes: 5 additions & 4 deletions example/src/HeaderPreset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react';
import { Button, StatusBar } from 'react-native';
import { SafeAreaView } from '@react-navigation/native';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
TransitionPresets,
} from 'react-navigation-stack';

class HomeScreen extends React.Component {
static navigationOptions = {
Expand Down Expand Up @@ -100,9 +103,7 @@ const StackWithHeaderPreset = createStackNavigator(
ScreenWithNoHeader: ScreenWithNoHeader,
ScreenWithLongTitle: ScreenWithLongTitle,
},
{
headerTransitionPreset: 'uikit',
}
TransitionPresets.SlideFromRightIOS
);

export default StackWithHeaderPreset;
2 changes: 1 addition & 1 deletion example/src/ImageStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ListScreen extends React.Component {
static navigationOptions = ({ navigation }) => ({
title: 'Image list',
headerBackTitle: 'Back',
headerLeft: (
headerLeft: () => (
<Button title="Back" onPress={() => navigation.navigate('Home')} />
),
});
Expand Down
13 changes: 6 additions & 7 deletions example/src/SimpleStack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react';
import { Dimensions, Button, View, Text } from 'react-native';
import { withNavigation } from '@react-navigation/core';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
TransitionPresets,
} from 'react-navigation-stack';

const Buttons = withNavigation(props => (
<React.Fragment>
Expand Down Expand Up @@ -148,11 +151,7 @@ export default createStackNavigator(
},
{
initialRouteName: 'List',

// these are the defaults
cardShadowEnabled: true,
cardOverlayEnabled: false,

// headerTransitionPreset: 'uikit',
headerMode: 'screen',
...TransitionPresets.WipeFromBottomAndroid,
}
);
40 changes: 23 additions & 17 deletions example/src/TransparentStack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as React from 'react';
import { Animated, Button, Easing, View, Text } from 'react-native';
import { Button, View, Text } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import Animated from 'react-native-reanimated';

const { interpolate, multiply, cond } = Animated;

class ListScreen extends React.Component {
render() {
Expand Down Expand Up @@ -78,23 +81,26 @@ export default createStackNavigator(
navigationOptions: {
gesturesEnabled: false,
},
transitionConfig: () => ({
transitionSpec: {
duration: 300,
easing: Easing.inOut(Easing.ease),
timing: Animated.timing,
},
screenInterpolator: sceneProps => {
const { position, scene } = sceneProps;
const { index } = scene;
cardStyleInterpolator: ({ positions: { current }, layout, closing }) => {
const translateY = interpolate(current, {
inputRange: [0, 1],
outputRange: [multiply(layout.height, 0.08), 0],
});

const opacity = position.interpolate({
inputRange: [index - 1, index],
outputRange: [0, 1],
});
const opacity = cond(
closing,
current,
interpolate(current, {
inputRange: [0, 0.5, 0.9, 1],
outputRange: [0, 0.25, 0.7, 1],
})
);

return { opacity };
},
}),
return {
cardStyle: {
opacity,
},
};
},
}
);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"react": "16.5.0",
"react-dom": "16.5.0",
"react-native": "~0.57.7",
"react-native-gesture-handler": "^1.1.0",
"react-native-gesture-handler": "^1.2.1",
"react-native-reanimated": "^1.0.1",
"react-native-screens": "^1.0.0-alpha.22",
"react-test-renderer": "16.5.0",
"release-it": "^11.0.0",
Expand All @@ -76,6 +77,7 @@
"react": "*",
"react-native": "*",
"react-native-gesture-handler": "^1.0.0",
"react-native-reanimated": "^1.0.0",
"react-native-screens": "^1.0.0 || ^1.0.0-alpha"
},
"jest": {
Expand Down
140 changes: 140 additions & 0 deletions src/TransitionConfigs/CardStyleInterpolators.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import Animated from 'react-native-reanimated';
import { CardInterpolationProps, CardInterpolatedStyle } from '../types';

const { cond, multiply, interpolate } = Animated;

/**
* Standard iOS-style slide in from the right.
*/
export function forHorizontalIOS({
positions: { current, next },
layout,
}: CardInterpolationProps): CardInterpolatedStyle {
const translateFocused = interpolate(current, {
inputRange: [0, 1],
outputRange: [layout.width, 0],
});
const translateUnfocused = next
? interpolate(next, {
inputRange: [0, 1],
outputRange: [0, multiply(layout.width, -0.3)],
})
: 0;

const opacity = interpolate(current, {
inputRange: [0, 1],
outputRange: [0, 0.07],
});

const shadowOpacity = interpolate(current, {
inputRange: [0, 1],
outputRange: [0, 0.3],
});

return {
cardStyle: {
backgroundColor: '#eee',
transform: [
// Translation for the animation of the current card
{ translateX: translateFocused },
// Translation for the animation of the card on top of this
{ translateX: translateUnfocused },
],
shadowOpacity,
},
overlayStyle: { opacity },
};
}

/**
* Standard iOS-style slide in from the bottom (used for modals).
*/
export function forVerticalIOS({
positions: { current },
layout,
}: CardInterpolationProps): CardInterpolatedStyle {
const translateY = interpolate(current, {
inputRange: [0, 1],
outputRange: [layout.height, 0],
});

return {
cardStyle: {
backgroundColor: '#eee',
transform: [
// Translation for the animation of the current card
{ translateY },
],
},
};
}

/**
* Standard Android-style fade in from the bottom for Android Oreo.
*/
export function forFadeFromBottomAndroid({
positions: { current },
layout,
closing,
}: CardInterpolationProps): CardInterpolatedStyle {
const translateY = interpolate(current, {
inputRange: [0, 1],
outputRange: [multiply(layout.height, 0.08), 0],
});

const opacity = cond(
closing,
current,
interpolate(current, {
inputRange: [0, 0.5, 0.9, 1],
outputRange: [0, 0.25, 0.7, 1],
})
);

return {
cardStyle: {
opacity,
transform: [{ translateY }],
},
};
}

/**
* Standard Android-style wipe from the bottom for Android Pie.
*/
export function forWipeFromBottomAndroid({
positions: { current, next },
layout,
}: CardInterpolationProps): CardInterpolatedStyle {
const containerTranslateY = interpolate(current, {
inputRange: [0, 1],
outputRange: [layout.height, 0],
});
const cardTranslateYFocused = interpolate(current, {
inputRange: [0, 1],
outputRange: [multiply(layout.height, 95.9 / 100, -1), 0],
});
const cardTranslateYUnfocused = next
? interpolate(next, {
inputRange: [0, 1],
outputRange: [0, multiply(layout.height, 2 / 100, -1)],
})
: 0;
const overlayOpacity = interpolate(current, {
inputRange: [0, 0.36, 1],
outputRange: [0, 0.1, 0.1],
});

return {
containerStyle: {
transform: [{ translateY: containerTranslateY }],
},
cardStyle: {
transform: [
{ translateY: cardTranslateYFocused },
{ translateY: cardTranslateYUnfocused },
],
},
overlayStyle: { opacity: overlayOpacity },
};
}

0 comments on commit 2ae1ea5

Please sign in to comment.