@haroldtran/react-native-modals 0.0.4 → 0.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haroldtran/react-native-modals",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "React Native Modals Library for IOS & Android.",
5
5
  "main": "/src/index.tsx",
6
6
  "scripts": {
@@ -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
- StyleSheet.absoluteFill,
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";
@@ -90,6 +84,12 @@ class BaseModal extends Component<ModalProps, State> {
90
84
  onSwipeRelease: () => {},
91
85
  onSwipingOut: () => {},
92
86
  useNativeDriver: true,
87
+ useBlurView: false,
88
+ blurProps: {
89
+ blurType: "extraDark",
90
+ blurAmount: 20,
91
+ reducedTransparencyFallbackColor: "#000000",
92
+ },
93
93
  };
94
94
 
95
95
  constructor(props: ModalProps) {
@@ -142,8 +142,7 @@ class BaseModal extends Component<ModalProps, State> {
142
142
  }
143
143
 
144
144
  get modalSize(): any {
145
- const { width: screenWidth, height: screenHeight } =
146
- Dimensions.get("window");
145
+ const { width: screenWidth, height: screenHeight } = Dimensions.get("window");
147
146
  let { width, height } = this.props;
148
147
  if (width && width > 0.0 && width <= 1.0) {
149
148
  width *= screenWidth;
@@ -187,15 +186,11 @@ class BaseModal extends Component<ModalProps, State> {
187
186
  if (Math.abs(event.axis.y)) {
188
187
  const lastAxis = Math.abs(this.lastSwipeEvent.layout.y);
189
188
  const currAxis = Math.abs(event.axis.y);
190
- newOpacity =
191
- opacity -
192
- (opacity * currAxis) / (Dimensions.get("window").height - lastAxis);
189
+ newOpacity = opacity - (opacity * currAxis) / (Dimensions.get("window").height - lastAxis);
193
190
  } else {
194
191
  const lastAxis = Math.abs(this.lastSwipeEvent.layout.x);
195
192
  const currAxis = Math.abs(event.axis.x);
196
- newOpacity =
197
- opacity -
198
- (opacity * currAxis) / (Dimensions.get("window").width - lastAxis);
193
+ newOpacity = opacity - (opacity * currAxis) / (Dimensions.get("window").width - lastAxis);
199
194
  }
200
195
  this.backdrop?.setOpacity(newOpacity);
201
196
  };
@@ -225,10 +220,11 @@ class BaseModal extends Component<ModalProps, State> {
225
220
  onSwipeOut,
226
221
  swipeDirection,
227
222
  swipeThreshold,
223
+ useBlurView,
224
+ blurProps,
228
225
  } = this.props;
229
226
 
230
- const overlayVisible =
231
- hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState);
227
+ const overlayVisible = hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState);
232
228
  const round = rounded ? styles.round : null;
233
229
  const hidden = modalState === MODAL_CLOSED && styles.hidden;
234
230
 
@@ -266,6 +262,8 @@ class BaseModal extends Component<ModalProps, State> {
266
262
  opacity={overlayOpacity}
267
263
  animationDuration={animationDuration}
268
264
  useNativeDriver={useNativeDriver}
265
+ useBlurView={useBlurView}
266
+ blurProps={blurProps}
269
267
  />
270
268
  <Animated.View style={pan.getLayout()} onLayout={onLayout}>
271
269
  <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,8 @@ export type ModalProps = {
59
60
  swipeDirection?: SwipeDirection | Array<SwipeDirection>;
60
61
  swipeThreshold?: number;
61
62
  useNativeDriver?: boolean;
63
+ useBlurView?: boolean;
64
+ blurProps?: BlurViewProps;
62
65
  };
63
66
 
64
67
  export type ModalFooterProps = {
@@ -99,4 +102,6 @@ export type BackdropProps = {
99
102
  animationDuration?: number;
100
103
  pointerEvents?: "auto" | "none" | "box-none" | "box-only";
101
104
  useNativeDriver?: boolean;
105
+ blurProps?: BlurViewProps;
106
+ useBlurView?: boolean;
102
107
  };