Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {
  3. AppRegistry,
  4. AsyncStorage,
  5. Alert
  6. } from 'react-native';
  7.  
  8. import {WebView, View} from 'react-native';
  9.  
  10. export default class Loc extends Component {
  11.  
  12. constructor (props) {
  13. super(props);
  14. this.onMessage = this.onMessage.bind(this);
  15. this.set = this.set.bind(this);
  16. this.getStorage = this.getStorage.bind(this);
  17. }
  18.  
  19. getStorage() {
  20. let curData = {};
  21. console.log('GGGGGEEEETTTT__STTTTOOORRRAAAGGGEE');
  22. AsyncStorage.getAllKeys()
  23. .then((ks) => {
  24. ks.forEach((k) => {
  25. AsyncStorage.getItem(k)
  26. .then((v) => {
  27. curData[k] = v;
  28. console.log('Array***Currdata', JSON.stringify(curData));
  29. this.webview.postMessage(JSON.stringify(curData));
  30. return curData;
  31. })
  32. });
  33. });
  34. }
  35.  
  36. set(key, value) {
  37. value = JSON.stringify(value);
  38. if (value) { return AsyncStorage.setItem(key, value) };
  39. }
  40.  
  41. onMessage(data) {
  42. const parsedData = JSON.parse(data.nativeEvent.data);
  43. this.set(parsedData.payload.name, parsedData.payload.value);
  44. const postMsg = JSON.stringify(this.getStorage());
  45. }
  46.  
  47. render () {
  48. return (
  49. <View style={{paddingTop: 20, flex: 1}}>
  50. <WebView
  51. ref={(e) => this.webview = e}
  52. source={{uri: 'https://xn--80acmlhv0b.xn--80aaaf6bgu1fb.xn--p1ai/'}}
  53. javaScriptEnabledAndroid={true}
  54. onMessage={this.onMessage}
  55. bounces={false}
  56. scalesPageToFit={false}
  57. />
  58. </View>
  59. );
  60. }
  61. }
  62.  
  63. AppRegistry.registerComponent('Loc', () => Loc);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement