@haroldtran/react-native-modals 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/components/Backdrop.tsx +18 -12
- package/src/components/BaseModal.tsx +23 -42
- package/src/type.ts +6 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haroldtran/react-native-modals",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "React Native Modals Library for IOS & Android.",
|
|
5
5
|
"main": "/src/index.tsx",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
|
-
"prebuild": "
|
|
8
|
+
"prebuild": "bun install && tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"src"
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"homepage": "https://github.com/phattran1201/react-native-modals",
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@sbaiahmed1/react-native-blur": "^4.4.1",
|
|
40
41
|
"babel-plugin-flow-react-proptypes": "^9.1.1",
|
|
41
42
|
"prop-types": "^15.6.0"
|
|
42
43
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
+
import { BlurView } from "@sbaiahmed1/react-native-blur";
|
|
3
4
|
import React, { Component } from "react";
|
|
4
5
|
import { Animated, StyleSheet, TouchableOpacity } from "react-native";
|
|
5
6
|
import { BackdropProps } from "../type";
|
|
@@ -11,18 +12,19 @@ export default class Backdrop extends Component<BackdropProps> {
|
|
|
11
12
|
animationDuration: 200,
|
|
12
13
|
visible: false,
|
|
13
14
|
useNativeDriver: true,
|
|
15
|
+
useBlurView: false,
|
|
14
16
|
onPress: () => {},
|
|
17
|
+
blurProps: {
|
|
18
|
+
blurType: "extraDark",
|
|
19
|
+
blurAmount: 20,
|
|
20
|
+
reducedTransparencyFallbackColor: "#000000",
|
|
21
|
+
},
|
|
15
22
|
};
|
|
16
23
|
|
|
17
24
|
opacity = new Animated.Value(0);
|
|
18
25
|
|
|
19
26
|
componentDidUpdate(prevProps: BackdropProps) {
|
|
20
|
-
const {
|
|
21
|
-
visible,
|
|
22
|
-
useNativeDriver = true,
|
|
23
|
-
opacity: toOpacity = 0.5,
|
|
24
|
-
animationDuration: duration = 200,
|
|
25
|
-
} = this.props;
|
|
27
|
+
const { visible, useNativeDriver = true, opacity: toOpacity = 0.5, animationDuration: duration = 200 } = this.props;
|
|
26
28
|
if (prevProps.visible !== visible) {
|
|
27
29
|
const toValue = visible ? toOpacity : 0;
|
|
28
30
|
Animated.timing(this.opacity, {
|
|
@@ -38,16 +40,20 @@ export default class Backdrop extends Component<BackdropProps> {
|
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
render() {
|
|
41
|
-
const { onPress, pointerEvents, backgroundColor } = this.props;
|
|
43
|
+
const { onPress, pointerEvents, backgroundColor, useBlurView, blurProps } = this.props;
|
|
42
44
|
const { opacity } = this;
|
|
43
|
-
const overlayStyle: any = [
|
|
44
|
-
|
|
45
|
-
{ backgroundColor, opacity },
|
|
46
|
-
];
|
|
47
|
-
return (
|
|
45
|
+
const overlayStyle: any = [StyleSheet.absoluteFill, { backgroundColor, opacity }];
|
|
46
|
+
const _children = (
|
|
48
47
|
<Animated.View pointerEvents={pointerEvents as any} style={overlayStyle}>
|
|
49
48
|
<TouchableOpacity onPress={onPress} style={StyleSheet.absoluteFill} />
|
|
50
49
|
</Animated.View>
|
|
51
50
|
);
|
|
51
|
+
return useBlurView ? (
|
|
52
|
+
<BlurView {...blurProps} style={StyleSheet.absoluteFill}>
|
|
53
|
+
{_children}
|
|
54
|
+
</BlurView>
|
|
55
|
+
) : (
|
|
56
|
+
_children
|
|
57
|
+
);
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import React, { Component, Fragment } from "react";
|
|
2
|
-
import {
|
|
3
|
-
Animated,
|
|
4
|
-
BackHandler,
|
|
5
|
-
Dimensions,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
View,
|
|
8
|
-
} from "react-native";
|
|
2
|
+
import { Animated, BackHandler, Dimensions, StyleSheet, View } from "react-native";
|
|
9
3
|
|
|
10
4
|
import Animation from "../animations/Animation";
|
|
11
5
|
import FadeAnimation from "../animations/FadeAnimation";
|
|
@@ -49,11 +43,7 @@ const styles = StyleSheet.create({
|
|
|
49
43
|
},
|
|
50
44
|
});
|
|
51
45
|
|
|
52
|
-
type ModalState =
|
|
53
|
-
| typeof MODAL_OPENING
|
|
54
|
-
| typeof MODAL_OPENED
|
|
55
|
-
| typeof MODAL_CLOSING
|
|
56
|
-
| typeof MODAL_CLOSED;
|
|
46
|
+
type ModalState = typeof MODAL_OPENING | typeof MODAL_OPENED | typeof MODAL_CLOSING | typeof MODAL_CLOSED;
|
|
57
47
|
|
|
58
48
|
type State = {
|
|
59
49
|
modalAnimation: Animation;
|
|
@@ -90,6 +80,13 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
90
80
|
onSwipeRelease: () => {},
|
|
91
81
|
onSwipingOut: () => {},
|
|
92
82
|
useNativeDriver: true,
|
|
83
|
+
useBlurView: false,
|
|
84
|
+
isDelay: false,
|
|
85
|
+
blurProps: {
|
|
86
|
+
blurType: "extraDark",
|
|
87
|
+
blurAmount: 20,
|
|
88
|
+
reducedTransparencyFallbackColor: "#000000",
|
|
89
|
+
},
|
|
93
90
|
};
|
|
94
91
|
|
|
95
92
|
constructor(props: ModalProps) {
|
|
@@ -109,10 +106,7 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
109
106
|
if (this.props.visible) {
|
|
110
107
|
this.show();
|
|
111
108
|
}
|
|
112
|
-
this.backHandler = BackHandler.addEventListener(
|
|
113
|
-
HARDWARE_BACK_PRESS_EVENT,
|
|
114
|
-
this.onHardwareBackPress,
|
|
115
|
-
);
|
|
109
|
+
this.backHandler = BackHandler.addEventListener(HARDWARE_BACK_PRESS_EVENT, this.onHardwareBackPress);
|
|
116
110
|
}
|
|
117
111
|
|
|
118
112
|
componentDidUpdate(prevProps: ModalProps) {
|
|
@@ -129,8 +123,7 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
129
123
|
this.backHandler?.remove();
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
onHardwareBackPress = (): boolean =>
|
|
133
|
-
this.props.onHardwareBackPress ? this.props.onHardwareBackPress() : false;
|
|
126
|
+
onHardwareBackPress = (): boolean => (this.props.onHardwareBackPress ? this.props.onHardwareBackPress() : false);
|
|
134
127
|
|
|
135
128
|
get pointerEvents(): "auto" | "none" {
|
|
136
129
|
const { overlayPointerEvents } = this.props;
|
|
@@ -142,8 +135,7 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
142
135
|
}
|
|
143
136
|
|
|
144
137
|
get modalSize(): any {
|
|
145
|
-
const { width: screenWidth, height: screenHeight } =
|
|
146
|
-
Dimensions.get("window");
|
|
138
|
+
const { width: screenWidth, height: screenHeight } = Dimensions.get("window");
|
|
147
139
|
let { width, height } = this.props;
|
|
148
140
|
if (width && width > 0.0 && width <= 1.0) {
|
|
149
141
|
width *= screenWidth;
|
|
@@ -187,15 +179,11 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
187
179
|
if (Math.abs(event.axis.y)) {
|
|
188
180
|
const lastAxis = Math.abs(this.lastSwipeEvent.layout.y);
|
|
189
181
|
const currAxis = Math.abs(event.axis.y);
|
|
190
|
-
newOpacity =
|
|
191
|
-
opacity -
|
|
192
|
-
(opacity * currAxis) / (Dimensions.get("window").height - lastAxis);
|
|
182
|
+
newOpacity = opacity - (opacity * currAxis) / (Dimensions.get("window").height - lastAxis);
|
|
193
183
|
} else {
|
|
194
184
|
const lastAxis = Math.abs(this.lastSwipeEvent.layout.x);
|
|
195
185
|
const currAxis = Math.abs(event.axis.x);
|
|
196
|
-
newOpacity =
|
|
197
|
-
opacity -
|
|
198
|
-
(opacity * currAxis) / (Dimensions.get("window").width - lastAxis);
|
|
186
|
+
newOpacity = opacity - (opacity * currAxis) / (Dimensions.get("window").width - lastAxis);
|
|
199
187
|
}
|
|
200
188
|
this.backdrop?.setOpacity(newOpacity);
|
|
201
189
|
};
|
|
@@ -225,10 +213,12 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
225
213
|
onSwipeOut,
|
|
226
214
|
swipeDirection,
|
|
227
215
|
swipeThreshold,
|
|
216
|
+
useBlurView,
|
|
217
|
+
blurProps,
|
|
218
|
+
isDelay,
|
|
228
219
|
} = this.props;
|
|
229
220
|
|
|
230
|
-
const overlayVisible =
|
|
231
|
-
hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState);
|
|
221
|
+
const overlayVisible = hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState);
|
|
232
222
|
const round = rounded ? styles.round : null;
|
|
233
223
|
const hidden = modalState === MODAL_CLOSED && styles.hidden;
|
|
234
224
|
|
|
@@ -239,10 +229,7 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
239
229
|
hasFooter: Boolean(footer),
|
|
240
230
|
}}
|
|
241
231
|
>
|
|
242
|
-
<View
|
|
243
|
-
pointerEvents={this.isSwipingOut ? "none" : "auto"}
|
|
244
|
-
style={[styles.container, hidden]}
|
|
245
|
-
>
|
|
232
|
+
<View pointerEvents={this.isSwipingOut ? "none" : "auto"} style={[styles.container, hidden]}>
|
|
246
233
|
<DraggableView
|
|
247
234
|
style={StyleSheet.flatten([styles.draggableView, style])}
|
|
248
235
|
onMove={this.handleMove}
|
|
@@ -266,19 +253,13 @@ class BaseModal extends Component<ModalProps, State> {
|
|
|
266
253
|
opacity={overlayOpacity}
|
|
267
254
|
animationDuration={animationDuration}
|
|
268
255
|
useNativeDriver={useNativeDriver}
|
|
256
|
+
useBlurView={useBlurView}
|
|
257
|
+
blurProps={blurProps}
|
|
269
258
|
/>
|
|
270
259
|
<Animated.View style={pan.getLayout()} onLayout={onLayout}>
|
|
271
|
-
<Animated.View
|
|
272
|
-
style={[
|
|
273
|
-
styles.modal,
|
|
274
|
-
round,
|
|
275
|
-
this.modalSize,
|
|
276
|
-
modalStyle,
|
|
277
|
-
modalAnimation.getAnimations(),
|
|
278
|
-
]}
|
|
279
|
-
>
|
|
260
|
+
<Animated.View style={[styles.modal, round, this.modalSize, modalStyle, modalAnimation.getAnimations()]}>
|
|
280
261
|
{modalTitle}
|
|
281
|
-
{modalState === MODAL_OPENED
|
|
262
|
+
{isDelay ? (modalState === MODAL_OPENED ? children : null) : children}
|
|
282
263
|
{footer}
|
|
283
264
|
</Animated.View>
|
|
284
265
|
</Animated.View>
|
package/src/type.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// TypeScript types for the library
|
|
2
2
|
|
|
3
|
+
import { BlurViewProps } from "@sbaiahmed1/react-native-blur";
|
|
3
4
|
import { ReactNode } from "react";
|
|
4
5
|
import Animation from "./animations/Animation";
|
|
5
6
|
|
|
@@ -59,6 +60,9 @@ export type ModalProps = {
|
|
|
59
60
|
swipeDirection?: SwipeDirection | Array<SwipeDirection>;
|
|
60
61
|
swipeThreshold?: number;
|
|
61
62
|
useNativeDriver?: boolean;
|
|
63
|
+
useBlurView?: boolean;
|
|
64
|
+
blurProps?: BlurViewProps;
|
|
65
|
+
isDelay?: boolean;
|
|
62
66
|
};
|
|
63
67
|
|
|
64
68
|
export type ModalFooterProps = {
|
|
@@ -99,4 +103,6 @@ export type BackdropProps = {
|
|
|
99
103
|
animationDuration?: number;
|
|
100
104
|
pointerEvents?: "auto" | "none" | "box-none" | "box-only";
|
|
101
105
|
useNativeDriver?: boolean;
|
|
106
|
+
blurProps?: BlurViewProps;
|
|
107
|
+
useBlurView?: boolean;
|
|
102
108
|
};
|