@thanhphi/unistyles-ui 0.2.6 → 0.2.7
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/README.md +10 -0
- package/dist/fields.d.ts +4 -2
- package/dist/fields.js +9 -16
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +3 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/list-picker.d.ts +45 -0
- package/dist/list-picker.js +76 -0
- package/dist/module/fields.js +10 -17
- package/dist/module/icons.js +3 -2
- package/dist/module/index.js +3 -0
- package/dist/module/list-picker.js +70 -0
- package/dist/module/overlays.js +71 -35
- package/dist/module/search.js +88 -0
- package/dist/module/ui-modal.js +145 -0
- package/dist/overlays.d.ts +21 -1
- package/dist/overlays.js +71 -34
- package/dist/search.d.ts +27 -0
- package/dist/search.js +91 -0
- package/dist/ui-modal.d.ts +17 -0
- package/dist/ui-modal.js +151 -0
- package/package.json +1 -1
package/dist/ui-modal.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UIModal = UIModal;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const theme_1 = require("./theme");
|
|
11
|
+
function UIModal({ visible, onClose, onOpened, onClosed, position = "center", animationType = "slide", statusBarTranslucent, keyboardAvoiding = false, backdropColor, contentStyle, containerStyle, children, }) {
|
|
12
|
+
const { colors } = (0, theme_1.useUITheme)();
|
|
13
|
+
const Root = keyboardAvoiding && react_native_1.Platform.OS === "ios" ? react_native_1.KeyboardAvoidingView : react_native_1.View;
|
|
14
|
+
const backgroundColor = backdropColor ?? colors.backdrop;
|
|
15
|
+
const renderContent = (motion) => {
|
|
16
|
+
const Panel = motion ? react_native_1.Animated.View : react_native_1.View;
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(Root, { behavior: Root === react_native_1.KeyboardAvoidingView ? "padding" : undefined, style: [
|
|
18
|
+
styles.root,
|
|
19
|
+
position === "bottom" && styles.bottom,
|
|
20
|
+
containerStyle,
|
|
21
|
+
!motion && { backgroundColor },
|
|
22
|
+
], pointerEvents: visible ? "auto" : "none", children: [motion && ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { pointerEvents: "none", style: [
|
|
23
|
+
react_native_1.StyleSheet.absoluteFill,
|
|
24
|
+
{ backgroundColor, opacity: motion.progress },
|
|
25
|
+
] })), onClose && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: onClose, accessible: false })), (0, jsx_runtime_1.jsx)(Panel, { accessibilityViewIsModal: true, onLayout: motion?.onLayout, style: [
|
|
26
|
+
styles.panel,
|
|
27
|
+
position === "fullScreen" && styles.fullScreen,
|
|
28
|
+
contentStyle,
|
|
29
|
+
motion && {
|
|
30
|
+
opacity: motion.progress,
|
|
31
|
+
transform: [
|
|
32
|
+
{
|
|
33
|
+
translateY: motion.progress.interpolate({
|
|
34
|
+
inputRange: [0, 1],
|
|
35
|
+
outputRange: [motion.offset, 0],
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
], children: children })] }));
|
|
41
|
+
};
|
|
42
|
+
if (onOpened || onClosed)
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ModalTransition, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, animationType: animationType, statusBarTranslucent: statusBarTranslucent, children: renderContent }));
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: visible, transparent: true, animationType: animationType, onRequestClose: onClose ?? ignoreModalClose, statusBarTranslucent: statusBarTranslucent, children: renderContent() }));
|
|
45
|
+
}
|
|
46
|
+
// Modal.onDismiss is iOS-only. Animate the panel and backdrop when callbacks
|
|
47
|
+
// are requested so Android can finish the exit before removing the modal.
|
|
48
|
+
function ModalTransition({ visible, onClose, statusBarTranslucent, onOpened, onClosed, animationType, children, }) {
|
|
49
|
+
const [presented, setPresented] = react_1.default.useState(visible);
|
|
50
|
+
const [shown, setShown] = react_1.default.useState(false);
|
|
51
|
+
const [panelHeight, setPanelHeight] = react_1.default.useState(0);
|
|
52
|
+
const [reduceMotion, setReduceMotion] = react_1.default.useState(false);
|
|
53
|
+
const [progress] = react_1.default.useState(() => new react_native_1.Animated.Value(0));
|
|
54
|
+
const request = react_1.default.useRef({ visible, onOpened, onClosed });
|
|
55
|
+
const dismissing = react_1.default.useRef(false);
|
|
56
|
+
const didOpen = react_1.default.useRef(false);
|
|
57
|
+
const entranceReady = shown && (animationType !== "slide" || panelHeight > 0);
|
|
58
|
+
const animate = animationType !== "none" && !reduceMotion;
|
|
59
|
+
react_1.default.useEffect(() => {
|
|
60
|
+
if (!presented)
|
|
61
|
+
return;
|
|
62
|
+
let active = true;
|
|
63
|
+
react_native_1.AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
64
|
+
if (active)
|
|
65
|
+
setReduceMotion(value);
|
|
66
|
+
});
|
|
67
|
+
const subscription = react_native_1.AccessibilityInfo.addEventListener("reduceMotionChanged", setReduceMotion);
|
|
68
|
+
return () => {
|
|
69
|
+
active = false;
|
|
70
|
+
subscription.remove();
|
|
71
|
+
};
|
|
72
|
+
}, [presented]);
|
|
73
|
+
react_1.default.useLayoutEffect(() => {
|
|
74
|
+
request.current = { visible, onOpened, onClosed };
|
|
75
|
+
}, [visible, onOpened, onClosed]);
|
|
76
|
+
const didDismiss = react_1.default.useCallback(() => {
|
|
77
|
+
if (!dismissing.current)
|
|
78
|
+
return;
|
|
79
|
+
dismissing.current = false;
|
|
80
|
+
setShown(false);
|
|
81
|
+
setPanelHeight(0);
|
|
82
|
+
if (request.current.visible)
|
|
83
|
+
setPresented(true);
|
|
84
|
+
else
|
|
85
|
+
request.current.onClosed?.();
|
|
86
|
+
}, []);
|
|
87
|
+
react_1.default.useEffect(() => {
|
|
88
|
+
if (react_native_1.Platform.OS !== "ios" && !presented)
|
|
89
|
+
didDismiss();
|
|
90
|
+
}, [didDismiss, presented]);
|
|
91
|
+
react_1.default.useEffect(() => {
|
|
92
|
+
if (dismissing.current)
|
|
93
|
+
return;
|
|
94
|
+
if (!presented) {
|
|
95
|
+
if (visible)
|
|
96
|
+
setPresented(true);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (visible && !entranceReady && animate)
|
|
100
|
+
return;
|
|
101
|
+
if (visible && !shown)
|
|
102
|
+
return;
|
|
103
|
+
if (!visible)
|
|
104
|
+
didOpen.current = false;
|
|
105
|
+
const complete = () => {
|
|
106
|
+
if (visible !== request.current.visible)
|
|
107
|
+
return;
|
|
108
|
+
if (visible) {
|
|
109
|
+
if (didOpen.current)
|
|
110
|
+
return;
|
|
111
|
+
didOpen.current = true;
|
|
112
|
+
request.current.onOpened?.();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
dismissing.current = true;
|
|
116
|
+
setPresented(false);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const target = visible ? 1 : 0;
|
|
120
|
+
if (!animate || !shown) {
|
|
121
|
+
progress.setValue(target);
|
|
122
|
+
complete();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const animation = react_native_1.Animated.timing(progress, {
|
|
126
|
+
toValue: target,
|
|
127
|
+
duration: visible ? 220 : 200,
|
|
128
|
+
easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
|
|
129
|
+
useNativeDriver: true,
|
|
130
|
+
});
|
|
131
|
+
animation.start(({ finished }) => {
|
|
132
|
+
if (finished)
|
|
133
|
+
complete();
|
|
134
|
+
});
|
|
135
|
+
return () => animation.stop();
|
|
136
|
+
}, [animate, entranceReady, presented, progress, shown, visible]);
|
|
137
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: presented, transparent: true, animationType: "none", onRequestClose: visible ? onClose ?? ignoreModalClose : ignoreModalClose, onShow: () => setShown(true), onDismiss: didDismiss, statusBarTranslucent: statusBarTranslucent, children: children(animate
|
|
138
|
+
? {
|
|
139
|
+
progress,
|
|
140
|
+
offset: animationType === "slide" ? panelHeight : 0,
|
|
141
|
+
onLayout: (event) => setPanelHeight(event.nativeEvent.layout.height),
|
|
142
|
+
}
|
|
143
|
+
: undefined) }));
|
|
144
|
+
}
|
|
145
|
+
const ignoreModalClose = () => { };
|
|
146
|
+
const styles = react_native_1.StyleSheet.create({
|
|
147
|
+
root: { flex: 1, justifyContent: "center" },
|
|
148
|
+
bottom: { justifyContent: "flex-end" },
|
|
149
|
+
panel: { flexShrink: 1 },
|
|
150
|
+
fullScreen: { flex: 1 },
|
|
151
|
+
});
|