react-native-hold-menu-actions 0.1.6

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 (219) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +38 -0
  3. package/lib/commonjs/components/backdrop/Backdrop.js +104 -0
  4. package/lib/commonjs/components/backdrop/Backdrop.js.map +1 -0
  5. package/lib/commonjs/components/backdrop/constants.js +14 -0
  6. package/lib/commonjs/components/backdrop/constants.js.map +1 -0
  7. package/lib/commonjs/components/backdrop/index.js +16 -0
  8. package/lib/commonjs/components/backdrop/index.js.map +1 -0
  9. package/lib/commonjs/components/backdrop/styles.js +17 -0
  10. package/lib/commonjs/components/backdrop/styles.js.map +1 -0
  11. package/lib/commonjs/components/flatList/FlatList.js +35 -0
  12. package/lib/commonjs/components/flatList/FlatList.js.map +1 -0
  13. package/lib/commonjs/components/flatList/index.js +16 -0
  14. package/lib/commonjs/components/flatList/index.js.map +1 -0
  15. package/lib/commonjs/components/holdItem/HoldItem.js +369 -0
  16. package/lib/commonjs/components/holdItem/HoldItem.js.map +1 -0
  17. package/lib/commonjs/components/holdItem/index.js +16 -0
  18. package/lib/commonjs/components/holdItem/index.js.map +1 -0
  19. package/lib/commonjs/components/holdItem/styles.js +22 -0
  20. package/lib/commonjs/components/holdItem/styles.js.map +1 -0
  21. package/lib/commonjs/components/holdItem/types.d.js +2 -0
  22. package/lib/commonjs/components/holdItem/types.d.js.map +1 -0
  23. package/lib/commonjs/components/icon/Icon.js +43 -0
  24. package/lib/commonjs/components/icon/Icon.js.map +1 -0
  25. package/lib/commonjs/components/icon/index.js +16 -0
  26. package/lib/commonjs/components/icon/index.js.map +1 -0
  27. package/lib/commonjs/components/menu/Menu.js +57 -0
  28. package/lib/commonjs/components/menu/Menu.js.map +1 -0
  29. package/lib/commonjs/components/menu/MenuItem.js +85 -0
  30. package/lib/commonjs/components/menu/MenuItem.js.map +1 -0
  31. package/lib/commonjs/components/menu/MenuItems.js +35 -0
  32. package/lib/commonjs/components/menu/MenuItems.js.map +1 -0
  33. package/lib/commonjs/components/menu/MenuList.js +121 -0
  34. package/lib/commonjs/components/menu/MenuList.js.map +1 -0
  35. package/lib/commonjs/components/menu/Separator.js +47 -0
  36. package/lib/commonjs/components/menu/Separator.js.map +1 -0
  37. package/lib/commonjs/components/menu/calculations.js +31 -0
  38. package/lib/commonjs/components/menu/calculations.js.map +1 -0
  39. package/lib/commonjs/components/menu/constants.js +21 -0
  40. package/lib/commonjs/components/menu/constants.js.map +1 -0
  41. package/lib/commonjs/components/menu/index.js +16 -0
  42. package/lib/commonjs/components/menu/index.js.map +1 -0
  43. package/lib/commonjs/components/menu/styles.js +77 -0
  44. package/lib/commonjs/components/menu/styles.js.map +1 -0
  45. package/lib/commonjs/components/menu/types.d.js +2 -0
  46. package/lib/commonjs/components/menu/types.d.js.map +1 -0
  47. package/lib/commonjs/components/provider/Provider.js +98 -0
  48. package/lib/commonjs/components/provider/Provider.js.map +1 -0
  49. package/lib/commonjs/components/provider/index.js +16 -0
  50. package/lib/commonjs/components/provider/index.js.map +1 -0
  51. package/lib/commonjs/components/provider/reducer.js +50 -0
  52. package/lib/commonjs/components/provider/reducer.js.map +1 -0
  53. package/lib/commonjs/components/provider/types.d.js +2 -0
  54. package/lib/commonjs/components/provider/types.d.js.map +1 -0
  55. package/lib/commonjs/constants.js +60 -0
  56. package/lib/commonjs/constants.js.map +1 -0
  57. package/lib/commonjs/context/index.js +14 -0
  58. package/lib/commonjs/context/index.js.map +1 -0
  59. package/lib/commonjs/context/internal.js +13 -0
  60. package/lib/commonjs/context/internal.js.map +1 -0
  61. package/lib/commonjs/hooks/index.js +24 -0
  62. package/lib/commonjs/hooks/index.js.map +1 -0
  63. package/lib/commonjs/hooks/useDeviceOrientation.js +38 -0
  64. package/lib/commonjs/hooks/useDeviceOrientation.js.map +1 -0
  65. package/lib/commonjs/hooks/useInternal.js +15 -0
  66. package/lib/commonjs/hooks/useInternal.js.map +1 -0
  67. package/lib/commonjs/index.js +40 -0
  68. package/lib/commonjs/index.js.map +1 -0
  69. package/lib/commonjs/styleGuide.js +39 -0
  70. package/lib/commonjs/styleGuide.js.map +1 -0
  71. package/lib/commonjs/utils/calculations.js +73 -0
  72. package/lib/commonjs/utils/calculations.js.map +1 -0
  73. package/lib/commonjs/utils/validations.js +43 -0
  74. package/lib/commonjs/utils/validations.js.map +1 -0
  75. package/lib/module/components/backdrop/Backdrop.js +83 -0
  76. package/lib/module/components/backdrop/Backdrop.js.map +1 -0
  77. package/lib/module/components/backdrop/constants.js +4 -0
  78. package/lib/module/components/backdrop/constants.js.map +1 -0
  79. package/lib/module/components/backdrop/index.js +2 -0
  80. package/lib/module/components/backdrop/index.js.map +1 -0
  81. package/lib/module/components/backdrop/styles.js +7 -0
  82. package/lib/module/components/backdrop/styles.js.map +1 -0
  83. package/lib/module/components/flatList/FlatList.js +17 -0
  84. package/lib/module/components/flatList/FlatList.js.map +1 -0
  85. package/lib/module/components/flatList/index.js +2 -0
  86. package/lib/module/components/flatList/index.js.map +1 -0
  87. package/lib/module/components/holdItem/HoldItem.js +344 -0
  88. package/lib/module/components/holdItem/HoldItem.js.map +1 -0
  89. package/lib/module/components/holdItem/index.js +2 -0
  90. package/lib/module/components/holdItem/index.js.map +1 -0
  91. package/lib/module/components/holdItem/styles.js +12 -0
  92. package/lib/module/components/holdItem/styles.js.map +1 -0
  93. package/lib/module/components/holdItem/types.d.js +2 -0
  94. package/lib/module/components/holdItem/types.d.js.map +1 -0
  95. package/lib/module/components/icon/Icon.js +26 -0
  96. package/lib/module/components/icon/Icon.js.map +1 -0
  97. package/lib/module/components/icon/index.js +2 -0
  98. package/lib/module/components/icon/index.js.map +1 -0
  99. package/lib/module/components/menu/Menu.js +37 -0
  100. package/lib/module/components/menu/Menu.js.map +1 -0
  101. package/lib/module/components/menu/MenuItem.js +59 -0
  102. package/lib/module/components/menu/MenuItem.js.map +1 -0
  103. package/lib/module/components/menu/MenuItems.js +19 -0
  104. package/lib/module/components/menu/MenuItems.js.map +1 -0
  105. package/lib/module/components/menu/MenuList.js +93 -0
  106. package/lib/module/components/menu/MenuList.js.map +1 -0
  107. package/lib/module/components/menu/Separator.js +29 -0
  108. package/lib/module/components/menu/Separator.js.map +1 -0
  109. package/lib/module/components/menu/calculations.js +17 -0
  110. package/lib/module/components/menu/calculations.js.map +1 -0
  111. package/lib/module/components/menu/constants.js +8 -0
  112. package/lib/module/components/menu/constants.js.map +1 -0
  113. package/lib/module/components/menu/index.js +2 -0
  114. package/lib/module/components/menu/index.js.map +1 -0
  115. package/lib/module/components/menu/styles.js +63 -0
  116. package/lib/module/components/menu/styles.js.map +1 -0
  117. package/lib/module/components/menu/types.d.js +2 -0
  118. package/lib/module/components/menu/types.d.js.map +1 -0
  119. package/lib/module/components/provider/Provider.js +75 -0
  120. package/lib/module/components/provider/Provider.js.map +1 -0
  121. package/lib/module/components/provider/index.js +2 -0
  122. package/lib/module/components/provider/index.js.map +1 -0
  123. package/lib/module/components/provider/reducer.js +38 -0
  124. package/lib/module/components/provider/reducer.js.map +1 -0
  125. package/lib/module/components/provider/types.d.js +2 -0
  126. package/lib/module/components/provider/types.d.js.map +1 -0
  127. package/lib/module/constants.js +37 -0
  128. package/lib/module/constants.js.map +1 -0
  129. package/lib/module/context/index.js +2 -0
  130. package/lib/module/context/index.js.map +1 -0
  131. package/lib/module/context/internal.js +4 -0
  132. package/lib/module/context/internal.js.map +1 -0
  133. package/lib/module/hooks/index.js +3 -0
  134. package/lib/module/hooks/index.js.map +1 -0
  135. package/lib/module/hooks/useDeviceOrientation.js +27 -0
  136. package/lib/module/hooks/useDeviceOrientation.js.map +1 -0
  137. package/lib/module/hooks/useInternal.js +4 -0
  138. package/lib/module/hooks/useInternal.js.map +1 -0
  139. package/lib/module/index.js +5 -0
  140. package/lib/module/index.js.map +1 -0
  141. package/lib/module/styleGuide.js +30 -0
  142. package/lib/module/styleGuide.js.map +1 -0
  143. package/lib/module/utils/calculations.js +51 -0
  144. package/lib/module/utils/calculations.js.map +1 -0
  145. package/lib/module/utils/validations.js +38 -0
  146. package/lib/module/utils/validations.js.map +1 -0
  147. package/lib/typescript/components/backdrop/Backdrop.d.ts +3 -0
  148. package/lib/typescript/components/backdrop/constants.d.ts +2 -0
  149. package/lib/typescript/components/backdrop/index.d.ts +1 -0
  150. package/lib/typescript/components/backdrop/styles.d.ts +10 -0
  151. package/lib/typescript/components/flatList/FlatList.d.ts +5 -0
  152. package/lib/typescript/components/flatList/index.d.ts +2 -0
  153. package/lib/typescript/components/holdItem/HoldItem.d.ts +4 -0
  154. package/lib/typescript/components/holdItem/index.d.ts +2 -0
  155. package/lib/typescript/components/holdItem/styles.d.ts +15 -0
  156. package/lib/typescript/components/holdItem/types.d.ts +131 -0
  157. package/lib/typescript/components/icon/Icon.d.ts +7 -0
  158. package/lib/typescript/components/icon/index.d.ts +1 -0
  159. package/lib/typescript/components/menu/Menu.d.ts +3 -0
  160. package/lib/typescript/components/menu/MenuItem.d.ts +8 -0
  161. package/lib/typescript/components/menu/MenuItems.d.ts +6 -0
  162. package/lib/typescript/components/menu/MenuList.d.ts +3 -0
  163. package/lib/typescript/components/menu/Separator.d.ts +3 -0
  164. package/lib/typescript/components/menu/calculations.d.ts +4 -0
  165. package/lib/typescript/components/menu/constants.d.ts +7 -0
  166. package/lib/typescript/components/menu/index.d.ts +1 -0
  167. package/lib/typescript/components/menu/styles.d.ts +59 -0
  168. package/lib/typescript/components/menu/types.d.ts +28 -0
  169. package/lib/typescript/components/provider/Provider.d.ts +10 -0
  170. package/lib/typescript/components/provider/index.d.ts +2 -0
  171. package/lib/typescript/components/provider/reducer.d.ts +20 -0
  172. package/lib/typescript/components/provider/types.d.ts +33 -0
  173. package/lib/typescript/constants.d.ts +29 -0
  174. package/lib/typescript/context/index.d.ts +1 -0
  175. package/lib/typescript/context/internal.d.ts +16 -0
  176. package/lib/typescript/hooks/index.d.ts +2 -0
  177. package/lib/typescript/hooks/useDeviceOrientation.d.ts +3 -0
  178. package/lib/typescript/hooks/useInternal.d.ts +1 -0
  179. package/lib/typescript/index.d.ts +4 -0
  180. package/lib/typescript/styleGuide.d.ts +28 -0
  181. package/lib/typescript/utils/calculations.d.ts +14 -0
  182. package/lib/typescript/utils/validations.d.ts +3 -0
  183. package/package.json +106 -0
  184. package/src/components/backdrop/Backdrop.tsx +138 -0
  185. package/src/components/backdrop/constants.ts +8 -0
  186. package/src/components/backdrop/index.ts +1 -0
  187. package/src/components/backdrop/styles.ts +8 -0
  188. package/src/components/flatList/FlatList.tsx +23 -0
  189. package/src/components/flatList/index.ts +2 -0
  190. package/src/components/holdItem/HoldItem.tsx +449 -0
  191. package/src/components/holdItem/index.ts +2 -0
  192. package/src/components/holdItem/styles.ts +11 -0
  193. package/src/components/holdItem/types.d.ts +131 -0
  194. package/src/components/icon/Icon.tsx +33 -0
  195. package/src/components/icon/index.ts +1 -0
  196. package/src/components/menu/Menu.tsx +57 -0
  197. package/src/components/menu/MenuItem.tsx +79 -0
  198. package/src/components/menu/MenuItems.tsx +26 -0
  199. package/src/components/menu/MenuList.tsx +151 -0
  200. package/src/components/menu/Separator.tsx +28 -0
  201. package/src/components/menu/calculations.ts +49 -0
  202. package/src/components/menu/constants.ts +9 -0
  203. package/src/components/menu/index.ts +1 -0
  204. package/src/components/menu/styles.ts +64 -0
  205. package/src/components/menu/types.d.ts +28 -0
  206. package/src/components/provider/Provider.tsx +105 -0
  207. package/src/components/provider/index.ts +2 -0
  208. package/src/components/provider/reducer.ts +48 -0
  209. package/src/components/provider/types.d.ts +33 -0
  210. package/src/constants.ts +54 -0
  211. package/src/context/index.ts +1 -0
  212. package/src/context/internal.ts +19 -0
  213. package/src/hooks/index.ts +2 -0
  214. package/src/hooks/useDeviceOrientation.ts +28 -0
  215. package/src/hooks/useInternal.ts +4 -0
  216. package/src/index.ts +4 -0
  217. package/src/styleGuide.ts +31 -0
  218. package/src/utils/calculations.ts +110 -0
  219. package/src/utils/validations.ts +42 -0
