2018-08-03 14:59:12 -07:00
|
|
|
import React from 'react';
|
|
|
|
import Expo from 'expo';
|
2018-10-10 13:52:38 -07:00
|
|
|
import { FlatList, I18nManager } from 'react-native';
|
2018-10-31 15:21:07 -07:00
|
|
|
import {
|
|
|
|
createAppContainer,
|
|
|
|
SafeAreaView,
|
|
|
|
ScrollView,
|
|
|
|
} from '@react-navigation/native';
|
2018-10-15 13:17:12 -07:00
|
|
|
import {
|
|
|
|
Assets as StackAssets,
|
|
|
|
createStackNavigator,
|
|
|
|
} from 'react-navigation-stack';
|
2018-08-03 14:59:12 -07:00
|
|
|
import { ListSection, Divider } from 'react-native-paper';
|
2018-09-14 12:48:59 +02:00
|
|
|
|
2018-08-03 14:59:12 -07:00
|
|
|
import SimpleStack from './src/SimpleStack';
|
2018-10-10 13:52:38 -07:00
|
|
|
import ImageStack from './src/ImageStack';
|
2018-09-24 15:11:34 -04:00
|
|
|
import TransparentStack from './src/TransparentStack';
|
2018-10-10 13:52:38 -07:00
|
|
|
import ModalStack from './src/ModalStack';
|
|
|
|
import LifecycleInteraction from './src/LifecycleInteraction';
|
|
|
|
import GestureInteraction from './src/GestureInteraction';
|
2018-10-17 15:26:13 -07:00
|
|
|
import SwitchWithStacks from './src/SwitchWithStacks';
|
2018-10-30 13:08:06 -07:00
|
|
|
import StackWithDrawer from './src/StackWithDrawer';
|
2018-10-31 13:22:03 -07:00
|
|
|
import {
|
|
|
|
HeaderBackgroundDefault,
|
|
|
|
HeaderBackgroundTranslate,
|
|
|
|
HeaderBackgroundFade,
|
|
|
|
} from './src/HeaderBackgrounds';
|
2018-10-10 13:52:38 -07:00
|
|
|
|
2018-09-14 12:48:59 +02:00
|
|
|
// Comment the following two lines to stop using react-native-screens
|
|
|
|
import { useScreens } from 'react-native-screens';
|
2018-10-12 11:34:03 -07:00
|
|
|
|
|
|
|
// Uncomment the following line to force RTL. Requires closing and re-opening
|
|
|
|
// your app after you first load it with this option enabled.
|
|
|
|
I18nManager.forceRTL(false);
|
2018-09-14 12:48:59 +02:00
|
|
|
useScreens();
|
|
|
|
|
2018-08-03 14:59:12 -07:00
|
|
|
const data = [
|
|
|
|
{ component: SimpleStack, title: 'Simple', routeName: 'SimpleStack' },
|
2018-10-10 13:52:38 -07:00
|
|
|
{ component: ImageStack, title: 'Image', routeName: 'ImageStack' },
|
|
|
|
{ component: ModalStack, title: 'Modal', routeName: 'ModalStack' },
|
2018-10-12 11:23:17 -07:00
|
|
|
{
|
|
|
|
component: LifecycleInteraction,
|
|
|
|
title: 'Lifecycle',
|
|
|
|
routeName: 'LifecycleStack',
|
|
|
|
},
|
2018-09-24 15:11:34 -04:00
|
|
|
{
|
|
|
|
component: TransparentStack,
|
|
|
|
title: 'Transparent',
|
|
|
|
routeName: 'TransparentStack',
|
|
|
|
},
|
2018-10-12 11:23:17 -07:00
|
|
|
{
|
|
|
|
component: GestureInteraction,
|
|
|
|
title: 'Gesture Interaction',
|
|
|
|
routeName: 'GestureInteraction',
|
|
|
|
},
|
2018-10-17 15:26:13 -07:00
|
|
|
{
|
|
|
|
component: SwitchWithStacks,
|
|
|
|
title: 'Switch with Stacks',
|
|
|
|
routeName: 'SwitchWithStacks',
|
|
|
|
},
|
2018-10-30 13:08:06 -07:00
|
|
|
{
|
|
|
|
component: StackWithDrawer,
|
|
|
|
title: 'Stack with drawer inside',
|
|
|
|
routeName: 'StackWithDrawer',
|
|
|
|
},
|
2018-10-31 13:22:03 -07:00
|
|
|
{
|
|
|
|
component: HeaderBackgroundDefault,
|
|
|
|
title: 'Header background (default transition)',
|
|
|
|
routeName: 'HeaderBackgroundDefault',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: HeaderBackgroundFade,
|
|
|
|
title: 'Header background (fade transition)',
|
|
|
|
routeName: 'HeaderBackgroundFade',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: HeaderBackgroundTranslate,
|
|
|
|
title: 'Header background (translate transition)',
|
|
|
|
routeName: 'HeaderBackgroundTranslate',
|
|
|
|
},
|
2018-08-03 14:59:12 -07:00
|
|
|
];
|
|
|
|
|
2018-10-15 13:17:12 -07:00
|
|
|
// Cache images
|
|
|
|
Expo.Asset.loadAsync(StackAssets);
|
2018-10-10 13:52:38 -07:00
|
|
|
|
2018-08-03 14:59:12 -07:00
|
|
|
class Home extends React.Component {
|
|
|
|
static navigationOptions = {
|
|
|
|
title: 'Examples',
|
|
|
|
};
|
|
|
|
|
|
|
|
_renderItem = ({ item }) => (
|
|
|
|
<ListSection.Item
|
|
|
|
title={item.title}
|
|
|
|
onPress={() => this.props.navigation.navigate(item.routeName)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
_keyExtractor = item => item.routeName;
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
ItemSeparatorComponent={Divider}
|
|
|
|
renderItem={this._renderItem}
|
|
|
|
keyExtractor={this._keyExtractor}
|
2018-10-31 15:21:07 -07:00
|
|
|
renderScrollComponent={props => <SafeAreaScrollView {...props} />}
|
2018-08-03 14:59:12 -07:00
|
|
|
data={data}
|
2018-10-10 13:52:38 -07:00
|
|
|
style={{ backgroundColor: '#fff' }}
|
2018-08-03 14:59:12 -07:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 15:21:07 -07:00
|
|
|
class SafeAreaScrollView extends React.Component {
|
|
|
|
render() {
|
|
|
|
let { children, ...scrollViewProps } = this.props;
|
|
|
|
return (
|
|
|
|
<ScrollView {...scrollViewProps}>
|
|
|
|
<SafeAreaView forceInset={{ top: 'never' }}>{children}</SafeAreaView>
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:58:21 -07:00
|
|
|
const Root = createStackNavigator(
|
|
|
|
{
|
|
|
|
Home: createStackNavigator({ Home }),
|
|
|
|
...data.reduce((acc, it) => {
|
|
|
|
acc[it.routeName] = {
|
|
|
|
screen: it.component,
|
|
|
|
navigationOptions: {
|
|
|
|
title: it.title,
|
|
|
|
},
|
|
|
|
};
|
2018-08-03 14:59:12 -07:00
|
|
|
|
2018-10-16 19:58:21 -07:00
|
|
|
return acc;
|
|
|
|
}, {}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
|
|
|
headerMode: 'none',
|
|
|
|
}
|
|
|
|
);
|
2018-08-03 14:59:12 -07:00
|
|
|
|
2018-10-16 19:58:21 -07:00
|
|
|
const App = createAppContainer(Root);
|
2018-08-03 14:59:12 -07:00
|
|
|
Expo.registerRootComponent(App);
|