mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-06-14 01:54:59 +08:00
Setup example app
This commit is contained in:
52
example/src/ExampleList.js
Normal file
52
example/src/ExampleList.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/* @flow */
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
StyleSheet,
|
||||
} from 'react-native';
|
||||
import { Colors, TouchableRipple } from 'react-native-paper';
|
||||
import RipplesExample from './RipplesExample';
|
||||
|
||||
export const examples = {
|
||||
ripples: RipplesExample,
|
||||
};
|
||||
|
||||
export default class ExampleList extends Component {
|
||||
|
||||
static route = {
|
||||
navigationBar: {
|
||||
title: 'Examples',
|
||||
},
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.list}>
|
||||
{Object.keys(examples).map(id => (
|
||||
<TouchableRipple
|
||||
key={id}
|
||||
style={styles.item}
|
||||
onPress={() => this.props.navigator.push(id)}
|
||||
>
|
||||
<Text style={styles.text}>{examples[id].title}</Text>
|
||||
</TouchableRipple>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
item: {
|
||||
padding: 16,
|
||||
borderBottomColor: Colors.grey300,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
|
||||
text: {
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
12
example/src/RipplesExample.js
Normal file
12
example/src/RipplesExample.js
Normal file
@@ -0,0 +1,12 @@
|
||||
/* @flow */
|
||||
|
||||
import { Component } from 'react';
|
||||
|
||||
export default class RipplesExample extends Component {
|
||||
|
||||
static title = 'Ripples';
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
32
example/src/Router.js
Normal file
32
example/src/Router.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/* @flow */
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
createRouter,
|
||||
} from '@exponent/ex-navigation';
|
||||
import ExampleList, { examples } from './ExampleList';
|
||||
|
||||
const routes = Object.keys(examples)
|
||||
.map(id => ({ id, item: examples[id] }))
|
||||
.reduce((acc, { id, item }) => {
|
||||
const Comp = item;
|
||||
const Screen = props => <Comp {...props} />;
|
||||
|
||||
Screen.route = {
|
||||
navigationBar: {
|
||||
title: Comp.title,
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[id]: () => Screen,
|
||||
};
|
||||
}, {});
|
||||
|
||||
const Router = createRouter(() => ({
|
||||
home: () => ExampleList,
|
||||
...routes,
|
||||
}));
|
||||
|
||||
export default Router;
|
||||
Reference in New Issue
Block a user