Guest User

Untitled

a guest
Jan 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {View, Text, StyleSheet, TextInput, ScrollView, KeyboardAvoidingView, TouchableHighlight} from 'react-native';
  3. import {Icon} from 'react-native-elements';
  4. import { Dropdown } from 'react-native-material-dropdown';
  5.  
  6. export default class TambahAlamatScreen extends Component {
  7.  
  8. constructor(props){
  9. super(props);
  10. this.state = {
  11. APIUrl: '?????',
  12. provinceList: [],
  13. //subProvinsiList: []
  14. }
  15.  
  16. this.getProvinsiListData = this.getProvinsiListData.bind(this);
  17. }
  18.  
  19. //GET DATA PROVINSI
  20. getProvinsiListData(){
  21.  
  22. var temp = [];
  23. fetch( this.state.APIUrl + '/tracking/get/province' , {
  24. method: 'GET',
  25. headers: {
  26. Accept: "application/json",
  27. "Content-Type": "application/json"
  28. }
  29. })
  30. .then(response => response.json())
  31. .then(responseJSON => {
  32. var len = responseJSON.length;
  33. //responseJSON.data.map(data => ({ value: data })
  34. //console.log(len);
  35. if ( len > 0 ){
  36. for ( let i = 0; i < len; i++ ){
  37. var data = responseJSON[i];
  38. //console.log('masuk' + data.province);
  39. var joined = { value: data };
  40. console.log(data);
  41. temp.push(joined);
  42. }
  43. }
  44. //console.log('ini list provinsi=', JSON.stringify(temp));
  45. this.setState({
  46. provinceList: temp
  47. });
  48. console.log('testing' + this.state.provinceList);
  49. })
  50. .catch(error => {
  51. console.log(error);
  52. });
  53.  
  54. }
  55.  
  56.  
  57. //Header customize from react native navigator
  58. static navigationOptions = ({ navigation }) => {
  59. let headerTitle = 'Tambah Alamat';
  60. let headerTitleStyle={ color:'#fff', textAlign: 'center', fontSize:18 , flex:1, marginLeft:-50};
  61. let headerTintColor= '#fff';
  62. let headerStyle={ backgroundColor: '#3250E0' };
  63. let headerBackTitle= '';
  64.  
  65. return{ headerTitle, headerTitleStyle, headerStyle, headerTintColor, headerBackTitle }
  66. }
  67.  
  68.  
  69. //Get API Provinsi
  70. componentDidMount()
  71. {
  72. this.getProvinsiListData();
  73. }
  74.  
  75.  
  76.  
  77.  
  78. render(){
  79.  
  80. return(
  81. <View style={styles.container}>
  82. <KeyboardAvoidingView behavior="padding" enabled>
  83. <ScrollView>
  84. <View style={{marginVertical:10, marginHorizontal:10}}>
  85.  
  86. <View style={styles.jarak}>
  87. <Text style={{fontSize:14}}>Nama Lengkap</Text>
  88. <TextInput
  89. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  90. placeholder='Masukkan nama lengkap'
  91. />
  92. </View>
  93.  
  94. <View style={styles.jarak}>
  95. <Text style={{fontSize:14}}>Alamat</Text>
  96. <TextInput
  97. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  98. placeholder='Masukkan alamat lengkap'
  99. />
  100. </View>
  101.  
  102. <View style={styles.jarak}>
  103. <Text style={{fontSize:14}}>Provinsi</Text>
  104. <Dropdown
  105. baseColor='#616161'
  106. textColor='#616161'
  107. label='Pilih Provinsi'
  108. onChangeText={this.onChangeText}
  109. data={this.state.provinceList}
  110. />
  111. </View>
  112.  
  113. <View style={styles.jarak}>
  114. <Text style={{fontSize:14}}>Kota</Text>
  115. <TextInput
  116. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  117. placeholder='Pilih Kota'
  118. />
  119. </View>
  120.  
  121. <View style={styles.jarak}>
  122. <Text style={{fontSize:14}}>Kecamatan</Text>
  123. <TextInput
  124. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  125. placeholder='Pilih Kecamatan'
  126. />
  127. </View>
  128.  
  129. <View style={styles.jarak}>
  130. <Text style={{fontSize:14}}>Kode Pos</Text>
  131. <TextInput
  132. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  133. placeholder='Masukkan Kode Pos'
  134. />
  135. </View>
  136.  
  137. <View style={styles.jarak}>
  138. <Text style={{fontSize:14}}>No. Telp</Text>
  139. <TextInput
  140. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  141. placeholder='Masukkan No Telepon'
  142. />
  143. </View>
  144.  
  145. <View style={styles.jarak}>
  146. <Text style={{fontSize:14}}>Status</Text>
  147. <TextInput
  148. style={{height: 40, borderBottomColor: '#616161', borderBottomWidth: 2}}
  149. placeholder='Status'
  150. />
  151. </View>
  152.  
  153. <TouchableHighlight style={styles.btn}>
  154. <Text style={styles.btnText}>Simpan</Text>
  155. </TouchableHighlight>
  156.  
  157. </View>
  158. </ScrollView>
  159. </KeyboardAvoidingView>
  160. </View>
  161. );
  162. }
  163. }
  164.  
  165. const styles = StyleSheet.create({
  166. container: {
  167. flex: 1,
  168. justifyContent: 'flex-start',
  169. backgroundColor: '#fff',
  170. paddingHorizontal: 10,
  171. },
  172. jarak: {
  173. marginVertical:10
  174. },
  175. btn: {
  176. backgroundColor: '#3250E0',
  177. padding: 10,
  178. },
  179. btnText: {
  180. textAlign: 'center',
  181. color: '#fff',
  182. },
  183. });
  184.  
  185. var joined = { value: data.province };
Add Comment
Please, Sign In to add comment