-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathindex.js
114 lines (110 loc) · 2.87 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
View,
Platform,
NativeModules,
requireNativeComponent,
StyleSheet,
TouchableWithoutFeedback,
Animated,
} from 'react-native'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
var emitter = require('tiny-emitter/instance')
const { SajjadBlurOverlay } = NativeModules
var iface = {
name: 'BlurView',
propTypes: {
...View.propTypes,
brightness: PropTypes.any,
radius: PropTypes.number,
downsampling: PropTypes.number,
blurStyle: PropTypes.string,
vibrant: PropTypes.bool,
idBlur: PropTypes.string,
},
}
var RCTSajjadBlurOverlay = Platform.select({
ios: () => requireNativeComponent('SajjadBlurOverlay', iface),
android: () => requireNativeComponent('RCTSajjadBlurOverlay', iface),
})()
export default class BlurOverlay extends React.Component {
constructor(props) {
super(props)
this.state = {
showBlurOverlay: false,
fadeIn: new Animated.Value(0),
}
this._openOverlay = this.openOverlay.bind(this)
this._closeOverlay = this.closeOverlay.bind(this)
}
openOverlay() {
this.setState(
{
showBlurOverlay: true,
fadeIn: new Animated.Value(0),
},
() => {
Animated.timing(this.state.fadeIn, {
toValue: 1,
duration: 500,
useNativeDriver: true,
}).start()
}
)
}
closeOverlay() {
Animated.timing(this.state.fadeIn, {
toValue: 0,
duration: 500,
useNativeDriver: true,
}).start(() => this.setState({ showBlurOverlay: false }))
}
componentDidMount() {
emitter.on('drawer-open' + this.props.idBlur, this._openOverlay)
emitter.on('drawer-close' + this.props.idBlur, this._closeOverlay)
}
componentWillUnmount() {
emitter.off('drawer-open' + this.props.idBlur, this._openOverlay)
emitter.off('drawer-close' + this.props.idBlur, this._closeOverlay)
}
render() {
const { children } = this.props
return this.state.showBlurOverlay ? (
<Animated.View style={[{ opacity: this.state.fadeIn }, styles.style]}>
<TouchableWithoutFeedback
style={styles.style}
onPress={this.props.onPress}
>
<RCTSajjadBlurOverlay
{...this.props}
style={[this.props.customStyles, styles.style]}
>
<View style={[this.props.customStyles, styles.style]}>
{children}
</View>
</RCTSajjadBlurOverlay>
</TouchableWithoutFeedback>
</Animated.View>
) : null
}
}
const styles = StyleSheet.create({
style: {
position: 'absolute',
flex: 1,
left: 0,
top: 0,
bottom: 0,
right: 0,
// resizeMode: 'cover',
width: null,
height: null,
zIndex: 999,
},
})
export function openOverlay(idBlur) {
emitter.emit('drawer-open' + idBlur)
}
export function closeOverlay(idBlur) {
emitter.emit('drawer-close' + idBlur)
}