nwui-cli 0.3.6 → 0.4.0
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/.turbo/turbo-build.log +1 -1
- package/build/index.js +15 -3
- package/build/install-component.js +117 -32
- package/build/utils/env.js +3 -0
- package/my-expo-app-2/app/+html.tsx +46 -0
- package/my-expo-app-2/app/+not-found.tsx +33 -0
- package/my-expo-app-2/app/_layout.tsx +22 -0
- package/my-expo-app-2/app/details.tsx +17 -0
- package/my-expo-app-2/app/index.tsx +23 -0
- package/my-expo-app-2/app-env.d.ts +2 -0
- package/my-expo-app-2/app.json +48 -0
- package/my-expo-app-2/assets/adaptive-icon.png +0 -0
- package/my-expo-app-2/assets/favicon.png +0 -0
- package/my-expo-app-2/assets/icon.png +0 -0
- package/my-expo-app-2/assets/splash.png +0 -0
- package/my-expo-app-2/babel.config.js +18 -0
- package/my-expo-app-2/cesconfig.json +35 -0
- package/my-expo-app-2/components/Button.tsx +19 -0
- package/my-expo-app-2/components/Container.tsx +9 -0
- package/my-expo-app-2/components/EditScreenInfo.tsx +34 -0
- package/my-expo-app-2/components/ScreenContent.tsx +25 -0
- package/my-expo-app-2/components/nativewindui/ActivityIndicator.tsx +13 -0
- package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
- package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
- package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
- package/my-expo-app-2/components/nativewindui/Alert/Alert.ios.tsx +65 -0
- package/my-expo-app-2/components/nativewindui/Alert/Alert.tsx +291 -0
- package/my-expo-app-2/components/nativewindui/Alert/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/Alert/types.ts +27 -0
- package/my-expo-app-2/components/nativewindui/Badge.tsx +84 -0
- package/my-expo-app-2/components/nativewindui/Button.tsx +156 -0
- package/my-expo-app-2/components/nativewindui/Checkbox.tsx +61 -0
- package/my-expo-app-2/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
- package/my-expo-app-2/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
- package/my-expo-app-2/components/nativewindui/ContextMenu/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/ContextMenu/types.ts +91 -0
- package/my-expo-app-2/components/nativewindui/ContextMenu/utils.ts +14 -0
- package/my-expo-app-2/components/nativewindui/DrawerContent.tsx +145 -0
- package/my-expo-app-2/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
- package/my-expo-app-2/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
- package/my-expo-app-2/components/nativewindui/DropdownMenu/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/DropdownMenu/types.ts +93 -0
- package/my-expo-app-2/components/nativewindui/DropdownMenu/utils.ts +14 -0
- package/my-expo-app-2/components/nativewindui/Form.tsx +125 -0
- package/my-expo-app-2/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
- package/my-expo-app-2/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
- package/my-expo-app-2/components/nativewindui/LargeTitleHeader/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/LargeTitleHeader/types.ts +89 -0
- package/my-expo-app-2/components/nativewindui/List.tsx +433 -0
- package/my-expo-app-2/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
- package/my-expo-app-2/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
- package/my-expo-app-2/components/nativewindui/SearchInput/index.tsx +1 -0
- package/my-expo-app-2/components/nativewindui/SearchInput/types.ts +12 -0
- package/my-expo-app-2/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
- package/my-expo-app-2/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
- package/my-expo-app-2/components/nativewindui/SegmentedControl/index.ts +1 -0
- package/my-expo-app-2/components/nativewindui/SegmentedControl/types.ts +15 -0
- package/my-expo-app-2/components/nativewindui/Stepper.tsx +62 -0
- package/my-expo-app-2/components/nativewindui/Text.tsx +55 -0
- package/my-expo-app-2/components/nativewindui/TextField/TextField.ios.tsx +85 -0
- package/my-expo-app-2/components/nativewindui/TextField/TextField.tsx +326 -0
- package/my-expo-app-2/components/nativewindui/TextField/index.tsx +1 -0
- package/my-expo-app-2/components/nativewindui/TextField/types.ts +26 -0
- package/my-expo-app-2/components/nativewindui/Toolbar.tsx +116 -0
- package/my-expo-app-2/global.css +3 -0
- package/my-expo-app-2/metro.config.js +12 -0
- package/my-expo-app-2/package-lock.json +19162 -0
- package/my-expo-app-2/package.json +74 -0
- package/my-expo-app-2/prettier.config.js +11 -0
- package/my-expo-app-2/tailwind.config.js +11 -0
- package/my-expo-app-3/app/+html.tsx +46 -0
- package/my-expo-app-3/app/+not-found.tsx +33 -0
- package/my-expo-app-3/app/_layout.tsx +22 -0
- package/my-expo-app-3/app/details.tsx +17 -0
- package/my-expo-app-3/app/index.tsx +23 -0
- package/my-expo-app-3/app-env.d.ts +2 -0
- package/my-expo-app-3/app.json +48 -0
- package/my-expo-app-3/assets/adaptive-icon.png +0 -0
- package/my-expo-app-3/assets/favicon.png +0 -0
- package/my-expo-app-3/assets/icon.png +0 -0
- package/my-expo-app-3/assets/splash.png +0 -0
- package/my-expo-app-3/babel.config.js +18 -0
- package/my-expo-app-3/cesconfig.json +35 -0
- package/my-expo-app-3/components/Button.tsx +19 -0
- package/my-expo-app-3/components/Container.tsx +9 -0
- package/my-expo-app-3/components/EditScreenInfo.tsx +34 -0
- package/my-expo-app-3/components/ScreenContent.tsx +25 -0
- package/my-expo-app-3/components/nativewindui/ActivityIndicator.tsx +13 -0
- package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
- package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
- package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
- package/my-expo-app-3/components/nativewindui/Alert/Alert.ios.tsx +65 -0
- package/my-expo-app-3/components/nativewindui/Alert/Alert.tsx +291 -0
- package/my-expo-app-3/components/nativewindui/Alert/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/Alert/types.ts +27 -0
- package/my-expo-app-3/components/nativewindui/Badge.tsx +84 -0
- package/my-expo-app-3/components/nativewindui/Button.tsx +156 -0
- package/my-expo-app-3/components/nativewindui/Checkbox.tsx +61 -0
- package/my-expo-app-3/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
- package/my-expo-app-3/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
- package/my-expo-app-3/components/nativewindui/ContextMenu/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/ContextMenu/types.ts +91 -0
- package/my-expo-app-3/components/nativewindui/ContextMenu/utils.ts +14 -0
- package/my-expo-app-3/components/nativewindui/DrawerContent.tsx +145 -0
- package/my-expo-app-3/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
- package/my-expo-app-3/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
- package/my-expo-app-3/components/nativewindui/DropdownMenu/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/DropdownMenu/types.ts +93 -0
- package/my-expo-app-3/components/nativewindui/DropdownMenu/utils.ts +14 -0
- package/my-expo-app-3/components/nativewindui/Form.tsx +125 -0
- package/my-expo-app-3/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
- package/my-expo-app-3/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
- package/my-expo-app-3/components/nativewindui/LargeTitleHeader/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/LargeTitleHeader/types.ts +89 -0
- package/my-expo-app-3/components/nativewindui/List.tsx +433 -0
- package/my-expo-app-3/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
- package/my-expo-app-3/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
- package/my-expo-app-3/components/nativewindui/SearchInput/index.tsx +1 -0
- package/my-expo-app-3/components/nativewindui/SearchInput/types.ts +12 -0
- package/my-expo-app-3/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
- package/my-expo-app-3/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
- package/my-expo-app-3/components/nativewindui/SegmentedControl/index.ts +1 -0
- package/my-expo-app-3/components/nativewindui/SegmentedControl/types.ts +15 -0
- package/my-expo-app-3/components/nativewindui/Stepper.tsx +62 -0
- package/my-expo-app-3/components/nativewindui/Text.tsx +55 -0
- package/my-expo-app-3/components/nativewindui/TextField/TextField.ios.tsx +85 -0
- package/my-expo-app-3/components/nativewindui/TextField/TextField.tsx +326 -0
- package/my-expo-app-3/components/nativewindui/TextField/index.tsx +1 -0
- package/my-expo-app-3/components/nativewindui/TextField/types.ts +26 -0
- package/my-expo-app-3/components/nativewindui/Toolbar.tsx +116 -0
- package/my-expo-app-3/components/nativewindui/examples/selectable-text.tsx +43 -0
- package/my-expo-app-3/components/nativewindui/examples/text.tsx +43 -0
- package/my-expo-app-3/global.css +3 -0
- package/my-expo-app-3/metro.config.js +12 -0
- package/my-expo-app-3/package-lock.json +19141 -0
- package/my-expo-app-3/package.json +73 -0
- package/my-expo-app-3/prettier.config.js +11 -0
- package/my-expo-app-3/tailwind.config.js +11 -0
- package/my-expo-app-test-case/app/+html.tsx +46 -0
- package/my-expo-app-test-case/app/+not-found.tsx +33 -0
- package/my-expo-app-test-case/app/_layout.tsx +22 -0
- package/my-expo-app-test-case/app/details.tsx +17 -0
- package/my-expo-app-test-case/app/index.tsx +23 -0
- package/my-expo-app-test-case/app-env.d.ts +2 -0
- package/my-expo-app-test-case/app.json +48 -0
- package/my-expo-app-test-case/assets/adaptive-icon.png +0 -0
- package/my-expo-app-test-case/assets/favicon.png +0 -0
- package/my-expo-app-test-case/assets/icon.png +0 -0
- package/my-expo-app-test-case/assets/splash.png +0 -0
- package/my-expo-app-test-case/babel.config.js +18 -0
- package/my-expo-app-test-case/cesconfig.json +35 -0
- package/my-expo-app-test-case/components/Button.tsx +19 -0
- package/my-expo-app-test-case/components/Container.tsx +9 -0
- package/my-expo-app-test-case/components/EditScreenInfo.tsx +34 -0
- package/my-expo-app-test-case/components/ScreenContent.tsx +25 -0
- package/my-expo-app-test-case/components/nativewindui/ActivityIndicator.tsx +13 -0
- package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
- package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
- package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
- package/my-expo-app-test-case/components/nativewindui/Alert/Alert.ios.tsx +65 -0
- package/my-expo-app-test-case/components/nativewindui/Alert/Alert.tsx +291 -0
- package/my-expo-app-test-case/components/nativewindui/Alert/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/Alert/types.ts +27 -0
- package/my-expo-app-test-case/components/nativewindui/Badge.tsx +84 -0
- package/my-expo-app-test-case/components/nativewindui/Button.tsx +156 -0
- package/my-expo-app-test-case/components/nativewindui/Checkbox.tsx +61 -0
- package/my-expo-app-test-case/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
- package/my-expo-app-test-case/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
- package/my-expo-app-test-case/components/nativewindui/ContextMenu/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/ContextMenu/types.ts +91 -0
- package/my-expo-app-test-case/components/nativewindui/ContextMenu/utils.ts +14 -0
- package/my-expo-app-test-case/components/nativewindui/DrawerContent.tsx +145 -0
- package/my-expo-app-test-case/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
- package/my-expo-app-test-case/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
- package/my-expo-app-test-case/components/nativewindui/DropdownMenu/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/DropdownMenu/types.ts +93 -0
- package/my-expo-app-test-case/components/nativewindui/DropdownMenu/utils.ts +14 -0
- package/my-expo-app-test-case/components/nativewindui/Form.tsx +125 -0
- package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
- package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
- package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/types.ts +89 -0
- package/my-expo-app-test-case/components/nativewindui/List.tsx +433 -0
- package/my-expo-app-test-case/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
- package/my-expo-app-test-case/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
- package/my-expo-app-test-case/components/nativewindui/SearchInput/index.tsx +1 -0
- package/my-expo-app-test-case/components/nativewindui/SearchInput/types.ts +12 -0
- package/my-expo-app-test-case/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
- package/my-expo-app-test-case/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
- package/my-expo-app-test-case/components/nativewindui/SegmentedControl/index.ts +1 -0
- package/my-expo-app-test-case/components/nativewindui/SegmentedControl/types.ts +15 -0
- package/my-expo-app-test-case/components/nativewindui/Stepper.tsx +62 -0
- package/my-expo-app-test-case/components/nativewindui/Text.tsx +55 -0
- package/my-expo-app-test-case/components/nativewindui/TextField/TextField.ios.tsx +85 -0
- package/my-expo-app-test-case/components/nativewindui/TextField/TextField.tsx +326 -0
- package/my-expo-app-test-case/components/nativewindui/TextField/index.tsx +1 -0
- package/my-expo-app-test-case/components/nativewindui/TextField/types.ts +26 -0
- package/my-expo-app-test-case/components/nativewindui/Toolbar.tsx +116 -0
- package/my-expo-app-test-case/components/nativewindui/examples/a-user-created-file.tsx +0 -0
- package/my-expo-app-test-case/components/nativewindui/examples/selectable-text.tsx +43 -0
- package/my-expo-app-test-case/components/nativewindui/examples/text.tsx +43 -0
- package/my-expo-app-test-case/global.css +3 -0
- package/my-expo-app-test-case/metro.config.js +12 -0
- package/my-expo-app-test-case/package-lock.json +19141 -0
- package/my-expo-app-test-case/package.json +73 -0
- package/my-expo-app-test-case/prettier.config.js +11 -0
- package/my-expo-app-test-case/tailwind.config.js +11 -0
- package/no-install/app/+html.tsx +46 -0
- package/no-install/app/+not-found.tsx +25 -0
- package/no-install/app/_layout.tsx +7 -0
- package/no-install/app/details.tsx +20 -0
- package/no-install/app/index.tsx +19 -0
- package/no-install/app-env.d.ts +2 -0
- package/no-install/app.json +41 -0
- package/no-install/assets/adaptive-icon.png +0 -0
- package/no-install/assets/favicon.png +0 -0
- package/no-install/assets/icon.png +0 -0
- package/no-install/assets/splash.png +0 -0
- package/no-install/babel.config.js +13 -0
- package/no-install/cesconfig.json +35 -0
- package/no-install/components/Button.tsx +25 -0
- package/no-install/components/Container.tsx +9 -0
- package/no-install/components/EditScreenInfo.tsx +31 -0
- package/no-install/components/ScreenContent.tsx +29 -0
- package/no-install/components/nativewindui/Slider.tsx +26 -0
- package/no-install/global.css +3 -0
- package/no-install/metro.config.js +10 -0
- package/no-install/package-lock.json +17505 -0
- package/no-install/package.json +59 -0
- package/no-install/prettier.config.js +10 -0
- package/no-install/tailwind.config.js +14 -0
- package/package.json +2 -2
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import * as DropdownMenuPrimitive from '@rn-primitives/dropdown-menu';
|
|
2
|
+
import { useAugmentedRef } from '@rn-primitives/hooks';
|
|
3
|
+
import { Icon } from '@roninoss/icons';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { Image, LayoutChangeEvent, StyleSheet, View } from 'react-native';
|
|
6
|
+
import Animated, {
|
|
7
|
+
FadeIn,
|
|
8
|
+
FadeInLeft,
|
|
9
|
+
FadeOut,
|
|
10
|
+
FadeOutLeft,
|
|
11
|
+
LayoutAnimationConfig,
|
|
12
|
+
LinearTransition,
|
|
13
|
+
} from 'react-native-reanimated';
|
|
14
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
15
|
+
|
|
16
|
+
import { DropdownItem, DropdownMenuProps, DropdownMenuRef, DropdownSubMenu } from './types';
|
|
17
|
+
|
|
18
|
+
import { ActivityIndicator } from '~/components/nativewindui/ActivityIndicator';
|
|
19
|
+
import { Button } from '~/components/nativewindui/Button';
|
|
20
|
+
import { Text } from '~/components/nativewindui/Text';
|
|
21
|
+
import { cn } from '~/lib/cn';
|
|
22
|
+
import { useColorScheme } from '~/lib/useColorScheme';
|
|
23
|
+
|
|
24
|
+
const DropdownContext = React.createContext<{
|
|
25
|
+
onItemPress: DropdownMenuProps['onItemPress'];
|
|
26
|
+
dismissMenu?: () => void;
|
|
27
|
+
materialLoadingText: string;
|
|
28
|
+
materialSubMenuTitlePlaceholder: string;
|
|
29
|
+
subMenuRefs: React.MutableRefObject<DropdownMenuRef[]>;
|
|
30
|
+
closeSubMenus: () => void;
|
|
31
|
+
} | null>(null);
|
|
32
|
+
|
|
33
|
+
const DropdownMenu = React.forwardRef<DropdownMenuRef, DropdownMenuProps>(
|
|
34
|
+
(
|
|
35
|
+
{
|
|
36
|
+
items,
|
|
37
|
+
title,
|
|
38
|
+
iOSItemSize: _iOSItemSize,
|
|
39
|
+
onItemPress: onItemPressProp,
|
|
40
|
+
enabled = true,
|
|
41
|
+
children,
|
|
42
|
+
materialPortalHost,
|
|
43
|
+
materialSideOffset = 2,
|
|
44
|
+
materialAlignOffset,
|
|
45
|
+
materialAlign = 'center',
|
|
46
|
+
materialWidth,
|
|
47
|
+
materialMinWidth = 200,
|
|
48
|
+
materialLoadingText = 'Loading...',
|
|
49
|
+
materialSubMenuTitlePlaceholder = 'More ...',
|
|
50
|
+
materialOverlayClassName,
|
|
51
|
+
// @ts-expect-error internal prop
|
|
52
|
+
materialIsSubMenu,
|
|
53
|
+
...props
|
|
54
|
+
},
|
|
55
|
+
ref
|
|
56
|
+
) => {
|
|
57
|
+
const triggerRef = React.useRef<DropdownMenuPrimitive.DropdownMenuTriggerRef>(null);
|
|
58
|
+
const subMenuRefs = React.useRef<DropdownMenuRef[]>([]);
|
|
59
|
+
const insets = useSafeAreaInsets();
|
|
60
|
+
const rootRef = useAugmentedRef({
|
|
61
|
+
ref,
|
|
62
|
+
methods: {
|
|
63
|
+
presentMenu: () => {
|
|
64
|
+
triggerRef.current?.open();
|
|
65
|
+
},
|
|
66
|
+
dismissMenu,
|
|
67
|
+
},
|
|
68
|
+
deps: [triggerRef.current],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
function closeSubMenus() {
|
|
72
|
+
for (const subMenuRef of subMenuRefs.current) {
|
|
73
|
+
subMenuRef.dismissMenu?.();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function onItemPress(item: Omit<DropdownItem, 'icon'>) {
|
|
78
|
+
closeSubMenus();
|
|
79
|
+
onItemPressProp?.(item);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function dismissMenu() {
|
|
83
|
+
triggerRef.current?.close();
|
|
84
|
+
}
|
|
85
|
+
return (
|
|
86
|
+
<DropdownMenuPrimitive.Root ref={rootRef} {...props}>
|
|
87
|
+
<DropdownMenuPrimitive.Trigger ref={triggerRef} asChild>
|
|
88
|
+
{children}
|
|
89
|
+
</DropdownMenuPrimitive.Trigger>
|
|
90
|
+
<DropdownMenuPrimitive.Portal hostName={materialPortalHost}>
|
|
91
|
+
<DropdownContext.Provider
|
|
92
|
+
value={{
|
|
93
|
+
onItemPress,
|
|
94
|
+
dismissMenu,
|
|
95
|
+
materialLoadingText,
|
|
96
|
+
materialSubMenuTitlePlaceholder,
|
|
97
|
+
subMenuRefs,
|
|
98
|
+
closeSubMenus,
|
|
99
|
+
}}>
|
|
100
|
+
<DropdownMenuPrimitive.Overlay
|
|
101
|
+
style={StyleSheet.absoluteFill}
|
|
102
|
+
pointerEvents={materialIsSubMenu ? 'box-none' : undefined}>
|
|
103
|
+
<Animated.View
|
|
104
|
+
style={StyleSheet.absoluteFill}
|
|
105
|
+
entering={FadeIn}
|
|
106
|
+
exiting={FadeOut}
|
|
107
|
+
pointerEvents={materialIsSubMenu ? 'box-none' : undefined}
|
|
108
|
+
className={cn(
|
|
109
|
+
!materialIsSubMenu && 'bg-black/20',
|
|
110
|
+
!materialIsSubMenu && materialOverlayClassName
|
|
111
|
+
)}>
|
|
112
|
+
<DropdownMenuPrimitive.Content
|
|
113
|
+
insets={{
|
|
114
|
+
top: insets.top,
|
|
115
|
+
right: 8,
|
|
116
|
+
bottom: insets.bottom,
|
|
117
|
+
left: 8,
|
|
118
|
+
}}
|
|
119
|
+
sideOffset={materialSideOffset}
|
|
120
|
+
alignOffset={materialAlignOffset}
|
|
121
|
+
align={materialAlign}>
|
|
122
|
+
<Animated.View
|
|
123
|
+
entering={FadeIn}
|
|
124
|
+
exiting={materialIsSubMenu ? undefined : FadeOut}
|
|
125
|
+
style={{ minWidth: materialMinWidth, width: materialWidth }}
|
|
126
|
+
className="border-border/20 bg-card z-50 rounded-md border py-2 shadow-xl">
|
|
127
|
+
{!!title && <DropdownMenuLabel>{title}</DropdownMenuLabel>}
|
|
128
|
+
<DropdownMenuInnerContent items={items} />
|
|
129
|
+
</Animated.View>
|
|
130
|
+
</DropdownMenuPrimitive.Content>
|
|
131
|
+
</Animated.View>
|
|
132
|
+
</DropdownMenuPrimitive.Overlay>
|
|
133
|
+
</DropdownContext.Provider>
|
|
134
|
+
</DropdownMenuPrimitive.Portal>
|
|
135
|
+
</DropdownMenuPrimitive.Root>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
DropdownMenu.displayName = 'DropdownMenu';
|
|
141
|
+
|
|
142
|
+
export { DropdownMenu };
|
|
143
|
+
|
|
144
|
+
function useDropdownContext() {
|
|
145
|
+
const context = React.useContext(DropdownContext);
|
|
146
|
+
if (!context) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
'DropdownMenu compound components cannot be rendered outside the DropdownMenu component'
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return context;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function DropdownMenuInnerContent({ items }: { items: (DropdownItem | DropdownSubMenu)[] }) {
|
|
155
|
+
const { materialLoadingText } = useDropdownContext();
|
|
156
|
+
const id = React.useId();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<View>
|
|
160
|
+
{items.map((item, index) => {
|
|
161
|
+
if (item.loading) {
|
|
162
|
+
return (
|
|
163
|
+
<DropdownMenuPrimitive.Item key={`loading:${id}-${item.title}-${index}`} asChild>
|
|
164
|
+
<Button
|
|
165
|
+
disabled
|
|
166
|
+
variant="plain"
|
|
167
|
+
className="h-12 justify-between gap-10 rounded-none px-3"
|
|
168
|
+
androidRootClassName="rounded-none ">
|
|
169
|
+
<Text className="font-normal opacity-60">{materialLoadingText}</Text>
|
|
170
|
+
<ActivityIndicator />
|
|
171
|
+
</Button>
|
|
172
|
+
</DropdownMenuPrimitive.Item>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
if ((item as Partial<DropdownSubMenu>)?.items) {
|
|
176
|
+
const subMenu = item as DropdownSubMenu;
|
|
177
|
+
if (subMenu.items.length === 0) return null;
|
|
178
|
+
return (
|
|
179
|
+
<DropdownMenuSubMenu
|
|
180
|
+
title={subMenu.title}
|
|
181
|
+
subTitle={subMenu.subTitle}
|
|
182
|
+
items={subMenu.items}
|
|
183
|
+
key={`${id}-${subMenu.title}-${index}`}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const dropdownItem = item as DropdownItem;
|
|
188
|
+
return <DropdownMenuItem key={dropdownItem.actionKey} {...dropdownItem} />;
|
|
189
|
+
})}
|
|
190
|
+
</View>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function DropdownMenuLabel(props: { children: React.ReactNode }) {
|
|
195
|
+
return (
|
|
196
|
+
<DropdownMenuPrimitive.Label className="text-muted-foreground/80 border-border/25 dark:border-border/80 dark:text-muted-foreground border-b px-3 pb-2 text-sm">
|
|
197
|
+
{props.children}
|
|
198
|
+
</DropdownMenuPrimitive.Label>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function DropdownMenuItem(props: Omit<DropdownItem, 'loading'>) {
|
|
203
|
+
const { colors } = useColorScheme();
|
|
204
|
+
const { onItemPress } = useDropdownContext();
|
|
205
|
+
|
|
206
|
+
function onPress() {
|
|
207
|
+
onItemPress?.(props);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (props.hidden) return null;
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<LayoutAnimationConfig skipEntering skipExiting>
|
|
214
|
+
<DropdownMenuPrimitive.Item
|
|
215
|
+
asChild
|
|
216
|
+
closeOnPress={!props.keepOpenOnPress}
|
|
217
|
+
role="checkbox"
|
|
218
|
+
accessibilityState={{
|
|
219
|
+
disabled: !!props.disabled,
|
|
220
|
+
checked: props.state?.checked,
|
|
221
|
+
}}>
|
|
222
|
+
<Button
|
|
223
|
+
variant={props.state?.checked ? 'tonal' : 'plain'}
|
|
224
|
+
className={cn(
|
|
225
|
+
'h-12 justify-between gap-10 rounded-none px-3',
|
|
226
|
+
!props.state && !props.title && 'justify-center px-4'
|
|
227
|
+
)}
|
|
228
|
+
androidRootClassName="rounded-none"
|
|
229
|
+
accessibilityHint={props.subTitle}
|
|
230
|
+
onPress={onPress}>
|
|
231
|
+
{!props.state && !props.title ? null : (
|
|
232
|
+
<View className="flex-row items-center gap-3 py-0.5">
|
|
233
|
+
{props.state?.checked && (
|
|
234
|
+
<Animated.View entering={FadeInLeft} exiting={FadeOutLeft}>
|
|
235
|
+
<Icon name="check" size={21} color={colors.foreground} />
|
|
236
|
+
</Animated.View>
|
|
237
|
+
)}
|
|
238
|
+
<Animated.View layout={LinearTransition}>
|
|
239
|
+
<Text
|
|
240
|
+
numberOfLines={1}
|
|
241
|
+
className={cn(
|
|
242
|
+
'font-normal',
|
|
243
|
+
props.destructive && 'text-destructive font-medium',
|
|
244
|
+
props.disabled && 'opacity-60'
|
|
245
|
+
)}>
|
|
246
|
+
{props.title}
|
|
247
|
+
</Text>
|
|
248
|
+
</Animated.View>
|
|
249
|
+
{props.state && !props.state?.checked && (
|
|
250
|
+
<Icon name="check" size={21} color="#00000000" />
|
|
251
|
+
)}
|
|
252
|
+
</View>
|
|
253
|
+
)}
|
|
254
|
+
{props.image ? (
|
|
255
|
+
<Image
|
|
256
|
+
source={{ uri: props.image.url }}
|
|
257
|
+
style={{
|
|
258
|
+
width: 22,
|
|
259
|
+
height: 22,
|
|
260
|
+
borderRadius:
|
|
261
|
+
typeof props.image.cornerRadius === 'number' && props.image.cornerRadius > 0
|
|
262
|
+
? props.image.cornerRadius / 4
|
|
263
|
+
: 0,
|
|
264
|
+
}}
|
|
265
|
+
/>
|
|
266
|
+
) : props.icon ? (
|
|
267
|
+
<Icon color={colors.foreground} {...props.icon} size={22} />
|
|
268
|
+
) : null}
|
|
269
|
+
</Button>
|
|
270
|
+
</DropdownMenuPrimitive.Item>
|
|
271
|
+
</LayoutAnimationConfig>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const DEFAULT_LAYOUT = {
|
|
276
|
+
width: 0,
|
|
277
|
+
height: 0,
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function DropdownMenuSubMenu({ title, subTitle, items }: Omit<DropdownSubMenu, 'loading'>) {
|
|
281
|
+
const { colors } = useColorScheme();
|
|
282
|
+
const {
|
|
283
|
+
onItemPress: onDropdownItemPress,
|
|
284
|
+
dismissMenu,
|
|
285
|
+
materialSubMenuTitlePlaceholder,
|
|
286
|
+
subMenuRefs,
|
|
287
|
+
closeSubMenus,
|
|
288
|
+
} = useDropdownContext();
|
|
289
|
+
const [triggerLayout, setTriggerLayout] = React.useState<typeof DEFAULT_LAYOUT>(DEFAULT_LAYOUT);
|
|
290
|
+
|
|
291
|
+
function onItemPress(item: Omit<DropdownItem, 'icon'>) {
|
|
292
|
+
dismissMenu?.();
|
|
293
|
+
onDropdownItemPress?.(item);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function onLayout(ev: LayoutChangeEvent) {
|
|
297
|
+
setTriggerLayout(ev.nativeEvent.layout);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function addSubMenuRef(ref: DropdownMenuRef | null) {
|
|
301
|
+
if (!ref) return;
|
|
302
|
+
subMenuRefs.current.push(ref);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<DropdownMenu
|
|
307
|
+
items={items}
|
|
308
|
+
materialAlign="start"
|
|
309
|
+
materialSideOffset={-triggerLayout.height}
|
|
310
|
+
materialAlignOffset={triggerLayout.width}
|
|
311
|
+
onItemPress={onItemPress}
|
|
312
|
+
materialMinWidth={48}
|
|
313
|
+
// @ts-expect-error internal prop
|
|
314
|
+
materialIsSubMenu
|
|
315
|
+
ref={addSubMenuRef}>
|
|
316
|
+
<Button
|
|
317
|
+
variant="plain"
|
|
318
|
+
className=" justify-between gap-10 rounded-none px-3"
|
|
319
|
+
androidRootClassName="rounded-none"
|
|
320
|
+
onLayout={onLayout}
|
|
321
|
+
accessibilityHint={subTitle}
|
|
322
|
+
onPress={closeSubMenus}>
|
|
323
|
+
<Text numberOfLines={1} className="py-0.5 font-normal">
|
|
324
|
+
{title || materialSubMenuTitlePlaceholder}
|
|
325
|
+
</Text>
|
|
326
|
+
<Icon name="chevron-right" size={21} color={colors.grey} />
|
|
327
|
+
</Button>
|
|
328
|
+
</DropdownMenu>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DropdownMenu';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { MaterialIconName, SfSymbolIconName } from '@roninoss/icons';
|
|
2
|
+
import type { View, ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type MaterialIcon = {
|
|
5
|
+
name: MaterialIconName;
|
|
6
|
+
namingScheme?: 'material' | undefined;
|
|
7
|
+
color?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type SfSymbolIcon = {
|
|
11
|
+
name: SfSymbolIconName;
|
|
12
|
+
namingScheme: 'sfSymbol';
|
|
13
|
+
color?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type DropdownIcon = SfSymbolIcon | MaterialIcon;
|
|
17
|
+
|
|
18
|
+
type DropdownItem = {
|
|
19
|
+
actionKey: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
subTitle?: string;
|
|
22
|
+
state?: { checked: boolean };
|
|
23
|
+
keepOpenOnPress?: boolean;
|
|
24
|
+
// iOS 14 and above
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
destructive?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
hidden?: boolean;
|
|
29
|
+
// icon or image, not both image has higher priority
|
|
30
|
+
icon?: DropdownIcon;
|
|
31
|
+
// icon or image, not both image has higher priority
|
|
32
|
+
image?: { url?: string; cornerRadius?: number; tint?: string };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type DropdownSubMenuDropdown = {
|
|
36
|
+
iOSType?: 'dropdown';
|
|
37
|
+
// preferred item size
|
|
38
|
+
iOSItemSize?: 'large';
|
|
39
|
+
destructive?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type DropdownSubMenuInline = {
|
|
43
|
+
iOSType: 'inline';
|
|
44
|
+
// preferred item size
|
|
45
|
+
iOSItemSize?: 'small' | 'medium';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type DropdownSubMenu = (DropdownSubMenuDropdown | DropdownSubMenuInline) & {
|
|
49
|
+
title: string;
|
|
50
|
+
// Displayed on iOS 15 and above only, used as accessibility hint otherwise
|
|
51
|
+
subTitle?: string;
|
|
52
|
+
// iOS 14 and above only
|
|
53
|
+
loading?: boolean;
|
|
54
|
+
// No items shows nothing
|
|
55
|
+
items: (DropdownItem | DropdownSubMenu)[];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type DropdownMenuConfig = {
|
|
59
|
+
title?: string;
|
|
60
|
+
items: (DropdownItem | DropdownSubMenu)[];
|
|
61
|
+
// preferred item size
|
|
62
|
+
iOSItemSize?: 'small' | 'medium' | 'large';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type DropdownMenuProps = DropdownMenuConfig &
|
|
66
|
+
ViewProps & {
|
|
67
|
+
children: React.ReactNode;
|
|
68
|
+
onItemPress?: (item: Omit<DropdownItem, 'icon'>, isUsingActionSheetFallback?: boolean) => void;
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
materialPortalHost?: string;
|
|
71
|
+
// defaults to 2
|
|
72
|
+
materialSideOffset?: number;
|
|
73
|
+
materialAlignOffset?: number;
|
|
74
|
+
materialAlign?: 'start' | 'center' | 'end';
|
|
75
|
+
materialWidth?: number;
|
|
76
|
+
materialMinWidth?: number;
|
|
77
|
+
materialLoadingText?: string;
|
|
78
|
+
materialSubMenuTitlePlaceholder?: string;
|
|
79
|
+
materialOverlayClassName?: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type DropdownMenuRef = React.ElementRef<typeof View> & {
|
|
83
|
+
presentMenu?: () => void;
|
|
84
|
+
dismissMenu?: () => void;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type {
|
|
88
|
+
DropdownMenuProps,
|
|
89
|
+
DropdownMenuConfig,
|
|
90
|
+
DropdownSubMenu,
|
|
91
|
+
DropdownItem,
|
|
92
|
+
DropdownMenuRef,
|
|
93
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DropdownItem, DropdownSubMenu } from './types';
|
|
2
|
+
|
|
3
|
+
function createDropdownSubMenu(
|
|
4
|
+
subMenu: Omit<DropdownSubMenu, 'items'>,
|
|
5
|
+
items: DropdownSubMenu['items']
|
|
6
|
+
) {
|
|
7
|
+
return Object.assign(subMenu, { items }) as DropdownSubMenu;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function createDropdownItem(item: DropdownItem) {
|
|
11
|
+
return item;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createDropdownSubMenu, createDropdownItem };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Icon, type IconProps } from '@roninoss/icons';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Platform, View, ViewProps, ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { Text } from '~/components/nativewindui/Text';
|
|
6
|
+
import { cn } from '~/lib/cn';
|
|
7
|
+
import { useColorScheme } from '~/lib/useColorScheme';
|
|
8
|
+
|
|
9
|
+
const Form = React.forwardRef<View, ViewProps>(({ className, ...props }, ref) => {
|
|
10
|
+
return <View ref={ref} className={cn('flex-1 gap-9', className)} {...props} />;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Add as class when possible: https://github.com/marklawlor/nativewind/issues/522
|
|
14
|
+
const BORDER_CURVE: ViewStyle = {
|
|
15
|
+
borderCurve: 'continuous',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type FormSectionProps = ViewProps & {
|
|
19
|
+
rootClassName?: string;
|
|
20
|
+
footnote?: string;
|
|
21
|
+
footnoteClassName?: string;
|
|
22
|
+
ios?: {
|
|
23
|
+
title: string;
|
|
24
|
+
titleClassName?: string;
|
|
25
|
+
};
|
|
26
|
+
materialIconProps?: Omit<IconProps<'material'>, 'namingScheme' | 'ios'>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const FormSection = React.forwardRef<React.ElementRef<typeof View>, FormSectionProps>(
|
|
30
|
+
(
|
|
31
|
+
{
|
|
32
|
+
rootClassName,
|
|
33
|
+
className,
|
|
34
|
+
footnote,
|
|
35
|
+
footnoteClassName,
|
|
36
|
+
ios,
|
|
37
|
+
materialIconProps,
|
|
38
|
+
style = BORDER_CURVE,
|
|
39
|
+
children: childrenProps,
|
|
40
|
+
...props
|
|
41
|
+
},
|
|
42
|
+
ref
|
|
43
|
+
) => {
|
|
44
|
+
const { colors } = useColorScheme();
|
|
45
|
+
const children = React.useMemo(() => {
|
|
46
|
+
if (Platform.OS !== 'ios') return childrenProps;
|
|
47
|
+
const childrenArray = React.Children.toArray(childrenProps);
|
|
48
|
+
// Add isLast prop to last child
|
|
49
|
+
return React.Children.map(childrenArray, (child, index) => {
|
|
50
|
+
if (!React.isValidElement(child)) return child;
|
|
51
|
+
const isLast = index === childrenArray.length - 1;
|
|
52
|
+
if (typeof child === 'string') {
|
|
53
|
+
console.log('FormSection - Invalid asChild element', child);
|
|
54
|
+
}
|
|
55
|
+
return React.cloneElement<ViewProps & { isLast?: boolean }, View>(
|
|
56
|
+
typeof child === 'string' ? <></> : child,
|
|
57
|
+
{ isLast }
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
}, [childrenProps]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<View
|
|
64
|
+
className={cn(
|
|
65
|
+
'relative',
|
|
66
|
+
Platform.OS !== 'ios' && !!materialIconProps && 'flex-row gap-4',
|
|
67
|
+
rootClassName
|
|
68
|
+
)}>
|
|
69
|
+
{Platform.OS === 'ios' && !!ios?.title && (
|
|
70
|
+
<Text
|
|
71
|
+
variant="footnote"
|
|
72
|
+
className={cn('pb-1 pl-3 uppercase text-muted-foreground', ios?.titleClassName)}>
|
|
73
|
+
{ios.title}
|
|
74
|
+
</Text>
|
|
75
|
+
)}
|
|
76
|
+
{!!materialIconProps && (
|
|
77
|
+
<View className="ios:hidden pt-0.5">
|
|
78
|
+
<Icon color={colors.grey} size={24} {...(materialIconProps as IconProps<'material'>)} />
|
|
79
|
+
</View>
|
|
80
|
+
)}
|
|
81
|
+
<View className="flex-1">
|
|
82
|
+
<View
|
|
83
|
+
ref={ref}
|
|
84
|
+
className={cn(
|
|
85
|
+
'ios:overflow-hidden ios:rounded-lg ios:bg-card ios:gap-0 ios:pl-1 gap-4',
|
|
86
|
+
className
|
|
87
|
+
)}
|
|
88
|
+
style={style}
|
|
89
|
+
children={children}
|
|
90
|
+
{...props}
|
|
91
|
+
/>
|
|
92
|
+
{!!footnote && (
|
|
93
|
+
<Text
|
|
94
|
+
className={cn(
|
|
95
|
+
'ios:pl-3 ios:pt-1 pl-3 pt-0.5 text-muted-foreground',
|
|
96
|
+
footnoteClassName
|
|
97
|
+
)}
|
|
98
|
+
variant="footnote">
|
|
99
|
+
{footnote}
|
|
100
|
+
</Text>
|
|
101
|
+
)}
|
|
102
|
+
</View>
|
|
103
|
+
</View>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const FormItem = React.forwardRef<
|
|
109
|
+
View,
|
|
110
|
+
ViewProps & {
|
|
111
|
+
isLast?: boolean;
|
|
112
|
+
iosSeparatorClassName?: string;
|
|
113
|
+
}
|
|
114
|
+
>(({ className, isLast, iosSeparatorClassName, ...props }, ref) => {
|
|
115
|
+
return (
|
|
116
|
+
<>
|
|
117
|
+
<View ref={ref} className={cn('ios:pr-1', className)} {...props} />
|
|
118
|
+
{Platform.OS === 'ios' && !isLast && (
|
|
119
|
+
<View className={cn('ml-2 h-px flex-1 bg-border', iosSeparatorClassName)} />
|
|
120
|
+
)}
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export { Form, FormItem, FormSection };
|
package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useHeaderHeight } from '@react-navigation/elements';
|
|
2
|
+
import { Portal } from '@rn-primitives/portal';
|
|
3
|
+
import { Stack } from 'expo-router';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import Animated, { FadeIn } from 'react-native-reanimated';
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
LargeTitleHeaderProps,
|
|
10
|
+
NativeStackNavigationOptions,
|
|
11
|
+
NativeStackNavigationSearchBarOptions,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
import { useColorScheme } from '~/lib/useColorScheme';
|
|
15
|
+
|
|
16
|
+
export function LargeTitleHeader(props: LargeTitleHeaderProps) {
|
|
17
|
+
const id = React.useId();
|
|
18
|
+
const { colors } = useColorScheme();
|
|
19
|
+
const headerHeight = useHeaderHeight();
|
|
20
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<Stack.Screen options={propsToScreenOptions(props, colors.background, setIsFocused)} />
|
|
25
|
+
{props.searchBar?.content && isFocused && (
|
|
26
|
+
<Portal name={`large-title:${id}`}>
|
|
27
|
+
<Animated.View
|
|
28
|
+
entering={FadeIn.delay(100)}
|
|
29
|
+
style={{ top: headerHeight + 6 }}
|
|
30
|
+
className="absolute bottom-0 left-0 right-0">
|
|
31
|
+
{props.searchBar?.content}
|
|
32
|
+
</Animated.View>
|
|
33
|
+
</Portal>
|
|
34
|
+
)}
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function propsToScreenOptions(
|
|
40
|
+
props: LargeTitleHeaderProps,
|
|
41
|
+
backgroundColor: string,
|
|
42
|
+
setIsFocused: React.Dispatch<React.SetStateAction<boolean>>
|
|
43
|
+
): NativeStackNavigationOptions {
|
|
44
|
+
return {
|
|
45
|
+
headerLargeTitle: true,
|
|
46
|
+
headerBackButtonMenuEnabled: props.iosBackButtonMenuEnabled,
|
|
47
|
+
headerBackTitle: props.iosBackButtonTitle,
|
|
48
|
+
headerBackTitleVisible: props.iosBackButtonTitleVisible,
|
|
49
|
+
headerBackVisible: props.backVisible,
|
|
50
|
+
headerLargeTitleShadowVisible: props.shadowVisible,
|
|
51
|
+
headerBlurEffect:
|
|
52
|
+
props.iosBlurEffect === 'none' ? undefined : (props.iosBlurEffect ?? 'systemMaterial'),
|
|
53
|
+
headerShadowVisible: props.shadowVisible,
|
|
54
|
+
headerLeft: props.leftView
|
|
55
|
+
? (headerProps) => (
|
|
56
|
+
<View className="flex-row justify-center gap-4">{props.leftView!(headerProps)}</View>
|
|
57
|
+
)
|
|
58
|
+
: undefined,
|
|
59
|
+
headerRight: props.rightView
|
|
60
|
+
? (headerProps) => (
|
|
61
|
+
<View className="flex-row justify-center gap-4">{props.rightView!(headerProps)}</View>
|
|
62
|
+
)
|
|
63
|
+
: undefined,
|
|
64
|
+
headerShown: props.shown,
|
|
65
|
+
headerTitle: props.title,
|
|
66
|
+
headerTransparent: props.iosBlurEffect !== 'none',
|
|
67
|
+
headerLargeStyle: { backgroundColor: props.backgroundColor ?? backgroundColor },
|
|
68
|
+
headerStyle:
|
|
69
|
+
props.iosBlurEffect === 'none'
|
|
70
|
+
? { backgroundColor: props.backgroundColor ?? backgroundColor }
|
|
71
|
+
: undefined,
|
|
72
|
+
headerSearchBarOptions: props.searchBar
|
|
73
|
+
? {
|
|
74
|
+
autoCapitalize: props.searchBar?.autoCapitalize,
|
|
75
|
+
cancelButtonText: props.searchBar?.iosCancelButtonText,
|
|
76
|
+
hideWhenScrolling: props.searchBar?.iosHideWhenScrolling ?? false,
|
|
77
|
+
inputType: props.searchBar?.inputType,
|
|
78
|
+
tintColor: props.searchBar?.iosTintColor,
|
|
79
|
+
onBlur: () => {
|
|
80
|
+
setIsFocused(false);
|
|
81
|
+
props.searchBar?.onBlur?.();
|
|
82
|
+
},
|
|
83
|
+
onCancelButtonPress: props.searchBar?.onCancelButtonPress,
|
|
84
|
+
onChangeText: props.searchBar?.onChangeText
|
|
85
|
+
? (event) => props.searchBar?.onChangeText!(event.nativeEvent.text)
|
|
86
|
+
: undefined,
|
|
87
|
+
onFocus: () => {
|
|
88
|
+
setIsFocused(true);
|
|
89
|
+
props.searchBar?.onFocus?.();
|
|
90
|
+
},
|
|
91
|
+
onSearchButtonPress: props.searchBar?.onSearchButtonPress,
|
|
92
|
+
placeholder: props.searchBar?.placeholder ?? 'Search...',
|
|
93
|
+
ref: props.searchBar?.ref as NativeStackNavigationSearchBarOptions['ref'],
|
|
94
|
+
textColor: props.searchBar?.textColor,
|
|
95
|
+
}
|
|
96
|
+
: undefined,
|
|
97
|
+
...props.screen,
|
|
98
|
+
};
|
|
99
|
+
}
|