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,221 @@
1
+ import { ICON_MAPPING, type MaterialIconName } from '@roninoss/icons';
2
+ import { cssInterop } from 'nativewind';
3
+ import * as React from 'react';
4
+ import { View } from 'react-native';
5
+ import {
6
+ ContextMenuView,
7
+ MenuAttributes,
8
+ MenuConfig,
9
+ MenuElementConfig,
10
+ OnPressMenuItemEvent,
11
+ } from 'react-native-ios-context-menu';
12
+
13
+ import type {
14
+ ContextItem,
15
+ ContextMenuConfig,
16
+ ContextMenuProps,
17
+ ContextMenuRef,
18
+ ContextSubMenu,
19
+ } from './types';
20
+
21
+ cssInterop(ContextMenuView, {
22
+ className: 'style',
23
+ });
24
+
25
+ const PREVIEW_CONFIG = {
26
+ previewSize: 'INHERIT',
27
+ preferredCommitStyle: 'dismiss',
28
+ isResizeAnimated: true,
29
+ previewType: 'CUSTOM',
30
+ } as const;
31
+
32
+ function getAuxiliaryPreviewPosition(position: 'start' | 'center' | 'end') {
33
+ switch (position) {
34
+ case 'start':
35
+ return 'targetLeading';
36
+ case 'center':
37
+ return 'targetCenter';
38
+ case 'end':
39
+ return 'targetTrailing';
40
+ }
41
+ }
42
+
43
+ function getAuxiliaryPreviewConfig(position: 'start' | 'center' | 'end') {
44
+ return {
45
+ verticalAnchorPosition: 'automatic',
46
+ horizontalAlignment: getAuxiliaryPreviewPosition(position),
47
+ transitionConfigEntrance: {
48
+ mode: 'syncedToMenuEntranceTransition',
49
+ shouldAnimateSize: false,
50
+ },
51
+ transitionExitPreset: {
52
+ mode: 'zoomAndSlide',
53
+ },
54
+ } as const;
55
+ }
56
+
57
+ const ContextMenu = React.forwardRef<ContextMenuRef, ContextMenuProps>(
58
+ (
59
+ {
60
+ items,
61
+ title,
62
+ iOSItemSize = 'large',
63
+ onItemPress,
64
+ enabled = true,
65
+ iosRenderPreview,
66
+ iosOnPressMenuPreview,
67
+ renderAuxiliaryPreview,
68
+ auxiliaryPreviewPosition = 'start',
69
+ materialPortalHost: _materialPortalHost,
70
+ materialSideOffset: _materialSideOffset,
71
+ materialAlignOffset: _materialAlignOffset,
72
+ materialAlign: _materialAlign,
73
+ materialWidth: _materialWidth,
74
+ materialMinWidth: _materialMinWidth,
75
+ materialLoadingText: _materialLoadingText,
76
+ materialSubMenuTitlePlaceholder: _materialSubMenuTitlePlaceholder,
77
+ materialOverlayClassName: _materialOverlayClassName,
78
+ ...props
79
+ },
80
+ ref
81
+ ) => {
82
+ return (
83
+ <View>
84
+ <ContextMenuView
85
+ ref={ref as React.LegacyRef<ContextMenuView>}
86
+ isContextMenuEnabled={enabled}
87
+ menuConfig={toConfigMenu(items, iOSItemSize, title)}
88
+ onPressMenuItem={toOnPressMenuItem(onItemPress)}
89
+ onPressMenuPreview={iosOnPressMenuPreview}
90
+ shouldCleanupOnComponentWillUnmountForAuxPreview
91
+ previewConfig={!iosRenderPreview ? undefined : PREVIEW_CONFIG}
92
+ renderPreview={iosRenderPreview}
93
+ shouldPreventLongPressGestureFromPropagating
94
+ lazyPreview={!!iosRenderPreview}
95
+ auxiliaryPreviewConfig={
96
+ !renderAuxiliaryPreview
97
+ ? undefined
98
+ : getAuxiliaryPreviewConfig(auxiliaryPreviewPosition)
99
+ }
100
+ isAuxiliaryPreviewEnabled={!!renderAuxiliaryPreview}
101
+ renderAuxiliaryPreview={renderAuxiliaryPreview}
102
+ {...props}
103
+ />
104
+ </View>
105
+ );
106
+ }
107
+ );
108
+
109
+ ContextMenu.displayName = 'ContextMenu';
110
+
111
+ export { ContextMenu };
112
+
113
+ function toOnPressMenuItem(onItemPress: ContextMenuProps['onItemPress']): OnPressMenuItemEvent {
114
+ return ({ nativeEvent, isUsingActionSheetFallback }) => {
115
+ onItemPress?.(
116
+ {
117
+ actionKey: nativeEvent.actionKey,
118
+ title: nativeEvent.actionTitle,
119
+ subTitle: nativeEvent.actionSubtitle,
120
+ state: nativeEvent.menuState ? { checked: nativeEvent.menuState === 'on' } : undefined,
121
+ destructive: nativeEvent.menuAttributes?.includes('destructive'),
122
+ disabled: nativeEvent.menuAttributes?.includes('disabled'),
123
+ hidden: nativeEvent.menuAttributes?.includes('hidden'),
124
+ keepOpenOnPress: nativeEvent.menuAttributes?.includes('keepsMenuPresented'),
125
+ loading: false,
126
+ },
127
+ isUsingActionSheetFallback
128
+ );
129
+ };
130
+ }
131
+
132
+ function toConfigMenu(
133
+ items: ContextMenuConfig['items'],
134
+ iOSItemSize: ContextMenuConfig['iOSItemSize'],
135
+ title: ContextMenuConfig['title']
136
+ ): MenuConfig {
137
+ return {
138
+ menuTitle: title ?? '',
139
+ menuPreferredElementSize: iOSItemSize,
140
+ menuItems: items.map((item) => {
141
+ if ('items' in item) {
142
+ return toConfigSubMenu(item);
143
+ }
144
+ return toConfigItem(item);
145
+ }),
146
+ };
147
+ }
148
+
149
+ function toConfigSubMenu(subMenu: ContextSubMenu): MenuElementConfig {
150
+ if (subMenu.loading) {
151
+ return {
152
+ type: 'deferred',
153
+ deferredID: `${subMenu.title ?? ''}-${Date.now()}`,
154
+ };
155
+ }
156
+ return {
157
+ menuOptions: subMenu.iOSType === 'inline' ? ['displayInline'] : undefined,
158
+ menuTitle: subMenu.title ?? '',
159
+ menuSubtitle: subMenu.subTitle,
160
+ menuPreferredElementSize: subMenu.iOSItemSize,
161
+ menuItems: subMenu.items.map((item) => {
162
+ if ('items' in item) {
163
+ return toConfigSubMenu(item);
164
+ }
165
+ return toConfigItem(item);
166
+ }),
167
+ };
168
+ }
169
+
170
+ function toConfigItem(item: ContextItem): MenuElementConfig {
171
+ if (item.loading) {
172
+ return {
173
+ type: 'deferred',
174
+ deferredID: `${item.actionKey}-deferred}`,
175
+ };
176
+ }
177
+ const menuAttributes: MenuAttributes[] = [];
178
+ if (item.destructive) {
179
+ menuAttributes.push('destructive');
180
+ }
181
+ if (item.disabled) {
182
+ menuAttributes.push('disabled');
183
+ }
184
+ if (item.hidden) {
185
+ menuAttributes.push('hidden');
186
+ }
187
+ if (item.keepOpenOnPress) {
188
+ menuAttributes.push('keepsMenuPresented');
189
+ }
190
+ return {
191
+ actionKey: item.actionKey,
192
+ actionTitle: item.title ?? '',
193
+ actionSubtitle: item.subTitle,
194
+ menuState: item.state?.checked ? 'on' : 'off',
195
+ menuAttributes,
196
+ discoverabilityTitle: item.subTitle,
197
+ icon: item?.image?.url
198
+ ? {
199
+ type: 'IMAGE_REMOTE_URL',
200
+ imageValue: {
201
+ url: item.image.url,
202
+ },
203
+ imageOptions: {
204
+ cornerRadius: item.image.cornerRadius,
205
+ tint: item.image.tint,
206
+ },
207
+ }
208
+ : item.icon
209
+ ? {
210
+ iconType: 'SYSTEM',
211
+ iconValue:
212
+ item.icon?.namingScheme === 'sfSymbol'
213
+ ? item.icon.name ?? 'questionmark'
214
+ : item.icon.name && item.icon.name in ICON_MAPPING
215
+ ? ICON_MAPPING[item.icon.name as MaterialIconName].sfSymbol
216
+ : 'questionmark',
217
+ iconTint: item.icon?.color,
218
+ }
219
+ : undefined,
220
+ };
221
+ }
@@ -0,0 +1,420 @@
1
+ import * as ContextMenuPrimitive from '@rn-primitives/context-menu';
2
+ import { useAugmentedRef, useRelativePosition } from '@rn-primitives/hooks';
3
+ import * as Haptics from 'expo-haptics';
4
+ import { Icon } from '@roninoss/icons';
5
+ import * as React from 'react';
6
+ import {
7
+ Image,
8
+ LayoutChangeEvent,
9
+ LayoutRectangle,
10
+ Pressable,
11
+ StyleSheet,
12
+ View,
13
+ ViewProps,
14
+ } from 'react-native';
15
+ import Animated, {
16
+ FadeIn,
17
+ FadeInLeft,
18
+ FadeOut,
19
+ FadeOutLeft,
20
+ LayoutAnimationConfig,
21
+ LinearTransition,
22
+ } from 'react-native-reanimated';
23
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
24
+
25
+ import { ContextItem, ContextMenuProps, ContextMenuRef, ContextSubMenu } from './types';
26
+
27
+ import { ActivityIndicator } from '~/components/nativewindui/ActivityIndicator';
28
+ import { Button } from '~/components/nativewindui/Button';
29
+ import { DropdownMenu } from '~/components/nativewindui/DropdownMenu';
30
+ import { Text } from '~/components/nativewindui/Text';
31
+ import { cn } from '~/lib/cn';
32
+ import { useColorScheme } from '~/lib/useColorScheme';
33
+
34
+ const ContextMenuContext = React.createContext<{
35
+ onItemPress: ContextMenuProps['onItemPress'];
36
+ dismissMenu?: () => void;
37
+ materialLoadingText: string;
38
+ materialSubMenuTitlePlaceholder: string;
39
+ subMenuRefs: React.MutableRefObject<ContextMenuRef[]>;
40
+ closeSubMenus: () => void;
41
+ } | null>(null);
42
+
43
+ const ROOT_DEFAULT_LAYOUT = {
44
+ height: 0,
45
+ width: 0,
46
+ pageX: 0,
47
+ pageY: 0,
48
+ };
49
+
50
+ const ContextMenu = React.forwardRef<ContextMenuRef, ContextMenuProps>(
51
+ (
52
+ {
53
+ items,
54
+ title,
55
+ iOSItemSize: _iOSItemSize,
56
+ onItemPress: onItemPressProp,
57
+ enabled = true,
58
+ children,
59
+ materialPortalHost,
60
+ materialSideOffset = 2,
61
+ materialAlignOffset,
62
+ materialAlign = 'center',
63
+ materialWidth,
64
+ materialMinWidth = 200,
65
+ materialLoadingText = 'Loading...',
66
+ materialSubMenuTitlePlaceholder = 'More ...',
67
+ iosRenderPreview: _iosRenderPreview,
68
+ iosOnPressMenuPreview: _iosOnPressMenuPreview,
69
+ renderAuxiliaryPreview,
70
+ auxiliaryPreviewPosition = 'start',
71
+ materialOverlayClassName,
72
+ ...props
73
+ },
74
+ ref
75
+ ) => {
76
+ const [rootLayout, setRootLayout] = React.useState(ROOT_DEFAULT_LAYOUT);
77
+ const [auxiliaryContentLayout, setAuxiliaryContentLayout] =
78
+ React.useState<LayoutRectangle | null>(null);
79
+ const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
80
+ const subMenuRefs = React.useRef<ContextMenuRef[]>([]);
81
+ const insets = useSafeAreaInsets();
82
+ const triggerRef = React.useRef<ContextMenuPrimitive.ContextMenuTriggerRef>(null);
83
+ const rootRef = useAugmentedRef({
84
+ ref,
85
+ methods: {
86
+ presentMenu: () => {
87
+ triggerRef.current?.open();
88
+ },
89
+ dismissMenu,
90
+ },
91
+ deps: [triggerRef.current],
92
+ });
93
+
94
+ const positionStyle = useRelativePosition({
95
+ align: auxiliaryPreviewPosition,
96
+ avoidCollisions: true,
97
+ triggerPosition: rootLayout,
98
+ contentLayout: auxiliaryContentLayout,
99
+ alignOffset: 0,
100
+ insets: {
101
+ top: insets.top,
102
+ right: 8,
103
+ bottom: insets.bottom + (contentLayout?.height ?? 0),
104
+ left: 8,
105
+ },
106
+ sideOffset: 4,
107
+ side: 'top',
108
+ disablePositioningStyle: false,
109
+ });
110
+
111
+ function onLayout(event: LayoutChangeEvent) {
112
+ setAuxiliaryContentLayout(event.nativeEvent.layout);
113
+ }
114
+
115
+ function onTriggerLongPress() {
116
+ rootRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
117
+ setRootLayout({ height, width, pageX, pageY });
118
+ });
119
+ }
120
+
121
+ function closeSubMenus() {
122
+ for (const subMenuRef of subMenuRefs.current) {
123
+ subMenuRef.dismissMenu?.();
124
+ }
125
+ }
126
+
127
+ function onItemPress(item: Omit<ContextItem, 'icon'>) {
128
+ closeSubMenus();
129
+ onItemPressProp?.(item);
130
+ }
131
+
132
+ function dismissMenu() {
133
+ triggerRef.current?.close();
134
+ }
135
+
136
+ function onOpenChange(open: boolean) {
137
+ if (!open) {
138
+ setAuxiliaryContentLayout(null);
139
+ setContentLayout(null);
140
+ return;
141
+ }
142
+ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
143
+ }
144
+
145
+ function onContentLayout(ev: LayoutChangeEvent) {
146
+ setContentLayout(ev.nativeEvent.layout);
147
+ }
148
+
149
+ return (
150
+ <View>
151
+ <ContextMenuPrimitive.Root
152
+ ref={rootRef}
153
+ relativeTo="trigger"
154
+ onOpenChange={onOpenChange}
155
+ {...props}
156
+ collapsable={false}>
157
+ <ContextMenuPrimitive.Trigger ref={triggerRef} onLongPress={onTriggerLongPress} asChild>
158
+ {children}
159
+ </ContextMenuPrimitive.Trigger>
160
+ <ContextMenuPrimitive.Portal hostName={materialPortalHost}>
161
+ <ContextMenuContext.Provider
162
+ value={{
163
+ onItemPress,
164
+ dismissMenu,
165
+ materialLoadingText,
166
+ materialSubMenuTitlePlaceholder,
167
+ subMenuRefs,
168
+ closeSubMenus,
169
+ }}>
170
+ <ContextMenuPrimitive.Overlay style={StyleSheet.absoluteFill}>
171
+ <Animated.View
172
+ style={StyleSheet.absoluteFill}
173
+ entering={FadeIn}
174
+ exiting={FadeOut}
175
+ className={cn('bg-black/20', materialOverlayClassName)}>
176
+ {renderAuxiliaryPreview && contentLayout && (
177
+ <ContextMenuAuxiliaryPreview
178
+ onLayout={onLayout}
179
+ style={positionStyle}
180
+ children={renderAuxiliaryPreview()}
181
+ />
182
+ )}
183
+ <ContextMenuPrimitive.Content
184
+ insets={{
185
+ top: insets.top,
186
+ right: 8,
187
+ bottom: insets.bottom,
188
+ left: 8,
189
+ }}
190
+ sideOffset={materialSideOffset}
191
+ alignOffset={materialAlignOffset}
192
+ align={materialAlign}
193
+ className={cn(!title && items.length === 0 && 'opacity-0')}
194
+ pointerEvents={!title && items.length === 0 ? 'none' : undefined}
195
+ onLayout={onContentLayout}>
196
+ <Animated.View
197
+ entering={FadeIn}
198
+ exiting={FadeOut}
199
+ style={{
200
+ minWidth: materialMinWidth,
201
+ width: materialWidth,
202
+ }}
203
+ className="border-border/20 bg-card z-50 rounded-md border py-2 shadow-xl">
204
+ {!!title && <ContextMenuLabel>{title}</ContextMenuLabel>}
205
+ <ContextMenuInnerContent items={items} />
206
+ </Animated.View>
207
+ </ContextMenuPrimitive.Content>
208
+ </Animated.View>
209
+ </ContextMenuPrimitive.Overlay>
210
+ </ContextMenuContext.Provider>
211
+ </ContextMenuPrimitive.Portal>
212
+ </ContextMenuPrimitive.Root>
213
+ </View>
214
+ );
215
+ }
216
+ );
217
+
218
+ ContextMenu.displayName = 'ContextMenu';
219
+
220
+ export { ContextMenu };
221
+
222
+ function useContextMenuContext() {
223
+ const context = React.useContext(ContextMenuContext);
224
+ if (!context) {
225
+ throw new Error(
226
+ 'ContextMenu compound components cannot be rendered outside the ContextMenu component'
227
+ );
228
+ }
229
+ return context;
230
+ }
231
+
232
+ function ContextMenuAuxiliaryPreview({
233
+ style,
234
+ onLayout,
235
+ children,
236
+ }: Required<Pick<ViewProps, 'style' | 'onLayout' | 'children'>>) {
237
+ return (
238
+ <Pressable style={style} onLayout={onLayout}>
239
+ {children}
240
+ </Pressable>
241
+ );
242
+ }
243
+
244
+ function ContextMenuInnerContent({ items }: { items: (ContextItem | ContextSubMenu)[] }) {
245
+ const { materialLoadingText } = useContextMenuContext();
246
+ const id = React.useId();
247
+
248
+ return (
249
+ <View>
250
+ {items.map((item, index) => {
251
+ if (item.loading) {
252
+ return (
253
+ <ContextMenuPrimitive.Item key={`loading:${id}-${item.title}-${index}`} asChild>
254
+ <Button
255
+ disabled
256
+ variant="plain"
257
+ className="h-12 justify-between gap-10 rounded-none px-3"
258
+ androidRootClassName="rounded-none ">
259
+ <Text className="font-normal opacity-60">{materialLoadingText}</Text>
260
+ <ActivityIndicator />
261
+ </Button>
262
+ </ContextMenuPrimitive.Item>
263
+ );
264
+ }
265
+ if ((item as Partial<ContextSubMenu>)?.items) {
266
+ const subMenu = item as ContextSubMenu;
267
+ if (subMenu.items.length === 0) return null;
268
+ return (
269
+ <ContextMenuSubMenu
270
+ title={subMenu.title}
271
+ subTitle={subMenu.subTitle}
272
+ items={subMenu.items}
273
+ key={`${id}-${subMenu.title}-${index}`}
274
+ />
275
+ );
276
+ }
277
+ const contextMenuItem = item as ContextItem;
278
+ return <ContextMenuItem key={contextMenuItem.actionKey} {...contextMenuItem} />;
279
+ })}
280
+ </View>
281
+ );
282
+ }
283
+
284
+ function ContextMenuLabel(props: { children: React.ReactNode }) {
285
+ return (
286
+ <ContextMenuPrimitive.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">
287
+ {props.children}
288
+ </ContextMenuPrimitive.Label>
289
+ );
290
+ }
291
+
292
+ function ContextMenuItem(props: Omit<ContextItem, 'loading'>) {
293
+ const { colors } = useColorScheme();
294
+ const { onItemPress } = useContextMenuContext();
295
+
296
+ function onPress() {
297
+ onItemPress?.(props);
298
+ }
299
+
300
+ if (props.hidden) return null;
301
+
302
+ return (
303
+ <LayoutAnimationConfig skipEntering skipExiting>
304
+ <ContextMenuPrimitive.Item
305
+ asChild
306
+ closeOnPress={!props.keepOpenOnPress}
307
+ role="checkbox"
308
+ accessibilityState={{
309
+ disabled: !!props.disabled,
310
+ checked: props.state?.checked,
311
+ }}>
312
+ <Button
313
+ variant={props.state?.checked ? 'tonal' : 'plain'}
314
+ className={cn(
315
+ 'h-12 justify-between gap-10 rounded-none px-3',
316
+ !props.state && !props.title && 'justify-center px-4'
317
+ )}
318
+ androidRootClassName="rounded-none"
319
+ accessibilityHint={props.subTitle}
320
+ onPress={onPress}>
321
+ {!props.state && !props.title ? null : (
322
+ <View className="flex-row items-center gap-3 py-0.5">
323
+ {props.state?.checked && (
324
+ <Animated.View entering={FadeInLeft} exiting={FadeOutLeft}>
325
+ <Icon name="check" size={21} color={colors.foreground} />
326
+ </Animated.View>
327
+ )}
328
+ <Animated.View layout={LinearTransition}>
329
+ <Text
330
+ numberOfLines={1}
331
+ className={cn(
332
+ 'font-normal',
333
+ props.destructive && 'text-destructive font-medium',
334
+ props.disabled && 'opacity-60'
335
+ )}>
336
+ {props.title}
337
+ </Text>
338
+ </Animated.View>
339
+ {props.state && !props.state?.checked && (
340
+ <Icon name="check" size={21} color="#00000000" />
341
+ )}
342
+ </View>
343
+ )}
344
+ {props.image ? (
345
+ <Image
346
+ source={{ uri: props.image.url }}
347
+ style={{
348
+ width: 22,
349
+ height: 22,
350
+ borderRadius:
351
+ typeof props.image.cornerRadius === 'number' && props.image.cornerRadius > 0
352
+ ? props.image.cornerRadius / 4
353
+ : 0,
354
+ }}
355
+ />
356
+ ) : props.icon ? (
357
+ <Icon color={colors.foreground} {...props.icon} size={22} />
358
+ ) : null}
359
+ </Button>
360
+ </ContextMenuPrimitive.Item>
361
+ </LayoutAnimationConfig>
362
+ );
363
+ }
364
+
365
+ const DEFAULT_LAYOUT = {
366
+ width: 0,
367
+ height: 0,
368
+ };
369
+
370
+ function ContextMenuSubMenu({ title, subTitle, items }: Omit<ContextSubMenu, 'loading'>) {
371
+ const { colors } = useColorScheme();
372
+ const {
373
+ onItemPress: onContextMenuItemPress,
374
+ dismissMenu,
375
+ materialSubMenuTitlePlaceholder,
376
+ subMenuRefs,
377
+ closeSubMenus,
378
+ } = useContextMenuContext();
379
+ const [triggerLayout, setTriggerLayout] = React.useState<typeof DEFAULT_LAYOUT>(DEFAULT_LAYOUT);
380
+
381
+ function onItemPress(item: Omit<ContextItem, 'icon'>) {
382
+ dismissMenu?.();
383
+ onContextMenuItemPress?.(item);
384
+ }
385
+
386
+ function onLayout(ev: LayoutChangeEvent) {
387
+ setTriggerLayout(ev.nativeEvent.layout);
388
+ }
389
+
390
+ function addSubMenuRef(ref: ContextMenuRef | null) {
391
+ if (!ref) return;
392
+ subMenuRefs.current.push(ref);
393
+ }
394
+
395
+ return (
396
+ <DropdownMenu
397
+ items={items}
398
+ materialAlign="start"
399
+ materialSideOffset={-triggerLayout.height}
400
+ materialAlignOffset={triggerLayout.width}
401
+ onItemPress={onItemPress}
402
+ materialMinWidth={48}
403
+ // @ts-expect-error internal prop
404
+ materialIsSubMenu
405
+ ref={addSubMenuRef}>
406
+ <Button
407
+ variant="plain"
408
+ className="justify-between gap-10 rounded-none px-3"
409
+ androidRootClassName="rounded-none"
410
+ onLayout={onLayout}
411
+ accessibilityHint={subTitle}
412
+ onPress={closeSubMenus}>
413
+ <Text numberOfLines={1} className="py-0.5 font-normal">
414
+ {title || materialSubMenuTitlePlaceholder}
415
+ </Text>
416
+ <Icon name="chevron-right" size={21} color={colors.grey} />
417
+ </Button>
418
+ </DropdownMenu>
419
+ );
420
+ }
@@ -0,0 +1 @@
1
+ export * from './ContextMenu';