nwui-cli 0.3.6 → 0.4.0-beta.1
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/package.json +2 -2
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FlashList,
|
|
3
|
+
type FlashListProps,
|
|
4
|
+
type ListRenderItem as FlashListRenderItem,
|
|
5
|
+
type ListRenderItemInfo,
|
|
6
|
+
} from '@shopify/flash-list';
|
|
7
|
+
import { cva } from 'class-variance-authority';
|
|
8
|
+
import { cssInterop } from 'nativewind';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import {
|
|
11
|
+
Platform,
|
|
12
|
+
PressableProps,
|
|
13
|
+
StyleProp,
|
|
14
|
+
StyleSheet,
|
|
15
|
+
TextStyle,
|
|
16
|
+
View,
|
|
17
|
+
ViewProps,
|
|
18
|
+
ViewStyle,
|
|
19
|
+
} from 'react-native';
|
|
20
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
21
|
+
|
|
22
|
+
import { Button } from '~/components/nativewindui/Button';
|
|
23
|
+
import { Text, TextClassContext } from '~/components/nativewindui/Text';
|
|
24
|
+
import { cn } from '~/lib/cn';
|
|
25
|
+
|
|
26
|
+
cssInterop(FlashList, {
|
|
27
|
+
className: 'style',
|
|
28
|
+
contentContainerClassName: 'contentContainerStyle',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
type ListDataItem = string | { title: string; subTitle?: string };
|
|
32
|
+
type ListVariant = 'insets' | 'full-width';
|
|
33
|
+
|
|
34
|
+
type ListRef<T extends ListDataItem> = React.Ref<FlashList<T>>;
|
|
35
|
+
|
|
36
|
+
type ListRenderItemProps<T extends ListDataItem> = ListRenderItemInfo<T> & {
|
|
37
|
+
variant?: ListVariant;
|
|
38
|
+
isFirstInSection?: boolean;
|
|
39
|
+
isLastInSection?: boolean;
|
|
40
|
+
sectionHeaderAsGap?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type ListProps<T extends ListDataItem> = Omit<FlashListProps<T>, 'renderItem'> & {
|
|
44
|
+
renderItem?: ListRenderItem<T>;
|
|
45
|
+
variant?: ListVariant;
|
|
46
|
+
sectionHeaderAsGap?: boolean;
|
|
47
|
+
rootClassName?: string;
|
|
48
|
+
rootStyle?: StyleProp<ViewStyle>;
|
|
49
|
+
};
|
|
50
|
+
type ListRenderItem<T extends ListDataItem> = (
|
|
51
|
+
props: ListRenderItemProps<T>
|
|
52
|
+
) => ReturnType<FlashListRenderItem<T>>;
|
|
53
|
+
|
|
54
|
+
const rootVariants = cva('min-h-2 flex-1', {
|
|
55
|
+
variants: {
|
|
56
|
+
variant: {
|
|
57
|
+
insets: 'ios:px-4',
|
|
58
|
+
'full-width': 'ios:bg-card ios:dark:bg-background',
|
|
59
|
+
},
|
|
60
|
+
sectionHeaderAsGap: {
|
|
61
|
+
true: '',
|
|
62
|
+
false: '',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
compoundVariants: [
|
|
66
|
+
{
|
|
67
|
+
variant: 'full-width',
|
|
68
|
+
sectionHeaderAsGap: true,
|
|
69
|
+
className: 'bg-card dark:bg-background',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
defaultVariants: {
|
|
73
|
+
variant: 'full-width',
|
|
74
|
+
sectionHeaderAsGap: false,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function ListComponent<T extends ListDataItem>(
|
|
79
|
+
{
|
|
80
|
+
variant = 'full-width',
|
|
81
|
+
rootClassName,
|
|
82
|
+
rootStyle,
|
|
83
|
+
contentContainerClassName,
|
|
84
|
+
renderItem,
|
|
85
|
+
data,
|
|
86
|
+
sectionHeaderAsGap = false,
|
|
87
|
+
contentInsetAdjustmentBehavior = 'automatic',
|
|
88
|
+
...props
|
|
89
|
+
}: ListProps<T>,
|
|
90
|
+
ref: ListRef<T>
|
|
91
|
+
) {
|
|
92
|
+
const insets = useSafeAreaInsets();
|
|
93
|
+
return (
|
|
94
|
+
<View
|
|
95
|
+
className={cn(
|
|
96
|
+
rootVariants({
|
|
97
|
+
variant,
|
|
98
|
+
sectionHeaderAsGap,
|
|
99
|
+
}),
|
|
100
|
+
rootClassName
|
|
101
|
+
)}
|
|
102
|
+
style={rootStyle}>
|
|
103
|
+
<FlashList
|
|
104
|
+
data={data}
|
|
105
|
+
contentInsetAdjustmentBehavior={contentInsetAdjustmentBehavior}
|
|
106
|
+
renderItem={renderItemWithVariant(renderItem, variant, data, sectionHeaderAsGap)}
|
|
107
|
+
contentContainerClassName={cn(
|
|
108
|
+
variant === 'insets' && (!data || (typeof data?.[0] !== 'string' && 'pt-4')),
|
|
109
|
+
contentContainerClassName
|
|
110
|
+
)}
|
|
111
|
+
contentContainerStyle={{
|
|
112
|
+
paddingBottom: Platform.select({
|
|
113
|
+
ios:
|
|
114
|
+
!contentInsetAdjustmentBehavior || contentInsetAdjustmentBehavior === 'never'
|
|
115
|
+
? insets.bottom + 16
|
|
116
|
+
: 0,
|
|
117
|
+
default: insets.bottom,
|
|
118
|
+
}),
|
|
119
|
+
}}
|
|
120
|
+
getItemType={getItemType}
|
|
121
|
+
showsVerticalScrollIndicator={false}
|
|
122
|
+
{...props}
|
|
123
|
+
ref={ref}
|
|
124
|
+
/>
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getItemType<T>(item: T) {
|
|
130
|
+
return typeof item === 'string' ? 'sectioHeader' : 'row';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderItemWithVariant<T extends ListDataItem>(
|
|
134
|
+
renderItem: ListRenderItem<T> | null | undefined,
|
|
135
|
+
variant: ListVariant,
|
|
136
|
+
data: readonly T[] | null | undefined,
|
|
137
|
+
sectionHeaderAsGap?: boolean
|
|
138
|
+
) {
|
|
139
|
+
return (args: ListRenderItemProps<T>) => {
|
|
140
|
+
const previousItem = data?.[args.index - 1];
|
|
141
|
+
const nextItem = data?.[args.index + 1];
|
|
142
|
+
return renderItem
|
|
143
|
+
? renderItem({
|
|
144
|
+
...args,
|
|
145
|
+
variant,
|
|
146
|
+
isFirstInSection: !previousItem || typeof previousItem === 'string',
|
|
147
|
+
isLastInSection: !nextItem || typeof nextItem === 'string',
|
|
148
|
+
sectionHeaderAsGap,
|
|
149
|
+
})
|
|
150
|
+
: null;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const List = React.forwardRef(ListComponent) as <T extends ListDataItem>(
|
|
155
|
+
props: ListProps<T> & { ref?: ListRef<T> }
|
|
156
|
+
) => React.ReactElement;
|
|
157
|
+
|
|
158
|
+
function isPressable(props: PressableProps) {
|
|
159
|
+
return (
|
|
160
|
+
('onPress' in props && props.onPress) ||
|
|
161
|
+
('onLongPress' in props && props.onLongPress) ||
|
|
162
|
+
('onPressIn' in props && props.onPressIn) ||
|
|
163
|
+
('onPressOut' in props && props.onPressOut) ||
|
|
164
|
+
('onLongPress' in props && props.onLongPress)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type ListItemProps<T extends ListDataItem> = PressableProps &
|
|
169
|
+
ListRenderItemProps<T> & {
|
|
170
|
+
androidRootClassName?: string;
|
|
171
|
+
titleClassName?: string;
|
|
172
|
+
titleStyle?: StyleProp<TextStyle>;
|
|
173
|
+
textNumberOfLines?: number;
|
|
174
|
+
subTitleClassName?: string;
|
|
175
|
+
subTitleStyle?: StyleProp<TextStyle>;
|
|
176
|
+
subTitleNumberOfLines?: number;
|
|
177
|
+
textContentClassName?: string;
|
|
178
|
+
leftView?: React.ReactNode;
|
|
179
|
+
rightView?: React.ReactNode;
|
|
180
|
+
removeSeparator?: boolean;
|
|
181
|
+
};
|
|
182
|
+
type ListItemRef = React.Ref<View>;
|
|
183
|
+
|
|
184
|
+
const itemVariants = cva('ios:gap-0 flex-row gap-0 bg-card', {
|
|
185
|
+
variants: {
|
|
186
|
+
variant: {
|
|
187
|
+
insets: 'ios:bg-card bg-card/70',
|
|
188
|
+
'full-width': 'bg-card dark:bg-background',
|
|
189
|
+
},
|
|
190
|
+
sectionHeaderAsGap: {
|
|
191
|
+
true: '',
|
|
192
|
+
false: '',
|
|
193
|
+
},
|
|
194
|
+
isFirstItem: {
|
|
195
|
+
true: '',
|
|
196
|
+
false: '',
|
|
197
|
+
},
|
|
198
|
+
isFirstInSection: {
|
|
199
|
+
true: '',
|
|
200
|
+
false: '',
|
|
201
|
+
},
|
|
202
|
+
removeSeparator: {
|
|
203
|
+
true: '',
|
|
204
|
+
false: '',
|
|
205
|
+
},
|
|
206
|
+
isLastInSection: {
|
|
207
|
+
true: '',
|
|
208
|
+
false: '',
|
|
209
|
+
},
|
|
210
|
+
disabled: {
|
|
211
|
+
true: 'opacity-70',
|
|
212
|
+
false: 'opacity-100',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
compoundVariants: [
|
|
216
|
+
{
|
|
217
|
+
variant: 'insets',
|
|
218
|
+
sectionHeaderAsGap: true,
|
|
219
|
+
className: 'ios:dark:bg-card dark:bg-card/70',
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
variant: 'insets',
|
|
223
|
+
isFirstInSection: true,
|
|
224
|
+
className: 'ios:rounded-t-[10px]',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
variant: 'insets',
|
|
228
|
+
isLastInSection: true,
|
|
229
|
+
className: 'ios:rounded-b-[10px]',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
removeSeparator: false,
|
|
233
|
+
isLastInSection: true,
|
|
234
|
+
className: 'ios:border-b-0 border-b border-border/25 dark:border-border/80',
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
variant: 'insets',
|
|
238
|
+
isFirstItem: true,
|
|
239
|
+
className: 'border-border/40 border-t',
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
defaultVariants: {
|
|
243
|
+
variant: 'insets',
|
|
244
|
+
sectionHeaderAsGap: false,
|
|
245
|
+
isFirstInSection: false,
|
|
246
|
+
isLastInSection: false,
|
|
247
|
+
disabled: false,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
function ListItemComponent<T extends ListDataItem>(
|
|
252
|
+
{
|
|
253
|
+
item,
|
|
254
|
+
isFirstInSection,
|
|
255
|
+
isLastInSection,
|
|
256
|
+
index,
|
|
257
|
+
variant,
|
|
258
|
+
className,
|
|
259
|
+
androidRootClassName,
|
|
260
|
+
titleClassName,
|
|
261
|
+
titleStyle,
|
|
262
|
+
textNumberOfLines,
|
|
263
|
+
subTitleStyle,
|
|
264
|
+
subTitleClassName,
|
|
265
|
+
subTitleNumberOfLines,
|
|
266
|
+
textContentClassName,
|
|
267
|
+
sectionHeaderAsGap,
|
|
268
|
+
removeSeparator = false,
|
|
269
|
+
leftView,
|
|
270
|
+
rightView,
|
|
271
|
+
disabled,
|
|
272
|
+
...props
|
|
273
|
+
}: ListItemProps<T>,
|
|
274
|
+
ref: ListItemRef
|
|
275
|
+
) {
|
|
276
|
+
if (typeof item === 'string') {
|
|
277
|
+
console.log(
|
|
278
|
+
'List.tsx',
|
|
279
|
+
'ListItemComponent',
|
|
280
|
+
"Invalid item of type 'string' was provided. Use ListSectionHeader instead."
|
|
281
|
+
);
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
return (
|
|
285
|
+
<>
|
|
286
|
+
<Button
|
|
287
|
+
disabled={disabled || !isPressable(props)}
|
|
288
|
+
variant="plain"
|
|
289
|
+
size="none"
|
|
290
|
+
unstable_pressDelay={100}
|
|
291
|
+
androidRootClassName={androidRootClassName}
|
|
292
|
+
className={itemVariants({
|
|
293
|
+
variant,
|
|
294
|
+
sectionHeaderAsGap,
|
|
295
|
+
isFirstInSection,
|
|
296
|
+
isLastInSection,
|
|
297
|
+
disabled,
|
|
298
|
+
className,
|
|
299
|
+
removeSeparator,
|
|
300
|
+
})}
|
|
301
|
+
{...props}
|
|
302
|
+
ref={ref}>
|
|
303
|
+
<TextClassContext.Provider value="font-normal leading-5">
|
|
304
|
+
{!!leftView && <View>{leftView}</View>}
|
|
305
|
+
<View
|
|
306
|
+
className={cn(
|
|
307
|
+
'h-full flex-1 flex-row',
|
|
308
|
+
!item.subTitle ? 'ios:py-3 py-[18px]' : 'ios:py-2 py-2',
|
|
309
|
+
!leftView && 'ml-4',
|
|
310
|
+
!rightView && 'pr-4',
|
|
311
|
+
!removeSeparator &&
|
|
312
|
+
(!isLastInSection || variant === 'full-width') &&
|
|
313
|
+
'ios:border-b ios:border-border/80',
|
|
314
|
+
!removeSeparator &&
|
|
315
|
+
isFirstInSection &&
|
|
316
|
+
variant === 'full-width' &&
|
|
317
|
+
'ios:border-t ios:border-border/80'
|
|
318
|
+
)}>
|
|
319
|
+
<View className={cn('flex-1', textContentClassName)}>
|
|
320
|
+
<Text numberOfLines={textNumberOfLines} style={titleStyle} className={titleClassName}>
|
|
321
|
+
{item.title}
|
|
322
|
+
</Text>
|
|
323
|
+
{!!item.subTitle && (
|
|
324
|
+
<Text
|
|
325
|
+
numberOfLines={subTitleNumberOfLines}
|
|
326
|
+
variant="subhead"
|
|
327
|
+
style={subTitleStyle}
|
|
328
|
+
className={cn('text-muted-foreground', subTitleClassName)}>
|
|
329
|
+
{item.subTitle}
|
|
330
|
+
</Text>
|
|
331
|
+
)}
|
|
332
|
+
</View>
|
|
333
|
+
{!!rightView && <View>{rightView}</View>}
|
|
334
|
+
</View>
|
|
335
|
+
</TextClassContext.Provider>
|
|
336
|
+
</Button>
|
|
337
|
+
{!removeSeparator && Platform.OS !== 'ios' && !isLastInSection && (
|
|
338
|
+
<View className={cn(variant === 'insets' && 'px-4')}>
|
|
339
|
+
<View className="bg-border/25 dark:bg-border/80 h-px" />
|
|
340
|
+
</View>
|
|
341
|
+
)}
|
|
342
|
+
</>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const ListItem = React.forwardRef(ListItemComponent) as <T extends ListDataItem>(
|
|
347
|
+
props: ListItemProps<T> & { ref?: ListItemRef }
|
|
348
|
+
) => React.ReactElement;
|
|
349
|
+
|
|
350
|
+
type ListSectionHeaderProps<T extends ListDataItem> = ViewProps &
|
|
351
|
+
ListRenderItemProps<T> & {
|
|
352
|
+
textClassName?: string;
|
|
353
|
+
};
|
|
354
|
+
type ListSectionHeaderRef = React.Ref<View>;
|
|
355
|
+
|
|
356
|
+
function ListSectionHeaderComponent<T extends ListDataItem>(
|
|
357
|
+
{
|
|
358
|
+
item,
|
|
359
|
+
isFirstInSection,
|
|
360
|
+
isLastInSection,
|
|
361
|
+
index,
|
|
362
|
+
variant,
|
|
363
|
+
className,
|
|
364
|
+
textClassName,
|
|
365
|
+
sectionHeaderAsGap,
|
|
366
|
+
...props
|
|
367
|
+
}: ListSectionHeaderProps<T>,
|
|
368
|
+
ref: ListSectionHeaderRef
|
|
369
|
+
) {
|
|
370
|
+
if (typeof item !== 'string') {
|
|
371
|
+
console.log(
|
|
372
|
+
'List.tsx',
|
|
373
|
+
'ListSectionHeaderComponent',
|
|
374
|
+
"Invalid item provided. Expected type 'string'. Use ListItem instead."
|
|
375
|
+
);
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (sectionHeaderAsGap) {
|
|
380
|
+
return (
|
|
381
|
+
<View
|
|
382
|
+
className={cn(
|
|
383
|
+
'bg-background',
|
|
384
|
+
Platform.OS !== 'ios' && 'border-border/25 dark:border-border/80 border-b',
|
|
385
|
+
className
|
|
386
|
+
)}
|
|
387
|
+
{...props}
|
|
388
|
+
ref={ref}>
|
|
389
|
+
<View className="h-8" />
|
|
390
|
+
</View>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
return (
|
|
394
|
+
<View
|
|
395
|
+
className={cn(
|
|
396
|
+
'ios:pb-1 pb-4 pl-4 pt-4',
|
|
397
|
+
Platform.OS !== 'ios' && 'border-border/25 dark:border-border/80 border-b',
|
|
398
|
+
variant === 'full-width' ? 'bg-card dark:bg-background' : 'bg-background',
|
|
399
|
+
className
|
|
400
|
+
)}
|
|
401
|
+
{...props}
|
|
402
|
+
ref={ref}>
|
|
403
|
+
<Text
|
|
404
|
+
variant={Platform.select({ ios: 'footnote', default: 'body' })}
|
|
405
|
+
className={cn('ios:uppercase ios:text-muted-foreground', textClassName)}>
|
|
406
|
+
{item}
|
|
407
|
+
</Text>
|
|
408
|
+
</View>
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const ListSectionHeader = React.forwardRef(ListSectionHeaderComponent) as <T extends ListDataItem>(
|
|
413
|
+
props: ListSectionHeaderProps<T> & { ref?: ListSectionHeaderRef }
|
|
414
|
+
) => React.ReactElement;
|
|
415
|
+
|
|
416
|
+
const ESTIMATED_ITEM_HEIGHT = {
|
|
417
|
+
titleOnly: Platform.select({ ios: 45, default: 57 }),
|
|
418
|
+
withSubTitle: 56,
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
function getStickyHeaderIndices<T extends ListDataItem>(data: T[]) {
|
|
422
|
+
if (!data) return [];
|
|
423
|
+
const indices: number[] = [];
|
|
424
|
+
for (let i = 0; i < data.length; i++) {
|
|
425
|
+
if (typeof data[i] === 'string') {
|
|
426
|
+
indices.push(i);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return indices;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export { ESTIMATED_ITEM_HEIGHT, List, ListItem, ListSectionHeader, getStickyHeaderIndices };
|
|
433
|
+
export type { ListDataItem, ListItemProps, ListProps, ListRenderItemInfo, ListSectionHeaderProps };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { useAugmentedRef, useControllableState } from '@rn-primitives/hooks';
|
|
2
|
+
import { Icon } from '@roninoss/icons';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Pressable,
|
|
6
|
+
TextInput,
|
|
7
|
+
View,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
type NativeSyntheticEvent,
|
|
10
|
+
type TextInputFocusEventData,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import Animated, {
|
|
13
|
+
measure,
|
|
14
|
+
useAnimatedRef,
|
|
15
|
+
useAnimatedStyle,
|
|
16
|
+
useDerivedValue,
|
|
17
|
+
withTiming,
|
|
18
|
+
} from 'react-native-reanimated';
|
|
19
|
+
|
|
20
|
+
import type { SearchInputProps } from './types';
|
|
21
|
+
|
|
22
|
+
import { Text } from '~/components/nativewindui/Text';
|
|
23
|
+
|
|
24
|
+
import { cn } from '~/lib/cn';
|
|
25
|
+
import { useColorScheme } from '~/lib/useColorScheme';
|
|
26
|
+
|
|
27
|
+
// Add as class when possible: https://github.com/marklawlor/nativewind/issues/522
|
|
28
|
+
const BORDER_CURVE: ViewStyle = {
|
|
29
|
+
borderCurve: 'continuous',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const SearchInput = React.forwardRef<React.ElementRef<typeof TextInput>, SearchInputProps>(
|
|
33
|
+
(
|
|
34
|
+
{
|
|
35
|
+
value: valueProp,
|
|
36
|
+
onChangeText: onChangeTextProp,
|
|
37
|
+
onFocus: onFocusProp,
|
|
38
|
+
placeholder = 'Search...',
|
|
39
|
+
cancelText = 'Cancel',
|
|
40
|
+
containerClassName,
|
|
41
|
+
iconContainerClassName,
|
|
42
|
+
className,
|
|
43
|
+
iconColor,
|
|
44
|
+
...props
|
|
45
|
+
},
|
|
46
|
+
ref
|
|
47
|
+
) => {
|
|
48
|
+
const { colors } = useColorScheme();
|
|
49
|
+
const inputRef = useAugmentedRef({ ref, methods: { focus, blur, clear } });
|
|
50
|
+
const [showCancel, setShowCancel] = React.useState(false);
|
|
51
|
+
const showCancelDerivedValue = useDerivedValue(() => showCancel, [showCancel]);
|
|
52
|
+
const animatedRef = useAnimatedRef();
|
|
53
|
+
|
|
54
|
+
const [value = '', onChangeText] = useControllableState({
|
|
55
|
+
prop: valueProp,
|
|
56
|
+
defaultProp: valueProp ?? '',
|
|
57
|
+
onChange: onChangeTextProp,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const rootStyle = useAnimatedStyle(() => {
|
|
61
|
+
if (_WORKLET) {
|
|
62
|
+
// safely use measure
|
|
63
|
+
const measurement = measure(animatedRef);
|
|
64
|
+
return {
|
|
65
|
+
paddingRight: showCancelDerivedValue.value
|
|
66
|
+
? withTiming(measurement?.width ?? cancelText.length * 11.2)
|
|
67
|
+
: withTiming(0),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
paddingRight: showCancelDerivedValue.value
|
|
72
|
+
? withTiming(cancelText.length * 11.2)
|
|
73
|
+
: withTiming(0),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const buttonStyle3 = useAnimatedStyle(() => {
|
|
77
|
+
if (_WORKLET) {
|
|
78
|
+
// safely use measure
|
|
79
|
+
const measurement = measure(animatedRef);
|
|
80
|
+
return {
|
|
81
|
+
position: 'absolute',
|
|
82
|
+
right: 0,
|
|
83
|
+
opacity: showCancelDerivedValue.value ? withTiming(1) : withTiming(0),
|
|
84
|
+
transform: [
|
|
85
|
+
{
|
|
86
|
+
translateX: showCancelDerivedValue.value
|
|
87
|
+
? withTiming(0)
|
|
88
|
+
: measurement?.width
|
|
89
|
+
? withTiming(measurement.width)
|
|
90
|
+
: cancelText.length * 11.2,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
position: 'absolute',
|
|
97
|
+
right: 0,
|
|
98
|
+
opacity: showCancelDerivedValue.value ? withTiming(1) : withTiming(0),
|
|
99
|
+
transform: [
|
|
100
|
+
{
|
|
101
|
+
translateX: showCancelDerivedValue.value
|
|
102
|
+
? withTiming(0)
|
|
103
|
+
: withTiming(cancelText.length * 11.2),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
function focus() {
|
|
110
|
+
inputRef.current?.focus();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function blur() {
|
|
114
|
+
inputRef.current?.blur();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function clear() {
|
|
118
|
+
onChangeText('');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onFocus(e: NativeSyntheticEvent<TextInputFocusEventData>) {
|
|
122
|
+
setShowCancel(true);
|
|
123
|
+
onFocusProp?.(e);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Animated.View className="flex-row items-center" style={rootStyle}>
|
|
128
|
+
<Animated.View
|
|
129
|
+
style={BORDER_CURVE}
|
|
130
|
+
className={cn('flex-1 flex-row rounded-lg bg-card', containerClassName)}>
|
|
131
|
+
<View
|
|
132
|
+
className={cn(
|
|
133
|
+
'absolute bottom-0 left-0 top-0 z-50 justify-center pl-1.5',
|
|
134
|
+
iconContainerClassName
|
|
135
|
+
)}>
|
|
136
|
+
<Icon color={iconColor ?? colors.grey3} name="magnify" size={22} />
|
|
137
|
+
</View>
|
|
138
|
+
<TextInput
|
|
139
|
+
ref={inputRef}
|
|
140
|
+
placeholder={placeholder}
|
|
141
|
+
className={cn(
|
|
142
|
+
!showCancel && 'active:bg-muted/5 dark:active:bg-muted/20',
|
|
143
|
+
'flex-1 rounded-lg py-2 pl-8 pr-1 text-[17px] text-foreground',
|
|
144
|
+
className
|
|
145
|
+
)}
|
|
146
|
+
value={value}
|
|
147
|
+
onChangeText={onChangeText}
|
|
148
|
+
onFocus={onFocus}
|
|
149
|
+
clearButtonMode="while-editing"
|
|
150
|
+
role="searchbox"
|
|
151
|
+
{...props}
|
|
152
|
+
/>
|
|
153
|
+
</Animated.View>
|
|
154
|
+
<Animated.View
|
|
155
|
+
ref={animatedRef}
|
|
156
|
+
style={buttonStyle3}
|
|
157
|
+
pointerEvents={!showCancel ? 'none' : 'auto'}>
|
|
158
|
+
<Pressable
|
|
159
|
+
onPress={() => {
|
|
160
|
+
onChangeText('');
|
|
161
|
+
inputRef.current?.blur();
|
|
162
|
+
setShowCancel(false);
|
|
163
|
+
}}
|
|
164
|
+
disabled={!showCancel}
|
|
165
|
+
pointerEvents={!showCancel ? 'none' : 'auto'}
|
|
166
|
+
className="flex-1 justify-center active:opacity-50">
|
|
167
|
+
<Text className="px-2 text-primary">{cancelText}</Text>
|
|
168
|
+
</Pressable>
|
|
169
|
+
</Animated.View>
|
|
170
|
+
</Animated.View>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
SearchInput.displayName = 'SearchInput';
|
|
176
|
+
|
|
177
|
+
export { SearchInput };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { useAugmentedRef, useControllableState } from '@rn-primitives/hooks';
|
|
2
|
+
import { Icon } from '@roninoss/icons';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Pressable, TextInput, View } from 'react-native';
|
|
5
|
+
import Animated, { FadeIn, FadeOut } from 'react-native-reanimated';
|
|
6
|
+
|
|
7
|
+
import type { SearchInputProps } from './types';
|
|
8
|
+
|
|
9
|
+
import { Button } from '~/components/nativewindui/Button';
|
|
10
|
+
import { cn } from '~/lib/cn';
|
|
11
|
+
import { useColorScheme } from '~/lib/useColorScheme';
|
|
12
|
+
|
|
13
|
+
const SearchInput = React.forwardRef<React.ElementRef<typeof TextInput>, SearchInputProps>(
|
|
14
|
+
(
|
|
15
|
+
{
|
|
16
|
+
value: valueProp,
|
|
17
|
+
onChangeText: onChangeTextProp,
|
|
18
|
+
placeholder = 'Search...',
|
|
19
|
+
cancelText = 'Cancel',
|
|
20
|
+
containerClassName,
|
|
21
|
+
iconContainerClassName,
|
|
22
|
+
className,
|
|
23
|
+
iconColor,
|
|
24
|
+
...props
|
|
25
|
+
},
|
|
26
|
+
ref
|
|
27
|
+
) => {
|
|
28
|
+
const { colors } = useColorScheme();
|
|
29
|
+
const inputRef = useAugmentedRef({ ref, methods: { focus, blur, clear } });
|
|
30
|
+
const [value = '', onChangeText] = useControllableState({
|
|
31
|
+
prop: valueProp,
|
|
32
|
+
defaultProp: valueProp ?? '',
|
|
33
|
+
onChange: onChangeTextProp,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
function focus() {
|
|
37
|
+
inputRef.current?.focus();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function blur() {
|
|
41
|
+
inputRef.current?.blur();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function clear() {
|
|
45
|
+
onChangeText('');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Button
|
|
50
|
+
variant="plain"
|
|
51
|
+
className={cn(
|
|
52
|
+
'android:gap-0 android:h-14 flex-row items-center rounded-full bg-card px-2',
|
|
53
|
+
containerClassName
|
|
54
|
+
)}
|
|
55
|
+
onPress={focus}>
|
|
56
|
+
<View className={cn('p-2', iconContainerClassName)} pointerEvents="none">
|
|
57
|
+
<Icon color={iconColor ?? colors.grey2} name="magnify" size={24} />
|
|
58
|
+
</View>
|
|
59
|
+
|
|
60
|
+
<View className="flex-1" pointerEvents="none">
|
|
61
|
+
<TextInput
|
|
62
|
+
ref={inputRef}
|
|
63
|
+
placeholder={placeholder}
|
|
64
|
+
className={cn('flex-1 rounded-r-full p-2 text-[17px] text-foreground', className)}
|
|
65
|
+
placeholderTextColor={colors.grey2}
|
|
66
|
+
value={value}
|
|
67
|
+
onChangeText={onChangeText}
|
|
68
|
+
role="searchbox"
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
71
|
+
</View>
|
|
72
|
+
{!!value && (
|
|
73
|
+
<Animated.View entering={FadeIn} exiting={FadeOut.duration(150)}>
|
|
74
|
+
<Pressable className="p-2" onPress={clear}>
|
|
75
|
+
<Icon color={colors.grey2} name="close" size={24} />
|
|
76
|
+
</Pressable>
|
|
77
|
+
</Animated.View>
|
|
78
|
+
)}
|
|
79
|
+
</Button>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
SearchInput.displayName = 'SearchInput';
|
|
85
|
+
|
|
86
|
+
export { SearchInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SearchInput';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TextInput, TextInputProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
type SearchInputProps = TextInputProps & {
|
|
4
|
+
containerClassName?: string;
|
|
5
|
+
iconContainerClassName?: string;
|
|
6
|
+
cancelText?: string;
|
|
7
|
+
iconColor?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type SearchInputRef = TextInput;
|
|
11
|
+
|
|
12
|
+
export type { SearchInputProps, SearchInputRef };
|