@@ -4,28 +4,89 @@ import {
44 Navigator ,
55 View ,
66 Text ,
7- StyleSheet
7+ StyleSheet ,
8+ Image ,
9+ ScrollView ,
10+ TouchableOpacity ,
11+ Dimensions
812} from 'react-native' ;
913
10- export default class Article extends Component {
14+ class Article extends Component {
1115 constructor ( props ) {
1216 super ( props ) ;
1317 }
1418
19+ componentWillMount ( ) {
20+ const { actions } = this . props ;
21+ actions . getPhoto ( {
22+ page :1 ,
23+ limit :10
24+ } )
25+ }
26+
1527 render ( ) {
28+ console . log ( this )
29+ const { Acticle } = this . props ;
1630 return (
1731 < View style = { [ styles . container ] } >
18- < Text style = { { fontSize :30 , color :'#fff' } } > Hello React-native</ Text >
32+ {
33+ Acticle && Acticle . photos && Acticle . photos . length != 0 ?
34+ < ScrollView style = { { flex :1 } } >
35+
36+ < View style = { styles . imgsWrap } >
37+ < View style = { styles . imgs } >
38+ { this . _renderImg ( Acticle . photos . slice ( 0 , 5 ) ) }
39+ </ View >
40+ < View style = { styles . imgs } >
41+ { this . _renderImg ( Acticle . photos . slice ( 5 , 10 ) ) }
42+ </ View >
43+ </ View >
44+ </ ScrollView > :
45+ < View style = { { flexDirection :'row' , paddingTop :30 , alignItems : 'center' , justifyContent : 'center' } } >
46+ < Text style = { { fontSize :20 } } > 说好的妹子呢</ Text >
47+ </ View >
48+ }
1949 </ View >
2050 )
2151 }
22- }
2352
53+ _renderImg ( imgs ) {
54+ return (
55+ imgs . map ( ( v , k ) => {
56+ return (
57+ < TouchableOpacity
58+ key = { 'photo-' + k }
59+ >
60+ < Image
61+ style = { { width :width / 2 , height :parseInt ( Math . random ( ) * ( width / 4 ) + ( width / 2 ) ) } }
62+ source = { { uri : v . url } }
63+ />
64+ </ TouchableOpacity >
65+ )
66+ } )
67+ )
68+ }
69+ }
70+ const { width , height } = Dimensions . get ( 'window' ) ;
2471const styles = StyleSheet . create ( {
2572 container : {
2673 flex : 1 ,
27- alignItems : 'center' ,
28- justifyContent : 'center' ,
29- backgroundColor : 'blue'
30- }
74+ // alignItems : 'center',
75+ // justifyContent : 'center',
76+ // backgroundColor : 'blue'
77+ } ,
78+ imgsWrap : {
79+ flex :1 ,
80+ flexDirection : "row"
81+ } ,
82+ imgs : {
83+ flex : 1
84+ } ,
3185} )
86+
87+ export const LayoutComponent = Article ;
88+ export function mapStateToProps ( state ) {
89+ return {
90+ Acticle : state . Acticle ,
91+ }
92+ }
0 commit comments