Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. /*Example of Navigation Drawer with Sectioned Menu*/
  2. import React, { Component } from 'react';
  3. import { StyleSheet, View, Text, Picker, Image, TouchableOpacity, TextInput } from 'react-native';
  4. import AnimateLoadingButton from 'react-native-animate-loading-button';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import SearchableDropdown from 'react-native-searchable-dropdown';
  7. import NetInfo from '@react-native-community/netinfo'
  8.  
  9.  
  10. export default class Db extends Component {
  11. static navigationOptions = {
  12. title: 'Db ',
  13. tabBarOptions: {
  14. labelStyle: {
  15. fontSize: 16,
  16. color: '#000',
  17. },
  18. style: {
  19. backgroundColor: '#52c5d8',
  20. borderRadius: 15,
  21. },
  22. },
  23. };
  24.  
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. listdb: [],
  29. dbnya: '',
  30. connection_Status: ""
  31. }
  32. }
  33.  
  34.  
  35.  
  36.  
  37. _onPressHandler() {
  38. this.loadingButton.showLoading(true);
  39.  
  40. // mock
  41. setTimeout(() => {
  42. this.loadingButton.showLoading(false);
  43. }, 1000);
  44. if (this.state.connection_Status == "Offline") {
  45. alert('Poor Internet Connection')
  46. }
  47. else if (this.state.Dbname == "" || this.state.Dbname == null) {
  48. alert('Please Select Database')
  49. }
  50. else {
  51. this.props.navigation.navigate('login', {
  52. idDbase:this.state.id,
  53. Dbname:this.state.Dbname
  54. })
  55. }
  56. }
  57.  
  58.  
  59. componentDidMount = () => {
  60.  
  61. NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
  62.  
  63. NetInfo.isConnected.fetch().done((isConnected) => {
  64. if (isConnected == true) {
  65. this.setState({ connection_Status: "Online" })
  66. }
  67. else {
  68. this.setState({ connection_Status: "Offline" })
  69. alert('Offline Mode No Internet Connection')
  70. }
  71. });
  72.  
  73. fetch('https://tracessystem.com/apiims/inv_list_db.php', {
  74. method: 'POST',
  75. headers: {
  76. 'Accept': 'application/json',
  77. 'Content-Type': 'application/json',
  78. },
  79. body: JSON.stringify({
  80.  
  81. })
  82. })
  83. .then((response) => response.json())
  84. .then((responseJson) => {
  85. this.setState({
  86. listdb: responseJson,
  87. })
  88. })
  89. .catch((error) => {
  90. console.error(error);
  91. });
  92. }
  93.  
  94. componentWillUnmount = () => {
  95.  
  96. //internet
  97. NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
  98. //end internet
  99. }
  100. //internet
  101. handleConnectivityChange = (isConnected) => {
  102. if (isConnected == true) {
  103. this.setState({ connection_Status: "Online" })
  104.  
  105. }
  106. else {
  107. this.setState({ connection_Status: "Offline" })
  108. alert('No Internet Status')
  109. }
  110. };
  111. //end internet
  112.  
  113.  
  114. render() {
  115. dblist = this.state.listdb
  116. return (
  117.  
  118. <ScrollView keyboardShouldPersistTaps="handled">
  119. <View style={styles.backgrondImage}>
  120. <View style={styles.containerImage}>
  121. <Image
  122. source={require('../assets/logotwist.png')}
  123. style={{ width: 180, height: 60, top: 15 }} />
  124. <Text></Text>
  125. </View>
  126. <View style={styles.containerImage}>
  127. <Image
  128. source={require('../assets/Artboard_1.png')}
  129. style={{ width: 300, height: 180, top: 15 }} />
  130. <Text></Text>
  131. </View>
  132. <View style={styles.BoxVisitCentering}>
  133. <View style={styles.BoxVisit}>
  134. <View style={styles.centext}>
  135. <Text></Text>
  136. <SearchableDropdown
  137. onItemSelect={(item) => {
  138.  
  139. this.setState({
  140. id: item.id,
  141. Dbname: item.name,
  142. });
  143. }}
  144. containerStyle={{ padding: 5 }}
  145. onRemoveItem={(item, index) => {
  146. const items = this.state.selectedItems.filter((sitem) => sitem.id !== item.id);
  147. this.setState({ selectedItems: items });
  148. }}
  149. itemStyle={{
  150. padding: 10,
  151. marginTop: 2,
  152. backgroundColor: '#ddd',
  153. borderColor: 'skyblue',
  154. borderWidth: 1,
  155. borderRadius: 5,
  156. }}
  157. itemTextStyle={{ color: '#222' }}
  158. itemsContainerStyle={{ maxHeight: 140 }}
  159. items={dblist}
  160. defaultIndex={2}
  161. resetValue={false}
  162. textInputProps={
  163. {
  164. placeholder: "Select Database",
  165. underlineColorAndroid: "transparent",
  166. style: {
  167. padding: 10,
  168. borderWidth: 0.5,
  169. borderColor: '#ccc',
  170. borderRadius: 5,
  171. width: "100%",
  172. underlineColorAndroid: '#00A8CC'
  173. },
  174. }
  175. }
  176. listProps={
  177. {
  178.  
  179. }
  180. }
  181. />
  182. </View>
  183. <Text></Text>
  184. <View style={styles.centeringButton}>
  185. <AnimateLoadingButton
  186. ref={c => (this.loadingButton = c)}
  187. width={150}
  188. height={40}
  189. marginTop={80}
  190. title="NEXT"
  191. titleFontSize={18}
  192. titleColor="rgb(255,255,255)"
  193. backgroundColor="#00A8CC"
  194. borderRadius={25}
  195. onPress={this._onPressHandler.bind(this)}
  196. />
  197. </View>
  198. <Text></Text>
  199. </View>
  200. </View>
  201. </View>
  202. </ScrollView>
  203. );
  204. }
  205. }
  206.  
  207. const styles = StyleSheet.create({
  208. MainContainer: {
  209. flex: 1,
  210. alignItems: 'center',
  211. marginTop: 50,
  212. justifyContent: 'center',
  213. },
  214. centeringButton: {
  215. justifyContent: 'center',
  216. alignItems: 'center',
  217. },
  218. BoxVisit:
  219. {
  220. textAlign: 'center',
  221. color: 'grey',
  222. fontSize: 30,
  223. backgroundColor: "#fff",
  224. alignItems: 'center',
  225. width: 320,
  226. height: 910,
  227. borderRadius: 17,
  228. position: 'absolute',
  229. top: 50,
  230. },
  231. centext: {
  232. width: '60%',
  233. },
  234. BoxVisitCentering: {
  235. alignItems: 'center',
  236. },
  237. Merge: { flexDirection: "row" },
  238.  
  239. containerImage: {
  240.  
  241. backgroundColor: "#FFA41B",
  242. justifyContent: 'center',
  243. alignItems: 'center',
  244.  
  245. },
  246. backgrondImage: {
  247. backgroundColor: "#FFA41B",
  248. height: 990
  249. },
  250. BorddererText:
  251. {
  252. color: 'gray',
  253. textAlign: 'left',
  254. fontSize: 18,
  255. marginRight: 10,
  256. marginLeft: 30,
  257. marginTop: 10,
  258. fontWeight: 'bold',
  259. },
  260. PickerStyleClass:
  261. {
  262. textAlign: 'center',
  263. backgroundColor: "#fff",
  264. marginBottom: 10,
  265. width: '60%',
  266. },
  267. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement