-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.tsx
118 lines (100 loc) · 3.2 KB
/
index.tsx
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
115
116
117
118
import React, { useRef, useEffect, useState, useCallback } from 'react';
import {
View,
Platform,
NativeModules,
requireNativeComponent,
StyleSheet,
TouchableWithoutFeedback,
Animated,
StyleProp,
ViewStyle,
} from 'react-native';
import { EventEmitter } from 'events';
const emitter = new EventEmitter();
type BlurOverlayProps = {
brightness?: number;
radius?: number;
downsampling?: number;
blurStyle?: 'light' | 'dark' | 'extraLight'; // Define possible values if known
vibrant?: boolean;
idBlur: string;
onPress?: () => void;
customStyles?: StyleProp<ViewStyle>;
children?: React.ReactNode;
};
console.log('Before.RCTSajjadBlurOverlay')
const RCTSajjadBlurOverlay = Platform.OS === 'ios'
? requireNativeComponent('SajjadBlurOverlay')
: requireNativeComponent('RCTSajjadBlurOverlay');
// const RCTSajjadBlurOverlay = requireNativeComponent('SajjadBlurOverlay');
console.log("RCTSajjadBlurOverlay:", RCTSajjadBlurOverlay);
const BlurOverlay: React.FC<BlurOverlayProps> = ({
idBlur,
onPress,
customStyles,
children,
...props
}) => {
const [showBlurOverlay, setShowBlurOverlay] = useState<boolean>(false);
const fadeIn = useRef(new Animated.Value(0)).current;
const openOverlay = useCallback(() => {
setShowBlurOverlay(true);
fadeIn.setValue(0);
Animated.timing(fadeIn, {
toValue: 1,
duration: 500,
useNativeDriver: true,
}).start();
}, [fadeIn]);
const closeOverlay = useCallback(() => {
Animated.timing(fadeIn, {
toValue: 0,
duration: 500,
useNativeDriver: true,
}).start(() => setShowBlurOverlay(false));
}, [fadeIn]);
useEffect(() => {
emitter.on(`drawer-open${idBlur}`, openOverlay);
emitter.on(`drawer-close${idBlur}`, closeOverlay);
return () => {
emitter.off(`drawer-open${idBlur}`, openOverlay);
emitter.off(`drawer-close${idBlur}`, closeOverlay);
};
}, [idBlur, openOverlay, closeOverlay]);
if (!showBlurOverlay) return null;
if (!RCTSajjadBlurOverlay) {
console.warn("BlurOverlay native module is not linked properly.");
return null;
}
return (
<Animated.View style={[{ opacity: fadeIn }, styles.style]}>
<TouchableWithoutFeedback onPress={onPress}>
<RCTSajjadBlurOverlay {...props} style={[customStyles, styles.style]}>
<View style={[customStyles, styles.style]}>{children}</View>
</RCTSajjadBlurOverlay>
</TouchableWithoutFeedback>
</Animated.View>
);
};
const styles = StyleSheet.create({
style: {
position: 'absolute',
flex: 1,
left: 0,
top: 0,
bottom: 0,
right: 0,
width: '100%',
height: '100%',
zIndex: 999,
},
});
// Functions to control overlay visibility externally
export function openOverlay(idBlur: string) {
emitter.emit(`drawer-open${idBlur}`);
}
export function closeOverlay(idBlur: string) {
emitter.emit(`drawer-close${idBlur}`);
}
export default BlurOverlay;