@@ -0,0 +1,19 @@
1
+ import { createContext } from 'react';
2
+ import type Animated from 'react-native-reanimated';
3
+ import type { CONTEXT_MENU_STATE } from '../constants';
4
+ import { MenuInternalProps } from '../components/menu/types';
5
+
6
+ export type InternalContextType = {
7
+ state: Animated.SharedValue<CONTEXT_MENU_STATE>;
8
+ theme: Animated.SharedValue<'light' | 'dark'>;
9
+ menuProps: Animated.SharedValue<MenuInternalProps>;
10
+ safeAreaInsets?: {
11
+ top: number;
12
+ right: number;
13
+ bottom: number;
14
+ left: number;
15
+ };
16
+ };
17
+
18
+ // @ts-ignore
19
+ export const InternalContext = createContext<InternalContextType>();
@@ -0,0 +1,2 @@
1
+ export { default as useDeviceOrientation } from './useDeviceOrientation';
2
+ export { useInternal } from './useInternal';
@@ -0,0 +1,28 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { Dimensions } from 'react-native';
3
+
4
+ type Orientation = 'landscape' | 'portrait';
5
+
6
+ function getWindowOrientation(): Orientation {
7
+ const { width, height } = Dimensions.get('window');
8
+ return height >= width ? 'portrait' : 'landscape';
9
+ }
10
+
11
+ function useDeviceOrientation() {
12
+ const [deviceOrientation, setDeviceOrientation] = useState<Orientation>(
13
+ getWindowOrientation()
14
+ );
15
+
16
+ useEffect(() => {
17
+ function updateState() {
18
+ setDeviceOrientation(getWindowOrientation());
19
+ }
20
+ const changeEvent = Dimensions.addEventListener('change', updateState);
21
+ // @ts-ignore
22
+ return () => changeEvent.remove();
23
+ }, []);
24
+
25
+ return deviceOrientation;
26
+ }
27
+
28
+ export default useDeviceOrientation;
@@ -0,0 +1,4 @@
1
+ import { useContext } from 'react';
2
+ import { InternalContext } from '../context';
3
+
4
+ export const useInternal = () => useContext(InternalContext);
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as HoldItem } from './components/holdItem';
2
+ export { default as HoldMenuProvider } from './components/provider';
3
+ export { default as HoldMenuFlatList } from './components/flatList';
4
+ export { default as HoldMenuIcon } from './components/icon';
@@ -0,0 +1,31 @@
1
+ import { Dimensions } from 'react-native';
2
+
3
+ const styleGuide = {
4
+ spacing: 8,
5
+ dimensionWidth: Dimensions.get('screen').width,
6
+ dimensionHeight: Dimensions.get('screen').height,
7
+ palette: {
8
+ primary: '#0072ff',
9
+ secondary: '#e2e2e2',
10
+ common: {
11
+ white: '#fff',
12
+ black: '#000',
13
+ },
14
+ },
15
+ typography: {
16
+ body: {
17
+ fontSize: 17,
18
+ lineHeight: 20,
19
+ },
20
+ callout: {
21
+ fontSize: 16,
22
+ lineHeight: 20,
23
+ },
24
+ callout2: {
25
+ fontSize: 14,
26
+ lineHeight: 18,
27
+ },
28
+ },
29
+ };
30
+
31
+ export default styleGuide;
@@ -0,0 +1,110 @@
1
+ import styleGuide from '../styleGuide';
2
+ import {
3
+ MENU_WIDTH,
4
+ MENU_TRANSFORM_ORIGIN_TOLERENCE,
5
+ FONT_SCALE,
6
+ } from '../constants';
7
+
8
+ export const MenuItemHeight = () => {
9
+ 'worklet';
10
+ return (
11
+ styleGuide.typography.callout.lineHeight * FONT_SCALE +
12
+ styleGuide.spacing * 2.5
13
+ );
14
+ };
15
+
16
+ export const calculateMenuHeight = (
17
+ itemLength: number,
18
+ separatorCount: number
19
+ ) => {
20
+ 'worklet';
21
+ return (
22
+ MenuItemHeight() * itemLength +
23
+ (itemLength - 1) +
24
+ separatorCount * styleGuide.spacing
25
+ );
26
+ };
27
+
28
+ export type TransformOriginAnchorPosition =
29
+ | 'top-right'
30
+ | 'top-left'
31
+ | 'top-center'
32
+ | 'bottom-right'
33
+ | 'bottom-left'
34
+ | 'bottom-center';
35
+
36
+ export const menuAnimationAnchor = (
37
+ anchorPoint: TransformOriginAnchorPosition,
38
+ itemWidth: number,
39
+ itemLength: number,
40
+ itemsWithSeparatorLength: number
41
+ ) => {
42
+ 'worklet';
43
+ const MenuHeight = calculateMenuHeight(itemLength, itemsWithSeparatorLength);
44
+ const splittetAnchorName: string[] = anchorPoint.split('-');
45
+
46
+ const Center1 = itemWidth;
47
+ const Center2 = 0;
48
+
49
+ const TyTop1 = -(MenuHeight / 2);
50
+ const TyTop2 = MenuHeight / 2;
51
+
52
+ const TxLeft1 = (MENU_WIDTH / 2) * -1;
53
+ const TxLeft2 = (MENU_WIDTH / 2) * 1;
54
+
55
+ return {
56
+ beginningTransformations: {
57
+ translateX:
58
+ splittetAnchorName[1] === 'right'
59
+ ? -TxLeft1
60
+ : splittetAnchorName[1] === 'left'
61
+ ? TxLeft1
62
+ : Center1,
63
+ translateY:
64
+ splittetAnchorName[0] === 'top'
65
+ ? TyTop1
66
+ : splittetAnchorName[0] === 'bottom'
67
+ ? TyTop1
68
+ : Center2,
69
+ },
70
+ endingTransformations: {
71
+ translateX:
72
+ splittetAnchorName[1] === 'right'
73
+ ? -TxLeft2
74
+ : splittetAnchorName[1] === 'left'
75
+ ? TxLeft2
76
+ : Center2,
77
+ translateY:
78
+ splittetAnchorName[0] === 'top'
79
+ ? TyTop2
80
+ : splittetAnchorName[0] === 'bottom'
81
+ ? -TyTop2
82
+ : Center2,
83
+ },
84
+ };
85
+ };
86
+
87
+ export const getTransformOrigin = (
88
+ posX: number,
89
+ itemWidth: number,
90
+ windowWidth: number,
91
+ bottom?: boolean
92
+ ): TransformOriginAnchorPosition => {
93
+ 'worklet';
94
+ const distanceToLeft = Math.round(posX + itemWidth / 2);
95
+ const distanceToRight = Math.round(windowWidth - distanceToLeft);
96
+
97
+ let position: TransformOriginAnchorPosition = bottom
98
+ ? 'bottom-right'
99
+ : 'top-right';
100
+
101
+ const majority = Math.abs(distanceToLeft - distanceToRight);
102
+
103
+ if (majority < MENU_TRANSFORM_ORIGIN_TOLERENCE) {
104
+ position = bottom ? 'bottom-center' : 'top-center';
105
+ } else if (distanceToLeft < distanceToRight) {
106
+ position = bottom ? 'bottom-left' : 'top-left';
107
+ }
108
+
109
+ return position;
110
+ };
@@ -0,0 +1,42 @@
1
+ import { MenuItemProps } from '../components/menu/types';
2
+
3
+ function fieldAreSame(obj1: MenuItemProps, obj2: MenuItemProps) {
4
+ 'worklet';
5
+
6
+ const keys = Object.keys(obj1);
7
+
8
+ return keys.every(key => {
9
+ // @ts-ignore
10
+ const val1 = obj1[key];
11
+ // @ts-ignore
12
+ const val2 = obj2[key];
13
+
14
+ if (val1 !== val2) {
15
+ if (typeof val1 === 'function' && typeof val2 === 'function')
16
+ return val1.toString() === val2.toString();
17
+ return false;
18
+ }
19
+
20
+ return true;
21
+ });
22
+ }
23
+
24
+ function deepEqual(array1: MenuItemProps[], array2: MenuItemProps[]) {
25
+ 'worklet';
26
+
27
+ const areArrays = Array.isArray(array1) && Array.isArray(array2);
28
+ const areSameLength = areArrays && array2 && array1.length === array2.length;
29
+
30
+ if (areArrays && areSameLength && array2) {
31
+ return array1.every((menuItem: MenuItemProps, index) => {
32
+ const obj1 = menuItem;
33
+ const obj2 = array2[index];
34
+
35
+ return fieldAreSame(obj1, obj2);
36
+ });
37
+ }
38
+
39
+ return false;
40
+ }
41
+
42
+ export { deepEqual };