forked from Anthonyzou/react-native-full-screen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (45 loc) · 1.1 KB
/
index.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
import React, {
Component,
} from 'react';
import {
NativeModules,
View,
TouchableWithoutFeedback,
} from 'react-native';
const FullScreen = NativeModules.FullScreen
export default FullScreen;
import debounce from 'debounce';
export class ToggleView extends Component {
constructor(props,context){
super(props,context)
this.state = {
focus:this.props.focus||true
}
this.offFullScreen = debounce(FullScreen.offFullScreen,250);
this.delayHide = debounce(() => {
FullScreen.onFullScreen();
this.setState({focus:false});
},this.props.delay || 3000);
}
handlePress (){
if(this.state.focus){
FullScreen.onFullScreen();
this.setState({focus:!this.state.focus})
}
else {
this.offFullScreen();
if(this.props.delayHide !== false)
this.delayHide();
}
}
render() {
return (
<TouchableWithoutFeedback
onPress={this.handlePress.bind(this)}>
<View style={this.props.style}>
{React.Children.map(this.props.children, el=>el)}
</View>
</TouchableWithoutFeedback>
);
}
}