UNPKG

2.24 kBJavaScriptView Raw
1import React, {
2 Component,
3} from 'react';
4
5import {
6 Modal, ScrollView, Text, TouchableWithoutFeedback, View,
7} from 'react-native';
8
9import Demo from '../demo';
10
11class KitchenSink extends Component {
12
13 state = {
14 modalVisible: false,
15 target: null,
16 }
17
18 hideModal = () => {
19 this.setState({
20 modalVisible: false,
21 })
22 }
23
24 openModal = target => {
25 this.setState({
26 modalVisible: true,
27 target,
28 })
29 }
30
31 render() {
32 const { state, openModal, hideModal } = this;
33 const { modalVisible, target } = state;
34 const Content = Demo[target];
35 return (
36 <View flex={1}>
37 <ScrollView backgroundColor="#eee">
38 <View height={100} justifyContent="space-around" padding={20}>
39 <Text style={{ fontSize: 20 }}>BeeUI</Text>
40 <Text>A React Native UI Libary.</Text>
41 </View>
42 {Object.keys(Demo).map((key, index) => (
43 <View key={index}>
44 <TouchableWithoutFeedback onPress={() => openModal(key)}>
45 <View backgroundColor="#fff" height={40} justifyContent="center" margin={10} marginTop={0} paddingLeft={10}>
46 <Text>{key}</Text>
47 </View>
48 </TouchableWithoutFeedback>
49 </View>
50 ))}
51 </ScrollView>
52 <Modal animationType="slide" transparent visible={modalVisible}>
53 <View backgroundColor="rgba(0,0,0,.3)" marginTop={20} flex={1}>
54 <View alignItems="center" backgroundColor="#fff" flexDirection="row" height={44}>
55 <View bottom={0} justifyContent="center" left={0} position="absolute" right={0} top={0}>
56 <Text style={{ textAlign: 'center' }}>{target}</Text>
57 </View>
58 <TouchableWithoutFeedback onPress={hideModal}>
59 <View backgroundColor="#000" marginLeft={6} paddingHorizontal={6} paddingVertical={6}>
60 <Text style={{ color: '#fff' }}>关闭</Text>
61 </View>
62 </TouchableWithoutFeedback>
63 </View>
64 <View backgroundColor="#fff" flex={1}>
65 <Content />
66 </View>
67 </View>
68 </Modal>
69 </View>
70 );
71 }
72}
73
74export default KitchenSink;