nwui-cli 0.3.5 → 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.
Files changed (212) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/build/index.js +15 -3
  3. package/build/install-component.js +121 -34
  4. package/build/login.js +10 -2
  5. package/build/utils/env.js +4 -1
  6. package/my-expo-app-2/app/+html.tsx +46 -0
  7. package/my-expo-app-2/app/+not-found.tsx +33 -0
  8. package/my-expo-app-2/app/_layout.tsx +22 -0
  9. package/my-expo-app-2/app/details.tsx +17 -0
  10. package/my-expo-app-2/app/index.tsx +23 -0
  11. package/my-expo-app-2/app-env.d.ts +2 -0
  12. package/my-expo-app-2/app.json +48 -0
  13. package/my-expo-app-2/assets/adaptive-icon.png +0 -0
  14. package/my-expo-app-2/assets/favicon.png +0 -0
  15. package/my-expo-app-2/assets/icon.png +0 -0
  16. package/my-expo-app-2/assets/splash.png +0 -0
  17. package/my-expo-app-2/babel.config.js +18 -0
  18. package/my-expo-app-2/cesconfig.json +35 -0
  19. package/my-expo-app-2/components/Button.tsx +19 -0
  20. package/my-expo-app-2/components/Container.tsx +9 -0
  21. package/my-expo-app-2/components/EditScreenInfo.tsx +34 -0
  22. package/my-expo-app-2/components/ScreenContent.tsx +25 -0
  23. package/my-expo-app-2/components/nativewindui/ActivityIndicator.tsx +13 -0
  24. package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
  25. package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
  26. package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
  27. package/my-expo-app-2/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
  28. package/my-expo-app-2/components/nativewindui/Alert/Alert.ios.tsx +65 -0
  29. package/my-expo-app-2/components/nativewindui/Alert/Alert.tsx +291 -0
  30. package/my-expo-app-2/components/nativewindui/Alert/index.ts +1 -0
  31. package/my-expo-app-2/components/nativewindui/Alert/types.ts +27 -0
  32. package/my-expo-app-2/components/nativewindui/Badge.tsx +84 -0
  33. package/my-expo-app-2/components/nativewindui/Button.tsx +156 -0
  34. package/my-expo-app-2/components/nativewindui/Checkbox.tsx +61 -0
  35. package/my-expo-app-2/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
  36. package/my-expo-app-2/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
  37. package/my-expo-app-2/components/nativewindui/ContextMenu/index.ts +1 -0
  38. package/my-expo-app-2/components/nativewindui/ContextMenu/types.ts +91 -0
  39. package/my-expo-app-2/components/nativewindui/ContextMenu/utils.ts +14 -0
  40. package/my-expo-app-2/components/nativewindui/DrawerContent.tsx +145 -0
  41. package/my-expo-app-2/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
  42. package/my-expo-app-2/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
  43. package/my-expo-app-2/components/nativewindui/DropdownMenu/index.ts +1 -0
  44. package/my-expo-app-2/components/nativewindui/DropdownMenu/types.ts +93 -0
  45. package/my-expo-app-2/components/nativewindui/DropdownMenu/utils.ts +14 -0
  46. package/my-expo-app-2/components/nativewindui/Form.tsx +125 -0
  47. package/my-expo-app-2/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
  48. package/my-expo-app-2/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
  49. package/my-expo-app-2/components/nativewindui/LargeTitleHeader/index.ts +1 -0
  50. package/my-expo-app-2/components/nativewindui/LargeTitleHeader/types.ts +89 -0
  51. package/my-expo-app-2/components/nativewindui/List.tsx +433 -0
  52. package/my-expo-app-2/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
  53. package/my-expo-app-2/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
  54. package/my-expo-app-2/components/nativewindui/SearchInput/index.tsx +1 -0
  55. package/my-expo-app-2/components/nativewindui/SearchInput/types.ts +12 -0
  56. package/my-expo-app-2/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
  57. package/my-expo-app-2/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
  58. package/my-expo-app-2/components/nativewindui/SegmentedControl/index.ts +1 -0
  59. package/my-expo-app-2/components/nativewindui/SegmentedControl/types.ts +15 -0
  60. package/my-expo-app-2/components/nativewindui/Stepper.tsx +62 -0
  61. package/my-expo-app-2/components/nativewindui/Text.tsx +55 -0
  62. package/my-expo-app-2/components/nativewindui/TextField/TextField.ios.tsx +85 -0
  63. package/my-expo-app-2/components/nativewindui/TextField/TextField.tsx +326 -0
  64. package/my-expo-app-2/components/nativewindui/TextField/index.tsx +1 -0
  65. package/my-expo-app-2/components/nativewindui/TextField/types.ts +26 -0
  66. package/my-expo-app-2/components/nativewindui/Toolbar.tsx +116 -0
  67. package/my-expo-app-2/global.css +3 -0
  68. package/my-expo-app-2/metro.config.js +12 -0
  69. package/my-expo-app-2/package-lock.json +19162 -0
  70. package/my-expo-app-2/package.json +74 -0
  71. package/my-expo-app-2/prettier.config.js +11 -0
  72. package/my-expo-app-2/tailwind.config.js +11 -0
  73. package/my-expo-app-3/app/+html.tsx +46 -0
  74. package/my-expo-app-3/app/+not-found.tsx +33 -0
  75. package/my-expo-app-3/app/_layout.tsx +22 -0
  76. package/my-expo-app-3/app/details.tsx +17 -0
  77. package/my-expo-app-3/app/index.tsx +23 -0
  78. package/my-expo-app-3/app-env.d.ts +2 -0
  79. package/my-expo-app-3/app.json +48 -0
  80. package/my-expo-app-3/assets/adaptive-icon.png +0 -0
  81. package/my-expo-app-3/assets/favicon.png +0 -0
  82. package/my-expo-app-3/assets/icon.png +0 -0
  83. package/my-expo-app-3/assets/splash.png +0 -0
  84. package/my-expo-app-3/babel.config.js +18 -0
  85. package/my-expo-app-3/cesconfig.json +35 -0
  86. package/my-expo-app-3/components/Button.tsx +19 -0
  87. package/my-expo-app-3/components/Container.tsx +9 -0
  88. package/my-expo-app-3/components/EditScreenInfo.tsx +34 -0
  89. package/my-expo-app-3/components/ScreenContent.tsx +25 -0
  90. package/my-expo-app-3/components/nativewindui/ActivityIndicator.tsx +13 -0
  91. package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
  92. package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
  93. package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
  94. package/my-expo-app-3/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
  95. package/my-expo-app-3/components/nativewindui/Alert/Alert.ios.tsx +65 -0
  96. package/my-expo-app-3/components/nativewindui/Alert/Alert.tsx +291 -0
  97. package/my-expo-app-3/components/nativewindui/Alert/index.ts +1 -0
  98. package/my-expo-app-3/components/nativewindui/Alert/types.ts +27 -0
  99. package/my-expo-app-3/components/nativewindui/Badge.tsx +84 -0
  100. package/my-expo-app-3/components/nativewindui/Button.tsx +156 -0
  101. package/my-expo-app-3/components/nativewindui/Checkbox.tsx +61 -0
  102. package/my-expo-app-3/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
  103. package/my-expo-app-3/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
  104. package/my-expo-app-3/components/nativewindui/ContextMenu/index.ts +1 -0
  105. package/my-expo-app-3/components/nativewindui/ContextMenu/types.ts +91 -0
  106. package/my-expo-app-3/components/nativewindui/ContextMenu/utils.ts +14 -0
  107. package/my-expo-app-3/components/nativewindui/DrawerContent.tsx +145 -0
  108. package/my-expo-app-3/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
  109. package/my-expo-app-3/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
  110. package/my-expo-app-3/components/nativewindui/DropdownMenu/index.ts +1 -0
  111. package/my-expo-app-3/components/nativewindui/DropdownMenu/types.ts +93 -0
  112. package/my-expo-app-3/components/nativewindui/DropdownMenu/utils.ts +14 -0
  113. package/my-expo-app-3/components/nativewindui/Form.tsx +125 -0
  114. package/my-expo-app-3/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
  115. package/my-expo-app-3/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
  116. package/my-expo-app-3/components/nativewindui/LargeTitleHeader/index.ts +1 -0
  117. package/my-expo-app-3/components/nativewindui/LargeTitleHeader/types.ts +89 -0
  118. package/my-expo-app-3/components/nativewindui/List.tsx +433 -0
  119. package/my-expo-app-3/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
  120. package/my-expo-app-3/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
  121. package/my-expo-app-3/components/nativewindui/SearchInput/index.tsx +1 -0
  122. package/my-expo-app-3/components/nativewindui/SearchInput/types.ts +12 -0
  123. package/my-expo-app-3/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
  124. package/my-expo-app-3/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
  125. package/my-expo-app-3/components/nativewindui/SegmentedControl/index.ts +1 -0
  126. package/my-expo-app-3/components/nativewindui/SegmentedControl/types.ts +15 -0
  127. package/my-expo-app-3/components/nativewindui/Stepper.tsx +62 -0
  128. package/my-expo-app-3/components/nativewindui/Text.tsx +55 -0
  129. package/my-expo-app-3/components/nativewindui/TextField/TextField.ios.tsx +85 -0
  130. package/my-expo-app-3/components/nativewindui/TextField/TextField.tsx +326 -0
  131. package/my-expo-app-3/components/nativewindui/TextField/index.tsx +1 -0
  132. package/my-expo-app-3/components/nativewindui/TextField/types.ts +26 -0
  133. package/my-expo-app-3/components/nativewindui/Toolbar.tsx +116 -0
  134. package/my-expo-app-3/components/nativewindui/examples/selectable-text.tsx +43 -0
  135. package/my-expo-app-3/components/nativewindui/examples/text.tsx +43 -0
  136. package/my-expo-app-3/global.css +3 -0
  137. package/my-expo-app-3/metro.config.js +12 -0
  138. package/my-expo-app-3/package-lock.json +19141 -0
  139. package/my-expo-app-3/package.json +73 -0
  140. package/my-expo-app-3/prettier.config.js +11 -0
  141. package/my-expo-app-3/tailwind.config.js +11 -0
  142. package/my-expo-app-test-case/app/+html.tsx +46 -0
  143. package/my-expo-app-test-case/app/+not-found.tsx +33 -0
  144. package/my-expo-app-test-case/app/_layout.tsx +22 -0
  145. package/my-expo-app-test-case/app/details.tsx +17 -0
  146. package/my-expo-app-test-case/app/index.tsx +23 -0
  147. package/my-expo-app-test-case/app-env.d.ts +2 -0
  148. package/my-expo-app-test-case/app.json +48 -0
  149. package/my-expo-app-test-case/assets/adaptive-icon.png +0 -0
  150. package/my-expo-app-test-case/assets/favicon.png +0 -0
  151. package/my-expo-app-test-case/assets/icon.png +0 -0
  152. package/my-expo-app-test-case/assets/splash.png +0 -0
  153. package/my-expo-app-test-case/babel.config.js +18 -0
  154. package/my-expo-app-test-case/cesconfig.json +35 -0
  155. package/my-expo-app-test-case/components/Button.tsx +19 -0
  156. package/my-expo-app-test-case/components/Container.tsx +9 -0
  157. package/my-expo-app-test-case/components/EditScreenInfo.tsx +34 -0
  158. package/my-expo-app-test-case/components/ScreenContent.tsx +25 -0
  159. package/my-expo-app-test-case/components/nativewindui/ActivityIndicator.tsx +13 -0
  160. package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.ios.tsx +97 -0
  161. package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/AdaptiveSearchHeader.tsx +264 -0
  162. package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/index.ts +1 -0
  163. package/my-expo-app-test-case/components/nativewindui/AdaptiveSearchHeader/types.ts +95 -0
  164. package/my-expo-app-test-case/components/nativewindui/Alert/Alert.ios.tsx +65 -0
  165. package/my-expo-app-test-case/components/nativewindui/Alert/Alert.tsx +291 -0
  166. package/my-expo-app-test-case/components/nativewindui/Alert/index.ts +1 -0
  167. package/my-expo-app-test-case/components/nativewindui/Alert/types.ts +27 -0
  168. package/my-expo-app-test-case/components/nativewindui/Badge.tsx +84 -0
  169. package/my-expo-app-test-case/components/nativewindui/Button.tsx +156 -0
  170. package/my-expo-app-test-case/components/nativewindui/Checkbox.tsx +61 -0
  171. package/my-expo-app-test-case/components/nativewindui/ContextMenu/ContextMenu.ios.tsx +221 -0
  172. package/my-expo-app-test-case/components/nativewindui/ContextMenu/ContextMenu.tsx +420 -0
  173. package/my-expo-app-test-case/components/nativewindui/ContextMenu/index.ts +1 -0
  174. package/my-expo-app-test-case/components/nativewindui/ContextMenu/types.ts +91 -0
  175. package/my-expo-app-test-case/components/nativewindui/ContextMenu/utils.ts +14 -0
  176. package/my-expo-app-test-case/components/nativewindui/DrawerContent.tsx +145 -0
  177. package/my-expo-app-test-case/components/nativewindui/DropdownMenu/DropdownMenu.ios.tsx +168 -0
  178. package/my-expo-app-test-case/components/nativewindui/DropdownMenu/DropdownMenu.tsx +330 -0
  179. package/my-expo-app-test-case/components/nativewindui/DropdownMenu/index.ts +1 -0
  180. package/my-expo-app-test-case/components/nativewindui/DropdownMenu/types.ts +93 -0
  181. package/my-expo-app-test-case/components/nativewindui/DropdownMenu/utils.ts +14 -0
  182. package/my-expo-app-test-case/components/nativewindui/Form.tsx +125 -0
  183. package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/LargeTitleHeader.ios.tsx +99 -0
  184. package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/LargeTitleHeader.tsx +288 -0
  185. package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/index.ts +1 -0
  186. package/my-expo-app-test-case/components/nativewindui/LargeTitleHeader/types.ts +89 -0
  187. package/my-expo-app-test-case/components/nativewindui/List.tsx +433 -0
  188. package/my-expo-app-test-case/components/nativewindui/SearchInput/SearchInput.ios.tsx +177 -0
  189. package/my-expo-app-test-case/components/nativewindui/SearchInput/SearchInput.tsx +86 -0
  190. package/my-expo-app-test-case/components/nativewindui/SearchInput/index.tsx +1 -0
  191. package/my-expo-app-test-case/components/nativewindui/SearchInput/types.ts +12 -0
  192. package/my-expo-app-test-case/components/nativewindui/SegmentedControl/SegmentedControl.ios.tsx +31 -0
  193. package/my-expo-app-test-case/components/nativewindui/SegmentedControl/SegmentedControl.tsx +55 -0
  194. package/my-expo-app-test-case/components/nativewindui/SegmentedControl/index.ts +1 -0
  195. package/my-expo-app-test-case/components/nativewindui/SegmentedControl/types.ts +15 -0
  196. package/my-expo-app-test-case/components/nativewindui/Stepper.tsx +62 -0
  197. package/my-expo-app-test-case/components/nativewindui/Text.tsx +55 -0
  198. package/my-expo-app-test-case/components/nativewindui/TextField/TextField.ios.tsx +85 -0
  199. package/my-expo-app-test-case/components/nativewindui/TextField/TextField.tsx +326 -0
  200. package/my-expo-app-test-case/components/nativewindui/TextField/index.tsx +1 -0
  201. package/my-expo-app-test-case/components/nativewindui/TextField/types.ts +26 -0
  202. package/my-expo-app-test-case/components/nativewindui/Toolbar.tsx +116 -0
  203. package/my-expo-app-test-case/components/nativewindui/examples/a-user-created-file.tsx +0 -0
  204. package/my-expo-app-test-case/components/nativewindui/examples/selectable-text.tsx +43 -0
  205. package/my-expo-app-test-case/components/nativewindui/examples/text.tsx +43 -0
  206. package/my-expo-app-test-case/global.css +3 -0
  207. package/my-expo-app-test-case/metro.config.js +12 -0
  208. package/my-expo-app-test-case/package-lock.json +19141 -0
  209. package/my-expo-app-test-case/package.json +73 -0
  210. package/my-expo-app-test-case/prettier.config.js +11 -0
  211. package/my-expo-app-test-case/tailwind.config.js +11 -0
  212. package/package.json +4 -3
@@ -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 };