@haroldtran/react-native-modals 0.0.7 → 0.0.10
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 +41 -65
- package/src/BottomModal.tsx +1 -3
- package/src/Modal.tsx +4 -6
- package/src/ModalPortal.tsx +108 -75
- package/src/animations/Animation.tsx +10 -12
- package/src/animations/FadeAnimation.tsx +8 -18
- package/src/animations/ScaleAnimation.tsx +14 -7
- package/src/animations/SlideAnimation.tsx +35 -13
- package/src/components/Backdrop.tsx +40 -51
- package/src/components/BaseModal.tsx +265 -228
- package/src/components/BottomModal.tsx +23 -19
- package/src/components/DraggableView.tsx +192 -228
- package/src/components/ModalButton.tsx +15 -24
- package/src/components/ModalContent.tsx +4 -13
- package/src/components/ModalFooter.tsx +13 -24
- package/src/components/ModalTitle.tsx +11 -19
- package/src/index.tsx +14 -14
- package/src/type.ts +16 -16
- package/src/components/SlideAnimation.tsx +0 -91
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PixelRatio, Platform, StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import { Positions } from '../constants/Constants';
|
|
4
|
+
import type { ModalTitleProps } from '../type';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
import { PixelRatio, Platform, StyleSheet, Text, View } from "react-native";
|
|
5
|
-
import { Positions } from "../constants/Constants";
|
|
6
|
-
import type { ModalTitleProps } from "../type";
|
|
7
|
-
|
|
8
|
-
const isAndroid = Platform.OS === "android";
|
|
6
|
+
const isAndroid = Platform.OS === 'android';
|
|
9
7
|
|
|
10
8
|
const styles = StyleSheet.create({
|
|
11
9
|
title: {
|
|
@@ -16,24 +14,18 @@ const styles = StyleSheet.create({
|
|
|
16
14
|
},
|
|
17
15
|
titleBar: {
|
|
18
16
|
borderBottomWidth: 1 / PixelRatio.get(),
|
|
19
|
-
backgroundColor:
|
|
20
|
-
borderColor:
|
|
17
|
+
backgroundColor: '#F9F9FB',
|
|
18
|
+
borderColor: '#DAD9DC',
|
|
21
19
|
},
|
|
22
20
|
text: {
|
|
23
|
-
fontWeight: isAndroid ?
|
|
24
|
-
fontFamily: isAndroid ?
|
|
21
|
+
fontWeight: isAndroid ? '400' : '500',
|
|
22
|
+
fontFamily: isAndroid ? 'sans-serif-medium' : 'System',
|
|
25
23
|
fontSize: isAndroid ? 19 : 15,
|
|
26
|
-
color:
|
|
24
|
+
color: '#151822',
|
|
27
25
|
},
|
|
28
26
|
});
|
|
29
27
|
|
|
30
|
-
const ModalTitle = ({
|
|
31
|
-
title,
|
|
32
|
-
style,
|
|
33
|
-
textStyle,
|
|
34
|
-
hasTitleBar = true,
|
|
35
|
-
align = "center",
|
|
36
|
-
}: ModalTitleProps) => {
|
|
28
|
+
const ModalTitle = ({ title, style, textStyle, hasTitleBar = true, align = 'center' }: ModalTitleProps) => {
|
|
37
29
|
const titleBar = hasTitleBar ? styles.titleBar : null;
|
|
38
30
|
const titleAlign = { alignItems: Positions[align as keyof typeof Positions] };
|
|
39
31
|
|
package/src/index.tsx
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import Animation from
|
|
2
|
-
import FadeAnimation from
|
|
3
|
-
import ScaleAnimation from
|
|
4
|
-
import SlideAnimation from
|
|
5
|
-
import BottomModal from
|
|
6
|
-
import Backdrop from
|
|
7
|
-
import DraggableView from
|
|
8
|
-
import ModalButton from
|
|
9
|
-
import ModalContent from
|
|
10
|
-
import ModalFooter from
|
|
11
|
-
import ModalTitle from
|
|
12
|
-
import Modal from
|
|
13
|
-
import ModalPortal from
|
|
14
|
-
export * from
|
|
1
|
+
import Animation from './animations/Animation';
|
|
2
|
+
import FadeAnimation from './animations/FadeAnimation';
|
|
3
|
+
import ScaleAnimation from './animations/ScaleAnimation';
|
|
4
|
+
import SlideAnimation from './animations/SlideAnimation';
|
|
5
|
+
import BottomModal from './BottomModal';
|
|
6
|
+
import Backdrop from './components/Backdrop';
|
|
7
|
+
import DraggableView from './components/DraggableView';
|
|
8
|
+
import ModalButton from './components/ModalButton';
|
|
9
|
+
import ModalContent from './components/ModalContent';
|
|
10
|
+
import ModalFooter from './components/ModalFooter';
|
|
11
|
+
import ModalTitle from './components/ModalTitle';
|
|
12
|
+
import Modal from './Modal';
|
|
13
|
+
import ModalPortal from './ModalPortal';
|
|
14
|
+
export * from './type';
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
17
|
Animation,
|
package/src/type.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { BlurViewProps } from "@sbaiahmed1/react-native-blur";
|
|
4
|
-
import { ReactNode } from "react";
|
|
5
|
-
import Animation from "./animations/Animation";
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import Animation from './animations/Animation';
|
|
6
3
|
|
|
7
4
|
export type StackItem = ModalProps & {
|
|
8
5
|
key: string;
|
|
9
|
-
type?:
|
|
6
|
+
type?: 'modal' | 'bottomModal';
|
|
10
7
|
onDismiss?: () => void;
|
|
11
8
|
};
|
|
12
9
|
|
|
13
10
|
export type EmitModalPortal = {
|
|
14
|
-
type:
|
|
11
|
+
type: 'show' | 'update' | 'dismiss' | 'dismissAll';
|
|
15
12
|
key?: string;
|
|
16
13
|
stack: StackItem[];
|
|
17
14
|
};
|
|
18
15
|
|
|
19
|
-
export type SwipeDirection =
|
|
16
|
+
export type SwipeDirection = 'up' | 'down' | 'left' | 'right';
|
|
20
17
|
|
|
21
18
|
export type DragEvent = {
|
|
22
19
|
axis: {
|
|
@@ -39,14 +36,18 @@ export type ModalProps = {
|
|
|
39
36
|
height?: number;
|
|
40
37
|
rounded?: boolean;
|
|
41
38
|
hasOverlay?: boolean;
|
|
42
|
-
overlayPointerEvents?:
|
|
39
|
+
overlayPointerEvents?: 'auto' | 'none';
|
|
43
40
|
overlayBackgroundColor?: string;
|
|
44
41
|
overlayOpacity?: number;
|
|
42
|
+
overlayAnimationDelay?: number;
|
|
43
|
+
|
|
45
44
|
modalTitle?: any;
|
|
46
45
|
modalAnimation?: Animation;
|
|
47
46
|
modalStyle?: any;
|
|
48
47
|
style?: any;
|
|
49
48
|
animationDuration?: number;
|
|
49
|
+
animationDurationIn?: number;
|
|
50
|
+
animationDurationOut?: number;
|
|
50
51
|
onTouchOutside?: () => void;
|
|
51
52
|
onHardwareBackPress?: () => boolean;
|
|
52
53
|
onShow?: () => void;
|
|
@@ -60,9 +61,9 @@ export type ModalProps = {
|
|
|
60
61
|
swipeDirection?: SwipeDirection | Array<SwipeDirection>;
|
|
61
62
|
swipeThreshold?: number;
|
|
62
63
|
useNativeDriver?: boolean;
|
|
63
|
-
|
|
64
|
-
blurProps?: BlurViewProps;
|
|
64
|
+
|
|
65
65
|
isDelay?: boolean;
|
|
66
|
+
type?: 'modal' | 'bottomModal';
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
export type ModalFooterProps = {
|
|
@@ -74,7 +75,7 @@ export type ModalFooterProps = {
|
|
|
74
75
|
export type ModalButtonProps = {
|
|
75
76
|
text: string;
|
|
76
77
|
onPress?: () => void;
|
|
77
|
-
align?:
|
|
78
|
+
align?: 'left' | 'right' | 'center' | string;
|
|
78
79
|
style?: any;
|
|
79
80
|
textStyle?: any;
|
|
80
81
|
disabled?: boolean;
|
|
@@ -86,7 +87,7 @@ export type ModalTitleProps = {
|
|
|
86
87
|
title: any;
|
|
87
88
|
style?: any;
|
|
88
89
|
textStyle?: any;
|
|
89
|
-
align?:
|
|
90
|
+
align?: 'left' | 'right' | 'center' | string;
|
|
90
91
|
hasTitleBar?: boolean;
|
|
91
92
|
};
|
|
92
93
|
|
|
@@ -101,8 +102,7 @@ export type BackdropProps = {
|
|
|
101
102
|
onPress?: () => void;
|
|
102
103
|
backgroundColor?: string;
|
|
103
104
|
animationDuration?: number;
|
|
104
|
-
|
|
105
|
+
animationDelay?: number;
|
|
106
|
+
pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only';
|
|
105
107
|
useNativeDriver?: boolean;
|
|
106
|
-
blurProps?: BlurViewProps;
|
|
107
|
-
useBlurView?: boolean;
|
|
108
108
|
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import { Animated, Dimensions } from "react-native";
|
|
4
|
-
import Animation, { AnimationConfig } from "../animations/Animation";
|
|
5
|
-
|
|
6
|
-
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("window");
|
|
7
|
-
|
|
8
|
-
type SlideFrom = "top" | "bottom" | "left" | "right";
|
|
9
|
-
type SlideAnimationConfig = AnimationConfig & {
|
|
10
|
-
slideFrom?: SlideFrom;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default class SlideAnimation extends Animation {
|
|
14
|
-
slideFrom: SlideFrom;
|
|
15
|
-
|
|
16
|
-
static SLIDE_FROM_TOP: SlideFrom = "top";
|
|
17
|
-
static SLIDE_FROM_BOTTOM: SlideFrom = "bottom";
|
|
18
|
-
static SLIDE_FROM_LEFT: SlideFrom = "left";
|
|
19
|
-
static SLIDE_FROM_RIGHT: SlideFrom = "right";
|
|
20
|
-
|
|
21
|
-
constructor({
|
|
22
|
-
initialValue = 0,
|
|
23
|
-
useNativeDriver = true,
|
|
24
|
-
slideFrom = SlideAnimation.SLIDE_FROM_BOTTOM,
|
|
25
|
-
}: SlideAnimationConfig = {}) {
|
|
26
|
-
super({ initialValue, useNativeDriver });
|
|
27
|
-
this.slideFrom = slideFrom;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
in(onFinished: Animated.EndCallback = () => {}, options: any = {}): void {
|
|
31
|
-
Animated.spring(this.animate, {
|
|
32
|
-
toValue: 1,
|
|
33
|
-
velocity: 0,
|
|
34
|
-
tension: 65,
|
|
35
|
-
friction: 11,
|
|
36
|
-
useNativeDriver: this.useNativeDriver,
|
|
37
|
-
...options,
|
|
38
|
-
}).start(onFinished);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
out(onFinished: Animated.EndCallback = () => {}, options: any = {}): void {
|
|
42
|
-
Animated.spring(this.animate, {
|
|
43
|
-
toValue: 0,
|
|
44
|
-
velocity: 0,
|
|
45
|
-
tension: 65,
|
|
46
|
-
friction: 11,
|
|
47
|
-
useNativeDriver: this.useNativeDriver,
|
|
48
|
-
...options,
|
|
49
|
-
}).start(onFinished);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getAnimations(): any {
|
|
53
|
-
const transform: any[] = [];
|
|
54
|
-
if (this.slideFrom === SlideAnimation.SLIDE_FROM_TOP) {
|
|
55
|
-
transform.push({
|
|
56
|
-
translateY: this.animate.interpolate({
|
|
57
|
-
inputRange: [0, 1],
|
|
58
|
-
outputRange: [-SCREEN_HEIGHT, 0],
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
} else if (this.slideFrom === SlideAnimation.SLIDE_FROM_BOTTOM) {
|
|
62
|
-
transform.push({
|
|
63
|
-
translateY: this.animate.interpolate({
|
|
64
|
-
inputRange: [0, 1],
|
|
65
|
-
outputRange: [SCREEN_HEIGHT, 0],
|
|
66
|
-
}),
|
|
67
|
-
});
|
|
68
|
-
} else if (this.slideFrom === SlideAnimation.SLIDE_FROM_LEFT) {
|
|
69
|
-
transform.push({
|
|
70
|
-
translateX: this.animate.interpolate({
|
|
71
|
-
inputRange: [0, 1],
|
|
72
|
-
outputRange: [-SCREEN_WIDTH, 0],
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
} else if (this.slideFrom === SlideAnimation.SLIDE_FROM_RIGHT) {
|
|
76
|
-
transform.push({
|
|
77
|
-
translateX: this.animate.interpolate({
|
|
78
|
-
inputRange: [0, 1],
|
|
79
|
-
outputRange: [SCREEN_WIDTH, 0],
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
throw new Error(`
|
|
84
|
-
slideFrom: ${this.slideFrom} not supported. 'slideFrom' must be 'top' | 'bottom' | 'left' | 'right'
|
|
85
|
-
`);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
transform,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|