Advertisement
Guest User

SearchScreen

a guest
Jul 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. /* global require */
  2. import React, { Component } from 'react';
  3. import {
  4. StyleSheet,
  5. View,
  6. Image,
  7. Text,
  8. Picker
  9. } from 'react-native';
  10. import PropTypes from 'prop-types';
  11. import { Item, Input } from 'native-base';
  12. import { Form } from 'native-base';
  13. import PrimeButton from '../elements/PrimeButton';
  14.  
  15. import NavigationBar from '../elements/NavigationBar';
  16.  
  17. import CommonStyles from '../styles/CommonStyles';
  18. import {
  19. responsiveWidth,
  20. responsiveHeight,
  21. deviceWidth,
  22. colors,
  23. fontSize,
  24. fontFamily,
  25. spaceVertical,
  26. marginHorizontal,
  27. borderRadius,
  28. btnHeight,
  29. btnWidth
  30. } from '../styles/variables';
  31. import {
  32. scanIc,
  33. searchIc,
  34. } from '../styles/icon-variables';
  35.  
  36. const INFO_WIDTH = responsiveWidth(42.13);
  37.  
  38. export default class SearchScreen extends Component {
  39. constructor(props) {
  40. super(props);
  41. this.state = {
  42. text: 'type something',
  43. service:'',
  44. city:'',
  45. dataLocation:[],
  46. dataService:[]
  47. };
  48. }
  49.  
  50. componentDidMount() {
  51. var requestLocation = 'https://api.hellobeauty.id/public/location';
  52. var requestService = 'https://api.hellobeauty.id/public/category';
  53. fetch(requestLocation).then((response) => response.json()).then((responseData) => {
  54. this.setState({
  55. dataLocation: responseData.result
  56. });
  57. }).then(()=>{
  58. fetch(requestService).then((response) => response.json()).then((responseData) => {
  59. this.setState({
  60. dataService: responseData.result,
  61. isFinish: true
  62. });
  63. }).done();
  64. }).done();
  65. }
  66.  
  67. render() {
  68. const signInBtnSetting = {
  69. btnWidth: btnWidth.normal,
  70. btnHeight: btnHeight,
  71. style: {
  72. marginBottom: spaceVertical.semiSmall,
  73. }
  74. };
  75.  
  76. return (
  77. <View style={CommonStyles.container}>
  78. <NavigationBar
  79. back
  80. navigation={this.props.navigation}
  81. centerChildren={
  82. <Item style={styles.item}>
  83. <Image
  84. source={require('../../img/icons/search.png')}
  85. style={{width: searchIc.width, height: searchIc.height, marginRight: 5}}
  86. />
  87. <Input
  88. placeholder="type something"
  89. style={StyleSheet.flatten(styles.input)}
  90. />
  91. </Item>
  92. }
  93. centerStyle={{
  94. width: deviceWidth * 3.6/5,
  95. }}
  96. title='SEARCH'
  97. />
  98. <Form style={styles.form}>
  99. <View style={{flexDirection: 'row'}}>
  100. <Text black semiBold large style={{marginTop: spaceVertical.small/2}}>
  101. Service
  102. </Text>
  103. <Picker
  104. selectedValue={this.state.service}
  105. style={{ height: 50, width: 100, justifyContent:'center' }}
  106. onValueChange={(itemValue, itemIndex) => this.setState({service: itemValue})}>
  107. {
  108. this.state.dataService.map((item, key) => (
  109. <Picker.Item key={key} label={item.name} itemValue={item.service_category_id} />
  110. ))
  111. }
  112. </Picker>
  113. </View>
  114. <View style={{flexDirection: 'row'}}>
  115. <Text black semiBold large style={{marginTop: spaceVertical.small/2}}>
  116. Location
  117. </Text>
  118. <Picker
  119. selectedValue={this.state.city}
  120. style={{ height: 50, width: 100, justifyContent:'center'}}
  121. onValueChange={(itemValue, itemIndex) => this.setState({city: itemValue})}>
  122. {
  123. this.state.dataLocation.map((item, key) => (
  124. <Picker.Item key={key} label={item.name} itemValue={item.city_id} />
  125. ))
  126. }
  127. </Picker>
  128. </View>
  129. </Form>
  130. <View style={styles.btnCont}>
  131. <PrimeButton
  132. navigation={this.props.navigation}
  133. setting={signInBtnSetting}
  134. btnText='SEARCH'
  135. onPressButton={this.handleOnPressSearch.bind(this)}
  136. />
  137. </View>
  138. </View>
  139. );
  140. }
  141.  
  142. handleOnPressSearch() {
  143. // const {
  144. // service,
  145. // city,
  146. // } = this.state;
  147. let isError = false;
  148. this.props.navigation.navigate('ListProductsScreen',
  149. {service : this.state.service,
  150. city : this.state.city}
  151. );
  152. }
  153. }
  154.  
  155. const styles = StyleSheet.create({
  156. item: {
  157. marginLeft: 0,
  158. borderColor: colors.black,
  159. borderBottomWidth: 1,
  160. },
  161. input: {
  162. height: responsiveHeight(5.39),
  163. color: colors.black,
  164. fontSize: fontSize.small,
  165. fontFamily: fontFamily.regular,
  166. },
  167. dealInfo: {
  168. position: 'absolute',
  169. left: INFO_WIDTH,
  170. justifyContent: 'space-between',
  171. width: deviceWidth - INFO_WIDTH,
  172. height: responsiveHeight(21.29),
  173. paddingVertical: spaceVertical.small,
  174. paddingLeft: marginHorizontal.small,
  175. paddingRight: marginHorizontal.semiSmall/2,
  176. borderRadius: borderRadius.normal,
  177. backgroundColor: colors.white,
  178. },
  179. form: {
  180. paddingTop: spaceVertical.small,
  181. paddingBottom: responsiveHeight(6)
  182. },
  183. btnCont: {
  184. alignItems: 'center',
  185. paddingBottom: spaceVertical.semiSmall,
  186. }
  187. });
  188.  
  189. SearchScreen.propTypes = {
  190. navigation: PropTypes.any,
  191. onPressSearch: PropTypes.any
  192. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement