Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.53 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {ScrollView, Text, StyleSheet, View, Modal, TouchableHighlight, AsyncStorage} from 'react-native';
  3. import DeviceInfo from 'react-native-device-info'
  4. import Accordion from 'react-native-collapsible/Accordion';
  5. import * as Animatable from 'react-native-animatable';
  6. import FitImage from 'react-native-fit-image';
  7. import {Header, Icon} from 'react-native-elements'
  8.  
  9. var services = require('../assets/service.json');
  10. //
  11. // var SECTIONS = [
  12. // {
  13. // title: 'Netflix',
  14. // nom: 'DELIGNIERES',
  15. // prenom: 'Matthieu',
  16. // sexe: 'Homme',
  17. // ville: 'Anzin',
  18. // isAbo: 'true',
  19. // durationAbo: '6 mois',
  20. // hasNews: 'false',
  21. // image: 'https://img3.telestar.fr/var/telestar/storage/images/3/0/5/6/3056045/netflix-annonce-des-projets-france_width1024.png'
  22. // },
  23. // {
  24. // title: 'Allocine',
  25. // nom: 'HUBLARD',
  26. // prenom: 'Grobin',
  27. // sexe: 'Male',
  28. // ville: 'Campagne',
  29. // isAbo: 'true',
  30. // durationAbo: '3 mois',
  31. // hasNews: 'true',
  32. // image: 'http://www.business-actor.com/wp-content/uploads/2013/07/logo-allocine.png'
  33. // },
  34. // {
  35. // title: 'Brazzer',
  36. // nom: 'Sabadini',
  37. // prenom: 'Jerome',
  38. // sexe: 'Homme',
  39. // ville: 'Valenciennes',
  40. // isAbo: 'true',
  41. // durationAbo: 'A vie',
  42. // hasNews: 'true',
  43. // image: 'https://i.redd.it/9nfas2kg75py.png'
  44. // },
  45. // {
  46. // title: 'Spotify',
  47. // nom: 'LEBRUM',
  48. // prenom: 'Audrey',
  49. // sexe: 'Femme',
  50. // ville: 'Famars',
  51. // isAbo: 'false',
  52. // durationAbo: '',
  53. // hasNews: 'false',
  54. // image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Spotify_logo_with_text.svg/2000px-Spotify_logo_with_text.svg.png'
  55. // }
  56. // ];
  57.  
  58. const styles = StyleSheet.create({
  59. fitImage: {
  60. borderRadius: 20,
  61. },
  62. container: {
  63. flex: 1,
  64. justifyContent: 'center',
  65. backgroundColor: '#F5FCFF',
  66. },
  67. title: {
  68. textAlign: 'center',
  69. fontSize: 22,
  70. fontWeight: '300',
  71. marginBottom: 20,
  72. },
  73. header: {
  74. backgroundColor: '#F5FCFF',
  75. padding: 10,
  76. },
  77. headerText: {
  78. textAlign: 'center',
  79. fontSize: 16,
  80. fontWeight: '500',
  81. },
  82. content: {
  83. padding: 20,
  84. backgroundColor: '#fff',
  85. },
  86. active: {
  87. backgroundColor: 'rgba(255,255,255,1)',
  88. },
  89. inactive: {
  90. backgroundColor: 'rgba(245,252,255,1)',
  91. },
  92. selectors: {
  93. marginBottom: 10,
  94. flexDirection: 'row',
  95. justifyContent: 'center',
  96. },
  97. selector: {
  98. backgroundColor: '#F5FCFF',
  99. padding: 10,
  100. },
  101. activeSelector: {
  102. fontWeight: 'bold',
  103. },
  104. selectTitle: {
  105. fontSize: 14,
  106. fontWeight: '500',
  107. padding: 10,
  108. },
  109. });
  110. var update = require('react-addons-update');
  111.  
  112. class ResultScreen extends Component {
  113.  
  114. state = {
  115. modalVisible: false,
  116. };
  117. static navigationOptions = {
  118. header: () => null,
  119. };
  120.  
  121. setModalVisible(visible) {
  122. this.setState({modalVisible: visible});
  123. }
  124.  
  125. json = {};
  126. SECTIONS = [];
  127.  
  128. constructor(props) {
  129. super(props);
  130. this.setModalVisible = this.setModalVisible.bind(this);
  131. this.updateState = this.updateState.bind(this);
  132. this._renderContent = this._renderContent.bind(this)
  133. this._renderHeader = this._renderHeader.bind(this);
  134. this.render = this.render.bind(this);
  135. this.json = {};
  136. this.SECTIONS = [];
  137. this._parseStorage();
  138. }
  139.  
  140. updateState(infoName) {
  141. let newState = {};
  142. let scope = this;
  143. return function (value) {
  144. newState[infoName] = scope.state[infoName];
  145. newState[infoName].value = value;
  146. scope.setState(function () {
  147. return update(scope.state, {$merge: newState}
  148. )
  149. });
  150. }
  151. }
  152.  
  153. _renderHeader(section, index, isActive, sections) {
  154. return (
  155. <Animatable.View
  156. duration={300}
  157. transition="backgroundColor"
  158. style={{backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)')}}>
  159. {/*<FitImage*/}
  160. {/*source={{uri: section.image}}*/}
  161. {/*style={styles.fitImage}*/}
  162. {/*/>*/}
  163. <Text style={styles.headerText}>TITRE</Text>
  164. </Animatable.View>
  165. );
  166. }
  167.  
  168. _renderContent(section, i, isActive, sections) {
  169. // let message = "";
  170. // console.error(section);
  171. // for(var l = 0; l < section.length; l++){
  172. // message.append(section[i]+"\n");
  173. // }
  174.  
  175. return (
  176. <Animatable.View
  177. duration={300}
  178. transition="backgroundColor"
  179. style={{backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)')}}>
  180. <Animatable.Text
  181. duration={300}
  182. easing="ease-out"
  183. >
  184. <Text>test</Text>
  185. </Animatable.Text>
  186. </Animatable.View>
  187. );
  188. }
  189.  
  190. _parseStorage(){
  191. let scope = this;
  192. AsyncStorage.getItem('AwesomeProjectStorage').then(function (data) {
  193. scope.json = JSON.parse(data);
  194.  
  195. let numberOfServices = Object.keys(scope.json).length;
  196. for(let index = 0; index < numberOfServices; index++){
  197. let service = scope.json[Object.keys(scope.json)[index]];
  198. scope.SECTIONS.push(service);
  199. //let numberOfElementsInThisService = Object.keys(this.service).length;
  200. }
  201.  
  202. // console.error(numberOfElementsInThisService);
  203. // let js2 = Object.keys(service[0]);
  204. // console.error(service[0][js2[0]]);
  205. // // console.error(js+" \n "+this.json[js]+"\n")
  206. // console.error("!data: " + this.json);
  207. scope.forceUpdate();
  208. });
  209. }
  210.  
  211. render() {
  212. // if(this.json == null){
  213. // this.json=[];
  214. // }
  215. if(this.SECTIONS == null){
  216. this._parseStorage();
  217. }
  218. return (
  219. <ScrollView>
  220. <View style={{backgroundColor: 'white'}}>
  221. <Header
  222. centerComponent={{text: "Les résultats", style: {color: 'tomato'}}}
  223. rightComponent={
  224. <Icon
  225. name="extension"
  226. color='tomato'
  227. onPress={() => {
  228. this.setModalVisible(!this.state.modalVisible);
  229. }}
  230. underlayColor={'#64b5f6'}
  231. />
  232. }
  233. outerContainerStyles={{height: 50}}
  234. innerContainerStyles={{height: 50}}
  235. backgroundColor="white"
  236. />
  237. <Modal
  238. style={{
  239. position: 'relative',
  240. padding: 30
  241. }}
  242. animationType="slide"
  243. transparent={false}
  244. visible={this.state.modalVisible}
  245. onRequestClose={() => {
  246. alert('Modal has been closed.');
  247. }}>
  248. <Text style={{
  249. fontSize: 20,
  250. marginBottom: 10,
  251. marginLeft: 10,
  252. marginTop: 10,
  253. }}>Données du téléphone</Text>
  254.  
  255. <Text style={{
  256. marginLeft: 10
  257. }}>Marque : {DeviceInfo.getBrand()}</Text>
  258. <Text style={{
  259. marginLeft: 10
  260. }}>Nom du device : {DeviceInfo.getDeviceName()}</Text>
  261. <Text style={{
  262. marginLeft: 10
  263. }}>Fournisseur : {DeviceInfo.getManufacturer()}</Text>
  264. <Text style={{
  265. marginLeft: 10
  266. }}>Numéro de Téléphone : {DeviceInfo.getPhoneNumber()}</Text>
  267. <Text style={{
  268. marginLeft: 10
  269. }}>Mémoire max autorisé(en bytes): {DeviceInfo.getMaxMemory()}</Text>
  270. <Text style={{
  271. marginLeft: 10
  272. }}>Mémoire Total (en bytes): {DeviceInfo.getTotalMemory()}</Text>
  273. <Text style={{
  274. marginLeft: 10
  275. }}>Stockage total (en bytes): {DeviceInfo.getTotalDiskCapacity()}</Text>
  276.  
  277. <TouchableHighlight
  278. onPress={() => {
  279. this.setModalVisible(!this.state.modalVisible);
  280. }} style={{
  281. position: 'absolute',
  282. top: 10,
  283. right: 10
  284. }}>
  285. <Icon
  286. name="close"
  287. color='tomato'
  288. onPress={() => {
  289. this.setModalVisible(!this.state.modalVisible);
  290. }}
  291. style={{
  292. fontSize: 50,
  293.  
  294. }}
  295. underlayColor={'#64b5f6'}
  296. />
  297. </TouchableHighlight>
  298. </Modal>
  299. </View>
  300. <ScrollView>
  301. <Accordion
  302. sections={this.SECTIONS}
  303. renderHeader={this._renderHeader}
  304. renderContent={this._renderContent}
  305. />
  306. </ScrollView>
  307. </ScrollView>
  308. );
  309. }
  310. }
  311.  
  312. export default ResultScreen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement