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

Rewrite stack navigator #131

Merged
merged 56 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1ae8cac
refactor: rewrite based on reanimated
satya164 May 24, 2019
7fb1609
refactor: refactor and perf improvements
satya164 Jun 6, 2019
b8b948d
chore: fix snapshots
satya164 Jun 6, 2019
ddac993
fix: properly normalize velocity
satya164 Jun 6, 2019
90e7d7e
chore: make it run with just yarn
brentvatne Jun 6, 2019
7212027
chore: fix updating to SDK33
brentvatne Jun 6, 2019
0ec03c1
refactor: switch to fade animation for header by default
satya164 Jun 6, 2019
881e59a
chore: fix tests and lint
satya164 Jun 6, 2019
905600a
fix: use a separate shadow view for the cards
satya164 Jun 6, 2019
f365db2
fix: make sure left button isn't bigger than screen width / 2
satya164 Jun 7, 2019
4d66578
fix: properly set pointerEvents on the views
satya164 Jun 7, 2019
bf27d53
refactor: keep transition states locally and implement animated replace
satya164 Jun 7, 2019
072e737
feat: make listeners reliable
osdnk Jun 11, 2019
0703f12
feat: add comments
osdnk Jun 11, 2019
603502b
fix: tweak the easing for android
satya164 Jun 14, 2019
ea8661c
fix: use pure component for stack items
satya164 Jun 13, 2019
6620106
fix: handle RTL properly
satya164 Jun 14, 2019
c7d3f61
fix: when header mode is screen, disable animations by default
satya164 Jun 14, 2019
bd84d93
fix: don't set a header height when a custom header is specified
satya164 Jun 14, 2019
9cd9b46
feat: integrate react-native-screens (#145)
osdnk Jun 14, 2019
a285202
fix: make the header appear static when sibling of headerless screen
satya164 Jun 14, 2019
80b3e8c
chore: disable react-native-screens in the example for now
satya164 Jun 14, 2019
6d0fcad
Fix warnings from expo package in example
brentvatne Jun 14, 2019
c03b0c7
feat: consider both velocity and position while calculating the next …
osdnk Jun 14, 2019
0f14f09
chore: release 2.0.0-alpha.0
satya164 Jun 14, 2019
6252b36
fix: fix header tint color not applied
satya164 Jun 14, 2019
3c4b0eb
feat: add headerBackTitleVisible option to navigation options
satya164 Jun 14, 2019
f4031be
feat: add headerBackgroundStyle option
satya164 Jun 14, 2019
60fc324
feat: add cardX options in navigationOptions
satya164 Jun 14, 2019
6651972
chore: release 2.0.0-alpha.1
satya164 Jun 14, 2019
572ab5c
fix: don't enable overlay on iOS by default
satya164 Jun 18, 2019
5cf9e7e
feat: add headerTransparent option
satya164 Jun 21, 2019
f0244dd
fix: support specifying header background color in headerStyle
satya164 Jun 21, 2019
70e5a40
fix: make sure components update when descriptor changes
satya164 Jun 21, 2019
e84d62f
fix: whitelist supported styles instead of blacklist
satya164 Jun 21, 2019
243839d
feat: add iOS modal presentation style
satya164 Jun 7, 2019
34e12da
chore: release 2.0.0-alpha.2
satya164 Jun 21, 2019
ec23b74
refactor: measure back label layout when not truncated
satya164 Jul 1, 2019
8fb0da5
fix: fix broken shadows on card
satya164 Jul 1, 2019
ca741b6
fix: use opacity in headerStyle
satya164 Jul 1, 2019
1f6fc61
fix: hide background for unfocused header in fade
satya164 Jul 1, 2019
7cecfcf
fix: fix border radius of modal presentation
satya164 Jul 1, 2019
16823e3
feat: allow specifying style interpolators in navigationOptions (#155)
tchayen Jul 6, 2019
f41380f
chore: upgrade deps
satya164 Jul 6, 2019
a6335bd
fix: hide overflow in wipe preset
satya164 Jul 6, 2019
f173a16
fix: fix typo preventing the screen from being cleaned up
satya164 Jul 6, 2019
f43800b
fix: disable react-native-screens on iOS
satya164 Jul 6, 2019
a32e43a
feat: add on transition end callback (#153)
osdnk Jul 7, 2019
9d17440
fix: fix back button not working in header
satya164 Jul 7, 2019
05e1f31
chore: release 2.0.0-alpha.3
satya164 Jul 7, 2019
68bd0f4
fix: properly handle floating header height
satya164 Jul 7, 2019
973aef1
chore: release 2.0.0-alpha.4
satya164 Jul 7, 2019
f04b9bf
fix: don't enable screens for modal stacks
satya164 Jul 8, 2019
3f5b903
fix: tweak transition spec to prevent jumping effect
satya164 Jul 8, 2019
b3c7250
refactor: export a modal transition preset
satya164 Jul 8, 2019
67a942d
chore: release 2.0.0-alpha.5
satya164 Jul 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
{
'import/core-modules':
[
'expo-asset',
'react-navigation-stack',
'react-native-gesture-handler',
'react-native-reanimated',
'react-native-vector-icons',
],
},
Expand Down
15 changes: 6 additions & 9 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { List, Divider } from 'react-native-paper';

import FullScreen from './src/FullScreen';
import SimpleStack from './src/SimpleStack';
import WipeStack from './src/WipeStack';
import ImageStack from './src/ImageStack';
import TransparentStack from './src/TransparentStack';
import ModalStack from './src/ModalStack';
Expand All @@ -24,20 +25,22 @@ import StackWithDrawer from './src/StackWithDrawer';
import HeaderPreset from './src/HeaderPreset';
import {
HeaderBackgroundDefault,
HeaderBackgroundTranslate,
HeaderBackgroundFade,
} from './src/HeaderBackgrounds';

// Comment the following two lines to stop using react-native-screens
import { useScreens } from 'react-native-screens';

// Uncomment the following line to force RTL. Requires closing and re-opening
useScreens();

// Change `false` to `true` to force RTL. Requires closing and re-opening
// your app after you first load it with this option enabled.
I18nManager.forceRTL(false);

const data = [
{ component: SimpleStack, title: 'Simple', routeName: 'SimpleStack' },
{ component: HeaderPreset, title: 'UIKit Preset', routeName: 'UIKit' },
{ component: WipeStack, title: 'Wipe Preset', routeName: 'Wipe' },
{ component: ImageStack, title: 'Image', routeName: 'ImageStack' },
{ component: ModalStack, title: 'Modal', routeName: 'ModalStack' },
{ component: FullScreen, title: 'Full Screen', routeName: 'FullScreen' },
Expand Down Expand Up @@ -68,19 +71,14 @@ const data = [
},
{
component: HeaderBackgroundDefault,
title: 'Header background (default transition)',
title: 'Header background (UIKit transition)',
routeName: 'HeaderBackgroundDefault',
},
{
component: HeaderBackgroundFade,
title: 'Header background (fade transition)',
routeName: 'HeaderBackgroundFade',
},
{
component: HeaderBackgroundTranslate,
title: 'Header background (translate transition)',
routeName: 'HeaderBackgroundTranslate',
},
];

// Cache images
Expand Down Expand Up @@ -145,7 +143,6 @@ const Root = createStackNavigator(
}
);

useScreens();
export default createAppContainer(Root);

// Uncomment this to test immediate transitions
Expand Down
3 changes: 3 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
},
"devDependencies": {
"babel-plugin-module-resolver": "^3.2.0"
},
"resolutions": {
"react-native-safe-area-view": "0.14.5"
}
}
22 changes: 15 additions & 7 deletions example/src/HeaderBackgrounds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
TransitionPresets,
HeaderStyleInterpolators,
} from 'react-navigation-stack';

function createHeaderBackgroundExample(options = {}) {
return createStackNavigator(
Expand All @@ -19,7 +23,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Login Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#FF0066' }} />
),
},
Expand All @@ -38,7 +42,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Games Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#3388FF' }} />
),
},
Expand Down Expand Up @@ -89,12 +93,16 @@ function createHeaderBackgroundExample(options = {}) {
}
);
}
export const HeaderBackgroundDefault = createHeaderBackgroundExample();
export const HeaderBackgroundTranslate = createHeaderBackgroundExample({
headerBackgroundTransitionPreset: 'translate',
export const HeaderBackgroundDefault = createHeaderBackgroundExample({
...TransitionPresets.SlideFromRightIOS,
headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
headerMode: 'float',
});

export const HeaderBackgroundFade = createHeaderBackgroundExample({
headerBackgroundTransitionPreset: 'fade',
...TransitionPresets.SlideFromRightIOS,
headerStyleInterpolator: HeaderStyleInterpolators.forFade,
headerMode: 'float',
});

const styles = StyleSheet.create({
Expand Down
13 changes: 11 additions & 2 deletions example/src/HeaderPreset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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,
HeaderStyleInterpolators,
} from 'react-navigation-stack';

class HomeScreen extends React.Component {
static navigationOptions = {
Expand Down Expand Up @@ -101,7 +105,12 @@ const StackWithHeaderPreset = createStackNavigator(
ScreenWithLongTitle: ScreenWithLongTitle,
},
{
headerTransitionPreset: 'uikit',
...TransitionPresets.SlideFromRightIOS,
headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
headerMode: 'float',
defaultNavigationOptions: {
gesturesEnabled: true,
},
}
);

Expand Down
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
10 changes: 4 additions & 6 deletions example/src/SimpleStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const Buttons = withNavigation(props => (
title="Go to Details"
onPress={() => props.navigation.navigate('Details')}
/>
<Button
title="Replace with List"
onPress={() => props.navigation.replace('List')}
/>
<Button
title="Go and then go to details quick"
onPress={() => {
Expand Down Expand Up @@ -148,11 +152,5 @@ export default createStackNavigator(
},
{
initialRouteName: 'List',

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

// headerTransitionPreset: 'uikit',
}
);
31 changes: 13 additions & 18 deletions example/src/TransparentStack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';

class ListScreen extends React.Component {
render() {
Expand Down Expand Up @@ -78,23 +79,17 @@ 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: ({ progress: { current } }) => {
const opacity = Animated.interpolate(current, {
inputRange: [0, 0.5, 0.9, 1],
outputRange: [0, 0.25, 0.7, 1],
});

const opacity = position.interpolate({
inputRange: [index - 1, index],
outputRange: [0, 1],
});

return { opacity };
},
}),
return {
cardStyle: {
opacity,
},
};
},
}
);
157 changes: 157 additions & 0 deletions example/src/WipeStack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import * as React from 'react';
import { Dimensions, Button, View, Text } from 'react-native';
import { withNavigation } from '@react-navigation/core';
import {
createStackNavigator,
TransitionPresets,
} from 'react-navigation-stack';

const Buttons = withNavigation(props => (
<React.Fragment>
<Button
title="Go to Details"
onPress={() => props.navigation.navigate('Details')}
/>
<Button
title="Go and then go to details quick"
onPress={() => {
props.navigation.pop();
setTimeout(() => {
props.navigation.navigate('Details');
}, 100);
}}
/>
<Button
title="Go to Headerless"
onPress={() => props.navigation.navigate('Headerless')}
/>
<Button title="Go back" onPress={() => props.navigation.goBack()} />
<Button
title="Go back quick"
onPress={() => {
props.navigation.pop();
setTimeout(() => {
props.navigation.pop();
}, 100);
}}
/>
<Button
title="Go back to all examples"
onPress={() => props.navigation.navigate('Home')}
/>
</React.Fragment>
));

class ListScreen extends React.Component {
static navigationOptions = {
title: 'List',
};

componentDidMount() {
console.log('ListScreen didMount');
}

componentWillUnmount() {
console.log('ListScreen willUnmount');
}

render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>List Screen</Text>
<Text>A list may go here</Text>
<Buttons />
</View>
);
}
}

class DetailsScreen extends React.Component {
static navigationOptions = {
title: 'Details',
gestureResponseDistance: {
horizontal: Dimensions.get('window').width,
},
};

componentDidMount() {
console.log('DetailsScreen didMount');
}

componentWillUnmount() {
console.log('DetailsScreen willUnmount');
}

render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>Details Screen</Text>
<Button title="Go back in 2s" onPress={this._goBackInTwoSeconds} />
<Buttons />
</View>
);
}

_goBackInTwoSeconds = () => {
setTimeout(() => {
this.props.navigation.goBack();
}, 2000);
};
}

class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
};

componentDidMount() {
console.log('HeaderlessScreen didMount');
}

componentWillUnmount() {
console.log('HeaderlessScreen willUnmount');
}

render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>Headerless Screen</Text>
<Buttons />
</View>
);
}
}

export default createStackNavigator(
{
List: ListScreen,
Details: DetailsScreen,
Headerless: HeaderlessScreen,
},
{
initialRouteName: 'List',
headerMode: 'screen',
...TransitionPresets.WipeFromBottomAndroid,
}
);