@@ -13,7 +13,7 @@ import Carousel, { Pagination } from 'react-native-snap-carousel';
13
13
import Colors from '../Colors' ;
14
14
import Text from '../component/Text' ;
15
15
import Navbar from '../component/Navbar' ;
16
- import { default as ProductComponent } from '../component/Product' ;
16
+ import { default as ProductComponent } from '../component/Product' ;
17
17
18
18
export default class Product extends Component {
19
19
@@ -30,7 +30,7 @@ export default class Product extends Component {
30
30
31
31
componentWillMount ( ) {
32
32
//get the product with id of this.props.product.id from your server
33
- this . setState ( { product : dummyProduct } ) ;
33
+ this . setState ( { product : dummyProduct } ) ;
34
34
}
35
35
36
36
componentDidMount ( ) {
@@ -45,61 +45,65 @@ export default class Product extends Component {
45
45
46
46
render ( ) {
47
47
var left = (
48
- < Left style = { { flex :1 } } >
48
+ < Left style = { { flex : 1 } } >
49
49
< Button onPress = { ( ) => Actions . pop ( ) } transparent >
50
50
< Icon name = 'ios-arrow-back' />
51
51
</ Button >
52
52
</ Left >
53
53
) ;
54
54
var right = (
55
- < Right style = { { flex :1 } } >
55
+ < Right style = { { flex : 1 } } >
56
56
< Button onPress = { ( ) => Actions . search ( ) } transparent >
57
- < Icon name = 'ios-search-outline ' />
57
+ < Icon name = 'ios-search' />
58
58
</ Button >
59
59
< Button onPress = { ( ) => Actions . cart ( ) } transparent >
60
60
< Icon name = 'ios-cart' />
61
61
</ Button >
62
62
</ Right >
63
63
) ;
64
- return (
65
- < Container style = { { backgroundColor : '#fdfdfd' } } >
64
+ return (
65
+ < Container style = { { backgroundColor : '#fdfdfd' } } >
66
66
< Navbar left = { left } right = { right } title = { this . props . product . title } />
67
67
< Content >
68
+
69
+
70
+
71
+
68
72
< Carousel
69
- ref = { ( carousel ) => { this . _carousel = carousel ; } }
70
- sliderWidth = { Dimensions . get ( 'window' ) . width }
71
- itemWidth = { Dimensions . get ( 'window' ) . width }
72
- onSnapToItem = { ( index ) => this . setState ( { activeSlide : index } ) }
73
- enableSnap = { true }
74
- >
75
- { this . renderImages ( ) }
76
- </ Carousel >
77
- < Pagination
78
- dotsLength = { this . state . product . images . length }
79
- activeDotIndex = { this . state . activeSlide }
80
- containerStyle = { { backgroundColor : 'transparent' , paddingTop : 0 , paddingBottom : 0 , marginTop : - 15 } }
81
- dotStyle = { {
82
- width : 10 ,
83
- height : 10 ,
84
- borderRadius : 5 ,
85
- marginHorizontal : 2 ,
86
- backgroundColor : 'rgba(255, 255, 255, 0.92)'
87
- } }
88
- inactiveDotOpacity = { 0.4 }
89
- inactiveDotScale = { 0.6 }
90
- />
91
- < View style = { { backgroundColor : '#fdfdfd' , paddingTop : 10 , paddingBottom : 10 , paddingLeft : 12 , paddingRight : 12 , alignItems : 'center' } } >
73
+ data = { this . state . product . images }
74
+ renderItem = { this . _renderItem }
75
+ ref = { ( carousel ) => { this . _carousel = carousel ; } }
76
+ sliderWidth = { Dimensions . get ( 'window' ) . width }
77
+ itemWidth = { Dimensions . get ( 'window' ) . width }
78
+ onSnapToItem = { ( index ) => this . setState ( { activeSlide : index } ) }
79
+ enableSnap = { true }
80
+ / >
81
+ < Pagination
82
+ dotsLength = { this . state . product . images . length }
83
+ activeDotIndex = { this . state . activeSlide }
84
+ containerStyle = { { backgroundColor : 'transparent' , paddingTop : 0 , paddingBottom : 0 , marginTop : - 15 } }
85
+ dotStyle = { {
86
+ width : 10 ,
87
+ height : 10 ,
88
+ borderRadius : 5 ,
89
+ marginHorizontal : 2 ,
90
+ backgroundColor : 'rgba(255, 255, 255, 0.92)'
91
+ } }
92
+ inactiveDotOpacity = { 0.4 }
93
+ inactiveDotScale = { 0.6 }
94
+ />
95
+ < View style = { { backgroundColor : '#fdfdfd' , paddingTop : 10 , paddingBottom : 10 , paddingLeft : 12 , paddingRight : 12 , alignItems : 'center' } } >
92
96
< Grid >
93
97
< Col size = { 3 } >
94
- < Text style = { { fontSize : 18 } } > { this . state . product . title } </ Text >
98
+ < Text style = { { fontSize : 18 } } > { this . state . product . title } </ Text >
95
99
</ Col >
96
100
< Col >
97
- < Text style = { { fontSize : 20 , fontWeight : 'bold' } } > { this . state . product . price } </ Text >
101
+ < Text style = { { fontSize : 20 , fontWeight : 'bold' } } > { this . state . product . price } </ Text >
98
102
</ Col >
99
103
</ Grid >
100
- < Grid style = { { marginTop : 15 } } >
104
+ < Grid style = { { marginTop : 15 } } >
101
105
< Col >
102
- < View style = { { flex : 1 , justifyContent : 'center' } } >
106
+ < View style = { { flex : 1 , justifyContent : 'center' } } >
103
107
< Text > Color:</ Text >
104
108
</ View >
105
109
</ Col >
@@ -109,15 +113,15 @@ export default class Product extends Component {
109
113
placeholder = "Select a color"
110
114
note = { true }
111
115
selectedValue = { this . state . selectedColor }
112
- onValueChange = { ( color ) => this . setState ( { selectedColor : color } ) }
116
+ onValueChange = { ( color ) => this . setState ( { selectedColor : color } ) }
113
117
>
114
118
{ this . renderColors ( ) }
115
119
</ Picker >
116
120
</ Col >
117
121
</ Grid >
118
122
< Grid >
119
123
< Col >
120
- < View style = { { flex : 1 , justifyContent : 'center' } } >
124
+ < View style = { { flex : 1 , justifyContent : 'center' } } >
121
125
< Text > Size:</ Text >
122
126
</ View >
123
127
</ Col >
@@ -127,81 +131,77 @@ export default class Product extends Component {
127
131
placeholder = "Select a size"
128
132
note = { true }
129
133
selectedValue = { this . state . selectedSize }
130
- onValueChange = { ( size ) => this . setState ( { selectedSize : size } ) }
134
+ onValueChange = { ( size ) => this . setState ( { selectedSize : size } ) }
131
135
>
132
136
{ this . renderSize ( ) }
133
137
</ Picker >
134
138
</ Col >
135
139
</ Grid >
136
140
< Grid >
137
141
< Col >
138
- < View style = { { flex : 1 , justifyContent : 'center' } } >
142
+ < View style = { { flex : 1 , justifyContent : 'center' } } >
139
143
< Text > Quantity:</ Text >
140
144
</ View >
141
145
</ Col >
142
146
< Col size = { 3 } >
143
- < View style = { { flex : 1 , flexDirection : 'row' } } >
144
- < Button style = { { flex : 1 } } icon light onPress = { ( ) => this . setState ( { quantity : this . state . quantity > 1 ? this . state . quantity - 1 : 1 } ) } >
145
- < Icon name = 'ios-remove-outline' />
147
+ < View style = { { flex : 1 , flexDirection : 'row' } } >
148
+ < Button block icon transparent onPress = { ( ) => this . setState ( { quantity : this . state . quantity > 1 ? this . state . quantity - 1 : 1 } ) } >
149
+ < Icon name = 'ios-remove' style = { { color : Colors . navbarBackgroundColor } } />
146
150
</ Button >
147
- < View style = { { flex : 4 , justifyContent : 'center' , alignItems : 'center' , paddingLeft : 30 , paddingRight : 30 } } >
148
- < Text style = { { fontSize : 18 } } > { this . state . quantity } </ Text >
151
+ < View style = { { flex : 4 , justifyContent : 'center' , alignItems : 'center' , paddingLeft : 30 , paddingRight : 30 } } >
152
+ < Text style = { { fontSize : 18 } } > { this . state . quantity } </ Text >
149
153
</ View >
150
- < Button style = { { flex : 1 } } icon light onPress = { ( ) => this . setState ( { quantity : this . state . quantity + 1 } ) } >
151
- < Icon name = 'ios-add' />
154
+ < Button block icon transparent onPress = { ( ) => this . setState ( { quantity : this . state . quantity + 1 } ) } >
155
+ < Icon style = { { color : Colors . navbarBackgroundColor } } name = 'ios-add' />
152
156
</ Button >
153
157
</ View >
154
158
</ Col >
155
159
</ Grid >
156
- < Grid style = { { marginTop : 15 } } >
160
+ < Grid style = { { marginTop : 15 } } >
157
161
< Col size = { 3 } >
158
- < Button block onPress = { this . addToCart . bind ( this ) } style = { { backgroundColor : Colors . navbarBackgroundColor } } >
159
- < Text style = { { color : "#fdfdfd" , marginLeft : 5 } } > Add to cart</ Text >
162
+ < Button block onPress = { this . addToCart . bind ( this ) } style = { { backgroundColor : Colors . navbarBackgroundColor } } >
163
+ < Text style = { { color : "#fdfdfd" , marginLeft : 5 } } > Add to cart</ Text >
160
164
</ Button >
161
165
</ Col >
162
166
< Col >
163
- < Button block onPress = { this . addToWishlist . bind ( this ) } icon transparent style = { { backgroundColor : '#fdfdfd' } } >
164
- < Icon style = { { color : Colors . navbarBackgroundColor } } name = 'ios-heart' />
165
- </ Button >
167
+ < Button block onPress = { this . addToWishlist . bind ( this ) } icon transparent style = { { backgroundColor : '#fdfdfd' } } >
168
+ < Icon style = { { color : Colors . navbarBackgroundColor } } name = 'ios-heart' />
169
+ </ Button >
166
170
</ Col >
167
171
</ Grid >
168
- < View style = { { marginTop : 15 , padding : 10 , borderWidth : 1 , borderRadius : 3 , borderColor : 'rgba(149, 165, 166, 0.3)' } } >
169
- < Text style = { { marginBottom : 5 } } > Description</ Text >
170
- < View style = { { width : 50 , height : 1 , backgroundColor : 'rgba(44, 62, 80, 0.5)' , marginLeft : 7 , marginBottom : 10 } } />
172
+ < View style = { { marginTop : 15 , padding : 10 , borderWidth : 1 , borderRadius : 3 , borderColor : 'rgba(149, 165, 166, 0.3)' } } >
173
+ < Text style = { { marginBottom : 5 } } > Description</ Text >
174
+ < View style = { { width : 50 , height : 1 , backgroundColor : 'rgba(44, 62, 80, 0.5)' , marginLeft : 7 , marginBottom : 10 } } />
171
175
< NBText note >
172
176
{ this . state . product . description }
173
177
</ NBText >
174
178
</ View >
175
179
</ View >
176
- < View style = { { marginTop : 15 , paddingLeft : 12 , paddingRight : 12 } } >
177
- < Text style = { { marginBottom : 5 } } > Similar items</ Text >
178
- < View style = { { width : 50 , height : 1 , backgroundColor : 'rgba(44, 62, 80, 0.5)' , marginLeft : 7 , marginBottom : 10 } } />
180
+ < View style = { { marginTop : 15 , paddingLeft : 12 , paddingRight : 12 } } >
181
+ < Text style = { { marginBottom : 5 } } > Similar items</ Text >
182
+ < View style = { { width : 50 , height : 1 , backgroundColor : 'rgba(44, 62, 80, 0.5)' , marginLeft : 7 , marginBottom : 10 } } />
179
183
{ this . renderSimilairs ( ) }
180
184
</ View >
181
185
</ Content >
182
186
</ Container >
183
187
) ;
184
188
}
185
-
186
- renderImages ( ) {
187
- let images = [ ] ;
188
- this . state . product . images . map ( ( img , i ) => {
189
- images . push (
190
- < TouchableWithoutFeedback
191
- key = { i }
192
- onPress = { ( ) => this . openGallery ( i ) }
193
- >
194
- < Image
195
- source = { { uri : img } }
196
- style = { { width : Dimensions . get ( 'window' ) . width , height : 350 } }
197
- resizeMode = "cover"
198
- />
199
- </ TouchableWithoutFeedback >
200
- ) ;
201
- } ) ;
202
- return images ;
189
+ _renderItem = ( { item, index } ) => {
190
+ return (
191
+ < TouchableWithoutFeedback
192
+ key = { index }
193
+ onPress = { ( ) => this . openGallery ( index ) }
194
+ >
195
+ < Image
196
+ source = { { uri : item } }
197
+ style = { { width : Dimensions . get ( 'window' ) . width , height : 350 } }
198
+ resizeMode = "cover"
199
+ />
200
+ </ TouchableWithoutFeedback >
201
+ ) ;
203
202
}
204
203
204
+
205
205
renderColors ( ) {
206
206
let colors = [ ] ;
207
207
this . state . product . colors . map ( ( color , i ) => {
@@ -225,29 +225,29 @@ export default class Product extends Component {
225
225
renderSimilairs ( ) {
226
226
let items = [ ] ;
227
227
let stateItems = this . state . product . similarItems ;
228
- for ( var i = 0 ; i < stateItems . length ; i += 2 ) {
229
- if ( stateItems [ i + 1 ] ) {
228
+ for ( var i = 0 ; i < stateItems . length ; i += 2 ) {
229
+ if ( stateItems [ i + 1 ] ) {
230
230
items . push (
231
231
< Grid key = { i } >
232
232
< ProductComponent key = { stateItems [ i ] . id } product = { stateItems [ i ] } />
233
- < ProductComponent key = { stateItems [ i + 1 ] . id } product = { stateItems [ i + 1 ] } isRight />
233
+ < ProductComponent key = { stateItems [ i + 1 ] . id } product = { stateItems [ i + 1 ] } isRight />
234
234
</ Grid >
235
235
) ;
236
236
}
237
237
else {
238
238
items . push (
239
239
< Grid key = { i } >
240
240
< ProductComponent key = { stateItems [ i ] . id } product = { stateItems [ i ] } />
241
- < Col key = { i + 1 } />
241
+ < Col key = { i + 1 } />
242
242
</ Grid >
243
243
) ;
244
244
}
245
245
}
246
246
return items ;
247
247
}
248
248
249
- openGallery ( pos ) {
250
- Actions . imageGallery ( { images : this . state . product . images , position : pos } ) ;
249
+ openGallery = ( pos ) => {
250
+ Actions . imageGallery ( { images : this . state . product . images , position : pos } ) ;
251
251
}
252
252
253
253
addToCart ( ) {
@@ -256,11 +256,11 @@ export default class Product extends Component {
256
256
product [ 'size' ] = this . state . selectedSize ;
257
257
product [ 'quantity' ] = this . state . quantity ;
258
258
AsyncStorage . getItem ( "CART" , ( err , res ) => {
259
- if ( ! res ) AsyncStorage . setItem ( "CART" , JSON . stringify ( [ product ] ) ) ;
259
+ if ( ! res ) AsyncStorage . setItem ( "CART" , JSON . stringify ( [ product ] ) ) ;
260
260
else {
261
261
var items = JSON . parse ( res ) ;
262
262
items . push ( product ) ;
263
- AsyncStorage . setItem ( "CART" , JSON . stringify ( items ) ) ;
263
+ AsyncStorage . setItem ( "CART" , JSON . stringify ( items ) ) ;
264
264
}
265
265
Toast . show ( {
266
266
text : 'Product added to your cart !' ,
@@ -276,18 +276,18 @@ export default class Product extends Component {
276
276
var product = this . state . product ;
277
277
var success = true ;
278
278
AsyncStorage . getItem ( "WISHLIST" , ( err , res ) => {
279
- if ( ! res ) AsyncStorage . setItem ( "WISHLIST" , JSON . stringify ( [ product ] ) ) ;
279
+ if ( ! res ) AsyncStorage . setItem ( "WISHLIST" , JSON . stringify ( [ product ] ) ) ;
280
280
else {
281
281
var items = JSON . parse ( res ) ;
282
- if ( this . search ( items , product ) ) {
282
+ if ( this . search ( items , product ) ) {
283
283
success = false
284
284
}
285
285
else {
286
286
items . push ( product ) ;
287
- AsyncStorage . setItem ( "WISHLIST" , JSON . stringify ( items ) ) ;
287
+ AsyncStorage . setItem ( "WISHLIST" , JSON . stringify ( items ) ) ;
288
288
}
289
289
}
290
- if ( success ) {
290
+ if ( success ) {
291
291
Toast . show ( {
292
292
text : 'Product added to your wishlist !' ,
293
293
position : 'bottom' ,
@@ -309,8 +309,8 @@ export default class Product extends Component {
309
309
}
310
310
311
311
search ( array , object ) {
312
- for ( var i = 0 ; i < array . length ; i ++ )
313
- if ( JSON . stringify ( array [ i ] ) === JSON . stringify ( object ) )
312
+ for ( var i = 0 ; i < array . length ; i ++ )
313
+ if ( JSON . stringify ( array [ i ] ) === JSON . stringify ( object ) )
314
314
return true ;
315
315
return false ;
316
316
}
@@ -333,8 +333,8 @@ const dummyProduct = {
333
333
sizes : [ 'S' , 'M' , 'L' , 'XL' , 'XXL' ] ,
334
334
category : 'MAN' ,
335
335
similarItems : [
336
- { id : 10 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,g_face,h_250,x_248/v1500465308/fashion-men-s-individuality-black-and-white-157675_wnctss.jpg' } ,
337
- { id : 11 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250/v1500465308/pexels-photo-179909_ddlsmt.jpg' } ,
338
- { id : 12 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250/v1500465308/pexels-photo-179909_ddlsmt.jpg' }
336
+ { id : 10 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,g_face,h_250,x_248/v1500465308/fashion-men-s-individuality-black-and-white-157675_wnctss.jpg' } ,
337
+ { id : 11 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250/v1500465308/pexels-photo-179909_ddlsmt.jpg' } ,
338
+ { id : 12 , title : 'V NECK T-SHIRT' , price : '29$' , image : 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250/v1500465308/pexels-photo-179909_ddlsmt.jpg' }
339
339
]
340
340
} ;
0 commit comments