1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, FlatList, Modal } from 'react-native'; import StatusView from './components/StatusView' import Swiper from 'react-native-swiper' import GlobalStyles from './utils/GlobalStyles' import Focus from '.././src/components/home/Focus' import PicTextCell from '.././src/components/home/PicTextCell' import { NavigationActions } from 'react-navigation';
class Home extends Component { constructor(props) { super(props); this.state = { titleList: ['发现', '关注'], currentIndex: 0 };
}
render() { return ( <View style={styles.container}> <StatusView></StatusView> <View style={styles.titleView}> { this.state.titleList.map((item, index) => { return (<Text key={item} style={this.state.currentIndex == index ? styles.fontBig : styles.fontNormal} onPress={() => { this.press(index) }}>{item}</Text>) } ) } </View>
<FlatList data={["1", "2", "3", "1", "2", "3", "1", "2", "3"]} renderItem={(item) => { switch (item.index) { case 0: return (<View style={styles.swiperView}> <Swiper style={styles.swiper} height={200} width={GlobalStyles.window_width}> <View style={styles.slide}> <Image style={styles.image} style={{ width: GlobalStyles.window_width - 40, height: 130 }} source={{ uri: 'https://facebook.github.io/react-native/img/tiny_logo.png' }}></Image> </View>
<View style={styles.slide}> <Image style={styles.image} style={{ width: GlobalStyles.window_width - 40, height: 130 }} source={{ uri: 'https://facebook.github.io/react-native/img/tiny_logo.png' }}></Image> </View>
<View style={styles.slide}> <Image style={styles.image} style={{ width: GlobalStyles.window_width - 40, height: 130 }} source={{ uri: 'https://facebook.github.io/react-native/img/tiny_logo.png' }}></Image> </View> </Swiper> </View>) break; case 1: return (<Focus data={["关注", "已关注", "已关注"]}></Focus>) break default: return (<PicTextCell style={styles.picTextCell} imageurls={[ { url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460', }, { url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460', }, { url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460', }]} showPic={(index) => { this.showPic(index) }}></PicTextCell>) break; }
}} />
</View > ); } press(index) { this.setState({ currentIndex: index }) }
showPic(index) { const navigateAction = NavigationActions.navigate({ routeName: 'ImagePickViewer', params: {}, // navigate can have a nested navigate action that will be run inside the child router (navigate 可以用有一个嵌套的navigate 操作) action: NavigationActions.navigate({ routeName: 'ImagePickViewer' }), }); this.props.navigation.dispatch(navigateAction);
// this.props.navigation.navigate('ImagePickViewer')
} }
const styles = StyleSheet.create({ fontBig: { width: 50, fontSize: 21, fontWeight: 'bold' }, fontNormal: { width: 40, fontSize: 16, }, container: { flex: 1,
}, titleView: { flexDirection: 'row', alignItems: 'flex-end', marginLeft: 20, marginRight: 20, }, swiper: { marginTop: 20,
}, image: {
}, slide: { alignItems: 'center', width: GlobalStyles.window_width, height: 200 }, swiperView: { height: 200 },
})
export default Home;
|