@nativetail/ui 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import { BlurView } from "expo-blur";
|
2
|
-
import { AnimatePresence } from "moti";
|
3
1
|
import {
|
4
2
|
mergeClasses,
|
5
3
|
Pressable,
|
@@ -7,6 +5,7 @@ import {
|
|
7
5
|
useTw,
|
8
6
|
View,
|
9
7
|
} from "@nativetail/core";
|
8
|
+
import { AnimatePresence } from "moti";
|
10
9
|
import React, {
|
11
10
|
ReactNode,
|
12
11
|
useCallback,
|
@@ -20,6 +19,8 @@ import {
|
|
20
19
|
Modal,
|
21
20
|
View as NativeView,
|
22
21
|
StatusBar,
|
22
|
+
useWindowDimensions,
|
23
|
+
ViewStyle,
|
23
24
|
} from "react-native";
|
24
25
|
import { Blur } from "../blur";
|
25
26
|
|
@@ -28,6 +29,7 @@ type PositionType = {
|
|
28
29
|
height: number;
|
29
30
|
top: number;
|
30
31
|
left: number;
|
32
|
+
right: number;
|
31
33
|
bottom: number;
|
32
34
|
};
|
33
35
|
type DropdownState = {
|
@@ -97,12 +99,14 @@ const DropdownTrigger = ({
|
|
97
99
|
const top = isFull ? 20 : height + pageY + 2;
|
98
100
|
const bottom = H - top + height;
|
99
101
|
const left = I18nManager.isRTL ? W - width - pageX : pageX;
|
102
|
+
const right = W - left - width;
|
100
103
|
|
101
104
|
setPosition({
|
102
105
|
width: Math.floor(width),
|
103
106
|
top: Math.floor(top + statusBarHeight),
|
104
107
|
bottom: Math.floor(bottom - statusBarHeight),
|
105
108
|
left: Math.floor(left),
|
109
|
+
right: Math.floor(right),
|
106
110
|
height: Math.floor(height),
|
107
111
|
});
|
108
112
|
});
|
@@ -142,7 +146,24 @@ const DropdownMenu = ({
|
|
142
146
|
const top = position?.top || 0;
|
143
147
|
const menuX = left;
|
144
148
|
const menuY = top;
|
149
|
+
const width = position?.width || 0;
|
150
|
+
const screen = useWindowDimensions();
|
151
|
+
const tw = useTw();
|
152
|
+
const style = tw`${className}`;
|
153
|
+
const styleWidth = !isNaN(Number(style?.width)) ? Number(style?.width) : 0;
|
154
|
+
const menuWidth = styleWidth || width || 0;
|
155
|
+
const isEndOfScreen = screen.width - menuX < menuWidth;
|
156
|
+
const menuStyle: ViewStyle = {
|
157
|
+
top: menuY,
|
158
|
+
left: menuX,
|
159
|
+
transformOrigin: "top left",
|
160
|
+
};
|
161
|
+
if (isEndOfScreen) {
|
162
|
+
menuStyle.left = menuX - menuWidth + width;
|
163
|
+
menuStyle.transformOrigin = "top right";
|
164
|
+
}
|
145
165
|
const [modalOpen, setModalOpen] = useState(isOpen);
|
166
|
+
|
146
167
|
useEffect(() => {
|
147
168
|
if (isOpen) {
|
148
169
|
setModalOpen(true);
|
@@ -164,7 +185,6 @@ const DropdownMenu = ({
|
|
164
185
|
setModalOpen(false);
|
165
186
|
}
|
166
187
|
}, [isOpen]);
|
167
|
-
const tw = useTw();
|
168
188
|
const renderChildren = useCallback(() => {
|
169
189
|
return React.Children.map(children, (child, index) => {
|
170
190
|
return React.cloneElement(child as any, {
|
@@ -186,18 +206,14 @@ const DropdownMenu = ({
|
|
186
206
|
{isOpen && (
|
187
207
|
<View
|
188
208
|
className={mergeClasses(
|
189
|
-
"absolute in:scale-0 scale-100 out:scale-0 overflow-hidden z-10 bg-card/95 rounded-xl
|
209
|
+
"absolute in:scale-0 scale-100 out:scale-0 overflow-hidden z-10 bg-card/95 rounded-xl border border-muted/15",
|
210
|
+
width ? `w-[${width}px]` : "",
|
190
211
|
className
|
191
212
|
)}
|
192
213
|
onDidAnimate={onDidAnimate}
|
193
|
-
style={
|
194
|
-
top: menuY,
|
195
|
-
left: menuX,
|
196
|
-
transformOrigin: "top left",
|
197
|
-
}}
|
214
|
+
style={menuStyle}
|
198
215
|
animated
|
199
216
|
print
|
200
|
-
id={"1"}
|
201
217
|
>
|
202
218
|
{useBlur && (
|
203
219
|
<Blur style={tw`absolute top-0 left-0 rounded-xl flex-1 `} />
|