mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-06-13 01:28:13 +08:00
* refactor: use own toolbar in examples * refactor: fix missing space * refactor: remove useless code line
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
/* @flow */
|
|
|
|
import React from 'react';
|
|
import { StackNavigator } from 'react-navigation';
|
|
import { Platform, StatusBar } from 'react-native';
|
|
import { Toolbar } from 'react-native-paper';
|
|
import ExampleList, { examples } from './ExampleList';
|
|
|
|
const MORE_ICON = Platform.OS === 'ios' ? 'more-horiz' : 'more-vert';
|
|
|
|
const routes = Object.keys(examples)
|
|
.map(id => ({ id, item: examples[id] }))
|
|
.reduce((acc, { id, item }) => {
|
|
const Comp = item;
|
|
const Screen = props => <Comp {...props} />;
|
|
|
|
Screen.navigationOptions = ({ navigation }) => {
|
|
const { params = {} } = navigation.state;
|
|
return {
|
|
header: (
|
|
<Toolbar
|
|
dark
|
|
statusBarHeight={
|
|
Platform.OS === 'ios' ? 20 : StatusBar.currentHeight
|
|
}
|
|
>
|
|
{!params.showLeftIcon && (
|
|
<Toolbar.BackAction onPress={() => navigation.goBack()} />
|
|
)}
|
|
<Toolbar.Content
|
|
title={Comp.title}
|
|
subtitle={params.showSubtitle ? 'Subtitle' : null}
|
|
/>
|
|
{params.showSearchIcon && (
|
|
<Toolbar.Action icon="search" onPress={() => {}} />
|
|
)}
|
|
{!params.showMoreIcon && (
|
|
<Toolbar.Action icon={MORE_ICON} onPress={() => {}} />
|
|
)}
|
|
</Toolbar>
|
|
),
|
|
/* $FlowFixMe */
|
|
...Comp.navigationOptions,
|
|
};
|
|
};
|
|
|
|
return {
|
|
...acc,
|
|
[id]: { screen: Screen },
|
|
};
|
|
}, {});
|
|
|
|
export default StackNavigator(
|
|
{
|
|
home: { screen: ExampleList },
|
|
...routes,
|
|
},
|
|
{
|
|
navigationOptions: {
|
|
header: (
|
|
<Toolbar
|
|
dark
|
|
statusBarHeight={Platform.OS === 'ios' ? 20 : StatusBar.currentHeight}
|
|
>
|
|
<Toolbar.Content title="Examples" />
|
|
</Toolbar>
|
|
),
|
|
},
|
|
}
|
|
);
|