Guest User

Untitled

a guest
Jan 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Image, Dimensions, TouchableWithoutFeedback, AsyncStorage,StyleSheet,Text} from 'react-native';
  3. import { View, Root, Container, Content, Button, Left, Right, Icon, Picker, Item, Grid, Col, Toast,TextRN } from 'native-base';
  4. import Carousel, { Pagination } from 'react-native-snap-carousel';
  5. import { Font, AppLoading } from "expo";
  6. export default class Product extends Component {
  7.  
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. product: {},
  12. activeSlide: 0,
  13. quantity: 1,
  14. selectedColor: '',
  15. selectedSize: '',
  16. loading: true
  17. };
  18. }
  19. static route = {
  20. navigationBar: {
  21. title: 'ProductDetail',
  22. tintColor: '#FFF',
  23. },
  24. };
  25. async componentWillMount() {
  26. await Font.loadAsync({
  27. Roboto: require("native-base/Fonts/Roboto.ttf"),
  28. Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf")
  29. });
  30. this.setState({ loading: false, product: dummyProduct});
  31.  
  32. alert(JSON.stringify(this.state.product));
  33. if (this.state.product.length > 0) {
  34. let defColor = this.state.product.colors[0];
  35. let defSize = this.state.product.sizes[0];
  36. this.setState({
  37. selectedColor: defColor,
  38. selectedSize: defSize
  39. });
  40. }
  41. }
  42.  
  43.  
  44.  
  45. render() {
  46. if (this.state.product.length <= 0) {
  47. return (
  48. <Text>Loading</Text>
  49. );
  50. }
  51. return(
  52.  
  53. <Container style={{backgroundColor: '#fdfdfd'}}>
  54.  
  55. <Content>
  56. <Carousel
  57. ref={(carousel) => { this._carousel = carousel; }}
  58. sliderWidth={Dimensions.get('window').width}
  59. itemWidth={Dimensions.get('window').width}
  60. onSnapToItem={(index) => this.setState({ activeSlide: index }) }
  61. enableSnap={true}
  62. >
  63. {this.renderImages()}
  64. </Carousel>
  65. <Pagination
  66. dotsLength={this.state.product.images.length}
  67. activeDotIndex={this.state.activeSlide}
  68. containerStyle={{ backgroundColor: 'transparent',paddingTop: 0, paddingBottom: 0, marginTop: -15 }}
  69. dotStyle={{
  70. width: 10,
  71. height: 10,
  72. borderRadius: 5,
  73. marginHorizontal: 2,
  74. backgroundColor: 'rgba(255, 255, 255, 0.92)'
  75. }}
  76. inactiveDotOpacity={0.4}
  77. inactiveDotScale={0.6}
  78. />
  79. <View style={{backgroundColor: '#fdfdfd', paddingTop: 10, paddingBottom: 10, paddingLeft: 12, paddingRight: 12, alignItems: 'center'}}>
  80. <Grid>
  81. <Col size={3}>
  82. <TextRN style={{ fontSize: 18 }}>{this.state.product.title}</TextRN>
  83. </Col>
  84. <Col>
  85. <TextRN style={{ fontSize: 20, fontWeight: 'bold' }}>{this.state.product.price}</TextRN>
  86. </Col>
  87. </Grid>
  88. <Grid style={{marginTop: 15}}>
  89. <Col>
  90. <View style={{flex: 1, justifyContent: 'center'}}>
  91. <TextRN>Color:</TextRN>
  92. </View>
  93. </Col>
  94. <Col size={3}>
  95. <Picker
  96. mode="dropdown"
  97. placeholder="Select a color"
  98. note={true}
  99. selectedValue={this.state.selectedColor}
  100. onValueChange={(color) => this.setState({selectedColor: color})}
  101. >
  102. {this.renderColors()}
  103. </Picker>
  104. </Col>
  105. </Grid>
  106. <Grid>
  107. <Col>
  108. <View style={{flex: 1, justifyContent: 'center'}}>
  109. <TextRN>Size:</TextRN>
  110. </View>
  111. </Col>
  112. <Col size={3}>
  113. <Picker
  114. mode="dropdown"
  115. placeholder="Select a size"
  116. note={true}
  117. selectedValue={this.state.selectedSize}
  118. onValueChange={(size) => this.setState({selectedSize: size})}
  119. >
  120. {this.renderSize()}
  121. </Picker>
  122. </Col>
  123. </Grid>
  124. <Grid>
  125. <Col>
  126. <View style={{flex: 1, justifyContent: 'center'}}>
  127. <TextRN>Quantity:</TextRN>
  128. </View>
  129. </Col>
  130. <Col size={3}>
  131. <View style={{flex: 1, flexDirection: 'row'}}>
  132. <Button style={{flex: 1}} icon light onPress={() => this.setState({quantity: this.state.quantity>1 ? this.state.quantity-1 : 1})} >
  133. <Icon name='ios-remove-outline' />
  134. </Button>
  135. <View style={{flex: 4, justifyContent: 'center', alignItems: 'center', paddingLeft: 30, paddingRight: 30}}>
  136. <TextRN style={{ fontSize: 18 }}>{this.state.quantity}</TextRN>
  137. </View>
  138. <Button style={{flex: 1}} icon light onPress={() => this.setState({quantity: this.state.quantity+1})}>
  139. <Icon name='ios-add' />
  140. </Button>
  141. </View>
  142. </Col>
  143. </Grid>
  144. <Grid style={{marginTop: 15}}>
  145. <Col size={3}>
  146. <Button block onPress={this.addToCart.bind(this)} style={{backgroundColor: '#2c3e50'}}>
  147. <TextRN style={{ color: "#fdfdfd", marginLeft: 5 }}>Add to cart</TextRN>
  148. </Button>
  149. </Col>
  150. <Col>
  151. <Button block onPress={this.addToWishlist.bind(this)} icon transparent style={{backgroundColor: '#fdfdfd'}}>
  152. <Icon style={{color: '#2c3e50'}} name='ios-heart' />
  153. </Button>
  154. </Col>
  155. </Grid>
  156. <View style={{marginTop: 15, padding: 10, borderWidth: 1, borderRadius: 3, borderColor: 'rgba(149, 165, 166, 0.3)'}}>
  157. <TextRN style={{ marginBottom: 5 }}>Description</TextRN>
  158. <View style={{width: 50, height: 1, backgroundColor: 'rgba(44, 62, 80, 0.5)', marginLeft: 7, marginBottom: 10}} />
  159. <TextRN note>
  160. {this.state.product.description}
  161. </TextRN>
  162. </View>
  163. </View>
  164. <View style={{marginTop: 15, paddingLeft: 12, paddingRight: 12}}>
  165. <TextRN style={{ marginBottom: 5 }}>Similar items</TextRN>
  166. <View style={{width: 50, height: 1, backgroundColor: 'rgba(44, 62, 80, 0.5)', marginLeft: 7, marginBottom: 10}} />
  167.  
  168. </View>
  169. </Content>
  170.  
  171. </Container>
  172. );
  173.  
  174.  
  175. }
  176. }
  177.  
  178. const dummyProduct = {
  179. id: 2,
  180. title: 'V NECK T-SHIRT',
  181. description: "Pellentesque orci lectus, bibendum iaculis aliquet id, ullamcorper nec ipsum. In laoreet ligula vitae tristique viverra. Suspendisse augue nunc, laoreet in arcu ut, vulputate malesuada justo. Donec porttitor elit justo, sed lobortis nulla interdum et. Sed lobortis sapien ut augue condimentum, eget ullamcorper nibh lobortis. Cras ut bibendum libero. Quisque in nisl nisl. Mauris vestibulum leo nec pellentesque sollicitudin. Pellentesque lacus eros, venenatis in iaculis nec, luctus at eros. Phasellus id gravida magna. Maecenas fringilla auctor diam consectetur placerat. Suspendisse non convallis ligula. Aenean sagittis eu erat quis efficitur. Maecenas volutpat erat ac varius bibendum. Ut tincidunt, sem id tristique commodo, nunc diam suscipit lectus, vel",
  182. image: 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250,w_358,x_150/v1500465309/pexels-photo-206470_nwtgor.jpg',
  183. images: [
  184. 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250,w_358,x_150/v1500465309/pexels-photo-206470_nwtgor.jpg',
  185. 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250,x_226,y_54/v1500465309/pexels-photo-521197_hg8kak.jpg',
  186. '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',
  187. 'http://res.cloudinary.com/atf19/image/upload/c_crop,h_250/v1500465308/pexels-photo-179909_ddlsmt.jpg'
  188. ],
  189. price: '120$',
  190. colors: ['Red', 'Blue', 'Black'],
  191. sizes: ['S', 'M', 'L', 'XL', 'XXL'],
  192. category: 'MAN',
  193. similarItems: [
  194. {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'},
  195. {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'},
  196. {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'}
  197. ]
  198. };
Add Comment
Please, Sign In to add comment