Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react';
- import {
- AppRegistry,
- AsyncStorage,
- Alert
- } from 'react-native';
- import {WebView, View} from 'react-native';
- export default class Loc extends Component {
- constructor (props) {
- super(props);
- this.onMessage = this.onMessage.bind(this);
- this.set = this.set.bind(this);
- this.getStorage = this.getStorage.bind(this);
- }
- getStorage() {
- let curData = {};
- console.log('GGGGGEEEETTTT__STTTTOOORRRAAAGGGEE');
- AsyncStorage.getAllKeys()
- .then((ks) => {
- ks.forEach((k) => {
- AsyncStorage.getItem(k)
- .then((v) => {
- curData[k] = v;
- console.log('Array***Currdata', JSON.stringify(curData));
- this.webview.postMessage(JSON.stringify(curData));
- return curData;
- })
- });
- });
- }
- set(key, value) {
- value = JSON.stringify(value);
- if (value) { return AsyncStorage.setItem(key, value) };
- }
- onMessage(data) {
- const parsedData = JSON.parse(data.nativeEvent.data);
- this.set(parsedData.payload.name, parsedData.payload.value);
- const postMsg = JSON.stringify(this.getStorage());
- }
- render () {
- return (
- <View style={{paddingTop: 20, flex: 1}}>
- <WebView
- ref={(e) => this.webview = e}
- source={{uri: 'https://xn--80acmlhv0b.xn--80aaaf6bgu1fb.xn--p1ai/'}}
- javaScriptEnabledAndroid={true}
- onMessage={this.onMessage}
- bounces={false}
- scalesPageToFit={false}
- />
- </View>
- );
- }
- }
- AppRegistry.registerComponent('Loc', () => Loc);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement