-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.sample.js
94 lines (73 loc) · 3.4 KB
/
index.sample.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Text, View, Button, TextInput, Alert, Modal } from 'react-native'
import { Immersive } from 'react-native-immersive'
class testReactNative extends Component {
constructor (props) {
super(props)
this.setImmersiveOn = () => {
Immersive.on()
this.setState({ isImmersive: true })
}
this.setImmersiveOff = () => {
Immersive.off()
this.setState({ isImmersive: false })
}
this.getImmersiveState = () => Immersive.getImmersive().then((immersiveState) => {
__DEV__ && console.warn('[getImmersiveState]', immersiveState)
this.setState({ immersiveState })
})
this.setRestoreImmersiveOn = () => this.setState({ isRestoreImmersive: true })
this.setRestoreImmersiveOff = () => this.setState({ isRestoreImmersive: false })
this.restoreImmersive = () => {
__DEV__ && console.warn('[restoreImmersive]', this.state.isRestoreImmersive)
this.state.isRestoreImmersive && Immersive.setImmersive(this.state.isImmersive)
}
this.showModal = () => this.setState({ isModal: true })
this.hideModal = () => this.setState({ isModal: false })
this.onTextChange = (text) => this.setState({ text })
this.showAlert = () => Alert.alert('Alert Title', 'Alert Messsag')
this.state = {
isImmersive: false,
isRestoreImmersive: true,
immersiveState: null,
isModal: false,
text: 'test'
}
}
componentDidMount () { Immersive.addImmersiveListener(this.restoreImmersive) }
componentWillUnmount () { Immersive.removeImmersiveListener(this.restoreImmersive) }
renderTest () {
const { isImmersive, isRestoreImmersive, isModal, immersiveState, text } = this.state
return <View style={styles.containerTest}>
<Button onPress={isImmersive ? this.setImmersiveOff : this.setImmersiveOn} title="toggle isImmersive" />
<Text style={styles.text}>isImmersive: {JSON.stringify(isImmersive)}</Text>
<Button onPress={isRestoreImmersive ? this.setRestoreImmersiveOff : this.setRestoreImmersiveOn} title="toggle isRestoreImmersive" />
<Text style={styles.text}>isRestoreImmersive: {JSON.stringify(isRestoreImmersive)}</Text>
<Button onPress={this.getImmersiveState} title="get immersiveState" />
<Text style={styles.text}>immersiveState: {JSON.stringify(immersiveState)}</Text>
<Button onPress={isModal ? this.hideModal : this.showModal} title="toggle isModal" />
<Text style={styles.text}>isModal: {JSON.stringify(isModal)}</Text>
<Button onPress={this.showAlert} title="pop Alert" />
<TextInput value={text} onChangeText={this.onTextChange} />
</View>
}
render () {
const { isModal } = this.state
return <View style={styles.container}>
<Text style={styles.text}>Welcome to React Native!</Text>
{this.renderTest()}
<Text style={styles.text}>Welcome to React Native!</Text>
<Modal animationType="slide" visible={isModal} onRequestClose={this.hideModal}>
<Text style={styles.text}>Modal!</Text>
{this.renderTest()}
<Text style={styles.text}>Modal!</Text>
</Modal>
</View>
}
}
const styles = StyleSheet.create({
container: { flex: 1, padding: 24 },
containerTest: { alignItems: 'stretch', justifyContent: 'center', flex: 1 },
text: { textAlign: 'center', fontSize: 14 }
})
AppRegistry.registerComponent('testReactNative', () => testReactNative)