-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPage.js
80 lines (67 loc) · 2.38 KB
/
Page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import {StyleSheet, ScrollView, Keyboard, KeyboardAvoidingView} from 'react-native';
import FastoshWebView from "./FastoshWebView";
class Page extends React.Component {
constructor(props) {
super(props);
this.state = {
stack: [],
initialRoute: `https://max-webview.fastoche.fr${this.props.url}`
}
this.onMessage = this.onMessage.bind(this)
this._keyboardDidHide = this._keyboardDidHide.bind(this)
this._keyboardDidShow = this._keyboardDidShow.bind(this)
}
componentDidMount () {
console.log('mounted', this.state.initialRoute)
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
}
componentWillUnmount () {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidShow (e) {
this.child.sendPostMessage({type: 'keyboard', action: 'KEYBOARD_DID_SHOW', payload: {keyboardHeight: e.endCoordinates.height}})
}
_keyboardDidHide () {
this.child.sendPostMessage({type: 'keyboard', action: 'KEYBOARD_DID_HIDE'})
}
onMessage = (event) => {
console.log(event)
var parsedEvent = null;
try {
parsedEvent = JSON.parse(event.nativeEvent.data)
console.log('On Message', parsedEvent);
console.log(this.state.stack)
this.setState({stack: [...this.state.stack, JSON.parse(event.nativeEvent.data)]})
} catch(e) {
console.log(e.message)
}
}
sendPostMessage = (data) => {
this.child.sendPostMessage(data);
}
render() {
return (
<ScrollView contentContainerStyle={styles.container}>
{this.props.children}
<FastoshWebView
ref={ref => this.child = ref}
onMessage={this.onMessage}
uri={this.state.initialRoute}
/>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: 40,
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default Page;