tamagui 1.0.0-alpha.4 → 1.0.0-alpha.8

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 (121) hide show
  1. package/_jsx/index.js +5 -1
  2. package/_jsx/views/Button.js +26 -5
  3. package/_jsx/views/InteractiveFrame.js +0 -6
  4. package/_jsx/views/Popper.js +2 -0
  5. package/_jsx/views/SafeAreaProvider.js +26 -0
  6. package/_jsx/views/Tooltip.js +2 -2
  7. package/dist/cjs/helpers/normalizeColor.js +57 -0
  8. package/dist/cjs/helpers/normalizeColor.js.map +7 -0
  9. package/dist/cjs/helpers/prevent.js +13 -0
  10. package/dist/cjs/helpers/prevent.js.map +7 -0
  11. package/dist/cjs/hooks/useControllableState.js +51 -0
  12. package/dist/cjs/hooks/useControllableState.js.map +7 -0
  13. package/dist/cjs/hooks/useDebounce.js +89 -0
  14. package/dist/cjs/hooks/useDebounce.js.map +7 -0
  15. package/dist/cjs/hooks/useKeyboardDismissable.js +94 -0
  16. package/dist/cjs/hooks/useKeyboardDismissable.js.map +7 -0
  17. package/dist/cjs/hooks/useLayout.js +79 -0
  18. package/dist/cjs/hooks/useLayout.js.map +7 -0
  19. package/dist/cjs/index.js +63 -0
  20. package/dist/cjs/index.js.map +7 -0
  21. package/dist/cjs/viewTypes.js +4 -0
  22. package/dist/cjs/viewTypes.js.map +7 -0
  23. package/dist/cjs/views/BlurView.js +89 -0
  24. package/dist/cjs/views/BlurView.js.map +7 -0
  25. package/dist/cjs/views/BlurView.native.js +38 -0
  26. package/dist/cjs/views/BlurView.native.js.map +7 -0
  27. package/dist/cjs/views/Box.js +33 -0
  28. package/dist/cjs/views/Box.js.map +7 -0
  29. package/dist/cjs/views/Button.js +119 -0
  30. package/dist/cjs/views/Button.js.map +7 -0
  31. package/dist/cjs/views/Circle.js +44 -0
  32. package/dist/cjs/views/Circle.js.map +7 -0
  33. package/dist/cjs/views/EnsureFlexed.js +37 -0
  34. package/dist/cjs/views/EnsureFlexed.js.map +7 -0
  35. package/dist/cjs/views/ExitAnimationContext.js +33 -0
  36. package/dist/cjs/views/ExitAnimationContext.js.map +7 -0
  37. package/dist/cjs/views/Form.js +46 -0
  38. package/dist/cjs/views/Form.js.map +7 -0
  39. package/dist/cjs/views/Grid.js +61 -0
  40. package/dist/cjs/views/Grid.js.map +7 -0
  41. package/dist/cjs/views/Headings.js +75 -0
  42. package/dist/cjs/views/Headings.js.map +7 -0
  43. package/dist/cjs/views/Hoverable.js +83 -0
  44. package/dist/cjs/views/Hoverable.js.map +7 -0
  45. package/dist/cjs/views/HoverablePopover.js +108 -0
  46. package/dist/cjs/views/HoverablePopover.js.map +7 -0
  47. package/dist/cjs/views/InteractiveContainer.js +38 -0
  48. package/dist/cjs/views/InteractiveContainer.js.map +7 -0
  49. package/dist/cjs/views/InteractiveFrame.js +88 -0
  50. package/dist/cjs/views/InteractiveFrame.js.map +7 -0
  51. package/dist/cjs/views/Layouts.js +64 -0
  52. package/dist/cjs/views/Layouts.js.map +7 -0
  53. package/dist/cjs/views/LinearGradient.js +111 -0
  54. package/dist/cjs/views/LinearGradient.js.map +7 -0
  55. package/dist/cjs/views/LinearGradient.native.js +65 -0
  56. package/dist/cjs/views/LinearGradient.native.js.map +7 -0
  57. package/dist/cjs/views/Modal.js +212 -0
  58. package/dist/cjs/views/Modal.js.map +7 -0
  59. package/dist/cjs/views/NativeLinearGradientProps.js +4 -0
  60. package/dist/cjs/views/NativeLinearGradientProps.js.map +7 -0
  61. package/dist/cjs/views/Overlay.js +64 -0
  62. package/dist/cjs/views/Overlay.js.map +7 -0
  63. package/dist/cjs/views/Paragraph.js +34 -0
  64. package/dist/cjs/views/Paragraph.js.map +7 -0
  65. package/dist/cjs/views/Popover/Popover.js +157 -0
  66. package/dist/cjs/views/Popover/Popover.js.map +7 -0
  67. package/dist/cjs/views/Popover/PopoverArrow.js +52 -0
  68. package/dist/cjs/views/Popover/PopoverArrow.js.map +7 -0
  69. package/dist/cjs/views/Popover/PopoverContent.js +88 -0
  70. package/dist/cjs/views/Popover/PopoverContent.js.map +7 -0
  71. package/dist/cjs/views/Popover/PopoverContext.js +43 -0
  72. package/dist/cjs/views/Popover/PopoverContext.js.map +7 -0
  73. package/dist/cjs/views/Popover/PopoverProvider.js +35 -0
  74. package/dist/cjs/views/Popover/PopoverProvider.js.map +7 -0
  75. package/dist/cjs/views/Popover/types.js +4 -0
  76. package/dist/cjs/views/Popover/types.js.map +7 -0
  77. package/dist/cjs/views/Popper.js +235 -0
  78. package/dist/cjs/views/Popper.js.map +7 -0
  79. package/dist/cjs/views/SafeAreaProvider.js +49 -0
  80. package/dist/cjs/views/SafeAreaProvider.js.map +7 -0
  81. package/dist/cjs/views/Separator.js +43 -0
  82. package/dist/cjs/views/Separator.js.map +7 -0
  83. package/dist/cjs/views/SizableText.js +62 -0
  84. package/dist/cjs/views/SizableText.js.map +7 -0
  85. package/dist/cjs/views/Stacks.js +71 -0
  86. package/dist/cjs/views/Stacks.js.map +7 -0
  87. package/dist/cjs/views/Table.js +73 -0
  88. package/dist/cjs/views/Table.js.map +7 -0
  89. package/dist/cjs/views/Toast.js +130 -0
  90. package/dist/cjs/views/Toast.js.map +7 -0
  91. package/dist/cjs/views/Tooltip.js +93 -0
  92. package/dist/cjs/views/Tooltip.js.map +7 -0
  93. package/dist/cjs/views/TouchableOpacity.js +68 -0
  94. package/dist/cjs/views/TouchableOpacity.js.map +7 -0
  95. package/dist/cjs/views/Transitions/PresenceTransition.js +82 -0
  96. package/dist/cjs/views/Transitions/PresenceTransition.js.map +7 -0
  97. package/dist/cjs/views/Transitions/Transition.js +189 -0
  98. package/dist/cjs/views/Transitions/Transition.js.map +7 -0
  99. package/dist/cjs/views/Transitions/index.js +28 -0
  100. package/dist/cjs/views/Transitions/index.js.map +7 -0
  101. package/dist/cjs/views/Transitions/types.js +4 -0
  102. package/dist/cjs/views/Transitions/types.js.map +7 -0
  103. package/dist/cjs/views/VisuallyHidden.js +39 -0
  104. package/dist/cjs/views/VisuallyHidden.js.map +7 -0
  105. package/dist/index.cjs +29 -5
  106. package/dist/index.cjs.map +3 -3
  107. package/dist/index.js +5 -1
  108. package/dist/index.js.map +2 -2
  109. package/dist/packages/helpers/src/index.d.ts +5 -5
  110. package/dist/views/Button.js +26 -5
  111. package/dist/views/Button.js.map +2 -2
  112. package/dist/views/InteractiveFrame.js +0 -6
  113. package/dist/views/InteractiveFrame.js.map +2 -2
  114. package/dist/views/Popper.js +2 -0
  115. package/dist/views/Popper.js.map +2 -2
  116. package/dist/views/SafeAreaProvider.js +30 -0
  117. package/dist/views/SafeAreaProvider.js.map +7 -0
  118. package/dist/views/Tooltip.js +2 -2
  119. package/dist/views/Tooltip.js.map +2 -2
  120. package/package.json +13 -12
  121. package/types.d.ts +1754 -0
package/_jsx/index.js CHANGED
@@ -1,10 +1,10 @@
1
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
1
2
  export * from "@tamagui/helpers";
2
3
  export * from "@tamagui/core";
3
4
  export * from "./viewTypes";
4
5
  export * from "@tamagui/use-debounce";
5
6
  export * from "@tamagui/use-force-update";
6
7
  export * from "./hooks/useLayout";
7
- export * from "./hooks/useSafeAreaInsets";
8
8
  export * from "./hooks/useKeyboardDismissable";
9
9
  export * from "./views/BlurView";
10
10
  export * from "./views/Box";
@@ -32,4 +32,8 @@ export * from "./views/Tooltip";
32
32
  export * from "./views/TouchableOpacity";
33
33
  export * from "./views/Transitions";
34
34
  export * from "./views/VisuallyHidden";
35
+ export * from "./views/SafeAreaProvider";
35
36
  export * from "./helpers/prevent";
37
+ export {
38
+ useSafeAreaInsets
39
+ };
@@ -1,5 +1,7 @@
1
- import { themeable } from "@tamagui/core";
2
- import React, { forwardRef } from "react";
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { getTokens, themeable, useTheme } from "@tamagui/core";
4
+ import React, { forwardRef, isValidElement } from "react";
3
5
  import { InteractiveFrame } from "./InteractiveFrame";
4
6
  import { SizableText } from "./SizableText";
5
7
  React["createElement"];
@@ -13,14 +15,33 @@ const Button = InteractiveFrame.extractable(themeable(forwardRef(({
13
15
  elevation,
14
16
  theme: themeName,
15
17
  size,
18
+ themeIcon,
16
19
  ...props
17
20
  }, ref) => {
18
- return <InteractiveFrame size={size} space={space ?? size ?? "$2"} ref={ref} {...props}>
19
- {icon}
21
+ const theme = themeIcon ? useTheme() : null;
22
+ const addTheme = /* @__PURE__ */ __name((el) => isValidElement(el) ? el : !!el ? React.createElement(el, theme ? { color: theme.color2, size: getIconSize(size, -1) } : {}) : null, "addTheme");
23
+ const themedIcon = icon ? addTheme(icon) : null;
24
+ const themedIconAfter = iconAfter ? addTheme(iconAfter) : null;
25
+ return <InteractiveFrame size={size} space={space ?? (() => {
26
+ const sizes = getTokens().size;
27
+ const sizeNames = Object.keys(sizes);
28
+ const sizeDown = sizes[sizeNames[Math.max(0, sizeNames.indexOf(size || "$4") - 3)]] || "$4";
29
+ return sizeDown;
30
+ })()} ref={ref} {...props}>
31
+ {themedIcon}
20
32
  {noTextWrap ? children : !children ? null : textProps ? <SizableText color="$color2" flexGrow={0} flexShrink={1} ellipse size={size} {...textProps}>{children}</SizableText> : <SizableText size={size} color="$color2" flexGrow={0} flexShrink={1} ellipse>{children}</SizableText>}
21
- {iconAfter}
33
+ {themedIconAfter}
22
34
  </InteractiveFrame>;
23
35
  })));
36
+ const getIconSize = /* @__PURE__ */ __name((size = "$4", sizeUpDown = 0) => {
37
+ const tokens = getTokens();
38
+ const fonts = Object.keys(tokens.font);
39
+ const fontSize = (tokens.font.body || tokens.font[fonts[0]]).size;
40
+ const fontSizeNames = Object.keys(fontSize);
41
+ const nameIndex = Math.max(1, fontSizeNames.indexOf(size) + sizeUpDown);
42
+ const sizedName = fontSizeNames[nameIndex];
43
+ return (sizeUpDown === 0 ? fontSize[size] : fontSize[sizedName]) ?? 16;
44
+ }, "getIconSize");
24
45
  export {
25
46
  Button
26
47
  };
@@ -2,12 +2,6 @@ import { Variable } from "@tamagui/core";
2
2
  import { styled } from "@tamagui/core";
3
3
  import { XStack } from "./Stacks";
4
4
  const InteractiveFrame = styled(XStack, {
5
- hitSlop: {
6
- top: 5,
7
- left: 5,
8
- right: 5,
9
- bottom: 5
10
- },
11
5
  borderRadius: "$1",
12
6
  paddingVertical: "$2",
13
7
  paddingHorizontal: "$3",
@@ -3,6 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
3
3
  import { useOverlayPosition } from "@react-native-aria/overlays";
4
4
  import React, { createContext, useContext, useEffect, useRef } from "react";
5
5
  import { StyleSheet, View } from "react-native";
6
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7
  import { YStack } from "./Stacks";
7
8
  const defaultArrowHeight = 15;
8
9
  const defaultArrowWidth = 15;
@@ -26,6 +27,7 @@ const PopperContent = React.forwardRef(({ children, style, ...rest }, ref) => {
26
27
  setOverlayRef
27
28
  } = context;
28
29
  const overlayRef = useRef(null);
30
+ const { top } = useSafeAreaInsets();
29
31
  const { overlayProps, rendered, arrowProps, placement } = useOverlayPosition({
30
32
  targetRef: triggerRef,
31
33
  overlayRef,
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Platform } from "react-native";
4
+ import {
5
+ SafeAreaProvider as RNSafeAreaProvider,
6
+ initialWindowMetrics as defaultInitialWindowMetrics
7
+ } from "react-native-safe-area-context";
8
+ let defaultMetrics = null;
9
+ const SafeAreaProvider = /* @__PURE__ */ __name(({
10
+ initialWindowMetrics,
11
+ children
12
+ }) => {
13
+ if (!initialWindowMetrics && !defaultMetrics) {
14
+ defaultMetrics = Platform.select({
15
+ web: {
16
+ frame: { x: 0, y: 0, width: 0, height: 0 },
17
+ insets: { top: 0, left: 0, right: 0, bottom: 0 }
18
+ },
19
+ default: defaultInitialWindowMetrics
20
+ });
21
+ }
22
+ return <RNSafeAreaProvider initialMetrics={initialWindowMetrics ?? defaultMetrics}>{children}</RNSafeAreaProvider>;
23
+ }, "SafeAreaProvider");
24
+ export {
25
+ SafeAreaProvider
26
+ };
@@ -1,12 +1,12 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { Text, Theme } from "@tamagui/core";
3
+ import { Text, Theme, isTamaguiElement } from "@tamagui/core";
4
4
  import React from "react";
5
5
  import { HoverablePopover } from "./HoverablePopover";
6
6
  import { Paragraph } from "./Paragraph";
7
7
  import { YStack } from "./Stacks";
8
8
  const Tooltip = /* @__PURE__ */ __name(({ contents, tooltipFrameProps, ...props }) => {
9
- return <HoverablePopover placement="bottom" delay={200} disableUntilSettled {...props} trigger={(triggerProps) => React.isValidElement(props.children) ? React.cloneElement(props.children, triggerProps) : <Text fontFamily="inherit" fontSize="inherit" {...triggerProps}>{props.children}</Text>}>{({ open }) => {
9
+ return <HoverablePopover placement="bottom" delay={200} disableUntilSettled {...props} trigger={(triggerProps) => isTamaguiElement(props.children) ? React.cloneElement(props.children, triggerProps) : <Text fontFamily="inherit" fontSize="inherit" {...triggerProps}>{props.children}</Text>}>{({ open }) => {
10
10
  return open ? <Theme name="dark"><YStack margin={10} backgroundColor="$bg2" paddingHorizontal="$2" paddingVertical="$2" maxWidth={400} borderRadius="$2" shadowColor="$shadowColor" shadowRadius={2} shadowOffset={{ height: 2, width: 0 }} {...tooltipFrameProps}><Paragraph textAlign="center" fontSize={14} color="$color">{contents}</Paragraph></YStack></Theme> : null;
11
11
  }}</HoverablePopover>;
12
12
  }, "Tooltip");
@@ -0,0 +1,57 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ __markAsModule(target);
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && key !== "default")
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toModule = (module2) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ __export(exports, {
26
+ normalizeColor: () => normalizeColor
27
+ });
28
+ var import_normalize_css_color = __toModule(require("normalize-css-color"));
29
+ const normalizeColor = /* @__PURE__ */ __name((color, opacity = 1) => {
30
+ if (color == null)
31
+ return;
32
+ if (typeof color === "string" && isWebColor(color)) {
33
+ return color;
34
+ }
35
+ const colorInt = processColor(color);
36
+ if (colorInt != null) {
37
+ const r = colorInt >> 16 & 255;
38
+ const g = colorInt >> 8 & 255;
39
+ const b = colorInt & 255;
40
+ const a = (colorInt >> 24 & 255) / 255;
41
+ const alpha = (a * opacity).toFixed(2);
42
+ return `rgba(${r},${g},${b},${alpha})`;
43
+ }
44
+ }, "normalizeColor");
45
+ const isWebColor = /* @__PURE__ */ __name((color) => color === "currentcolor" || color === "currentColor" || color === "inherit" || color.indexOf("var(") === 0, "isWebColor");
46
+ const processColor = /* @__PURE__ */ __name((color) => {
47
+ if (color === void 0 || color === null) {
48
+ return color;
49
+ }
50
+ let int32Color = (0, import_normalize_css_color.default)(color);
51
+ if (int32Color === void 0 || int32Color === null) {
52
+ return void 0;
53
+ }
54
+ int32Color = (int32Color << 24 | int32Color >>> 8) >>> 0;
55
+ return int32Color;
56
+ }, "processColor");
57
+ //# sourceMappingURL=normalizeColor.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/normalizeColor.tsx"],
4
+ "sourcesContent": ["import normalizeCSSColor from 'normalize-css-color'\n\nexport const normalizeColor = (color?: number | string, opacity = 1): void | string => {\n if (color == null) return\n if (typeof color === 'string' && isWebColor(color)) {\n return color\n }\n const colorInt = processColor(color)\n if (colorInt != null) {\n const r = (colorInt >> 16) & 255\n const g = (colorInt >> 8) & 255\n const b = colorInt & 255\n const a = ((colorInt >> 24) & 255) / 255\n const alpha = (a * opacity).toFixed(2)\n return `rgba(${r},${g},${b},${alpha})`\n }\n}\n\nconst isWebColor = (color: string): boolean =>\n color === 'currentcolor' ||\n color === 'currentColor' ||\n color === 'inherit' ||\n color.indexOf('var(') === 0\n\nconst processColor = (color?: string | number): number | undefined => {\n if (color === undefined || color === null) {\n return color\n }\n // convert number and hex\n let int32Color = normalizeCSSColor(color)\n if (int32Color === undefined || int32Color === null) {\n return undefined\n }\n // @ts-ignore\n int32Color = ((int32Color << 24) | (int32Color >>> 8)) >>> 0\n // @ts-ignore\n return int32Color\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,iCAA8B;AAEvB,MAAM,iBAAiB,wBAAC,OAAyB,UAAU,MAAqB;AACrF,MAAI,SAAS;AAAM;AACnB,MAAI,OAAO,UAAU,YAAY,WAAW,QAAQ;AAClD,WAAO;AAAA;AAET,QAAM,WAAW,aAAa;AAC9B,MAAI,YAAY,MAAM;AACpB,UAAM,IAAK,YAAY,KAAM;AAC7B,UAAM,IAAK,YAAY,IAAK;AAC5B,UAAM,IAAI,WAAW;AACrB,UAAM,IAAM,aAAY,KAAM,OAAO;AACrC,UAAM,QAAS,KAAI,SAAS,QAAQ;AACpC,WAAO,QAAQ,KAAK,KAAK,KAAK;AAAA;AAAA,GAZJ;AAgB9B,MAAM,aAAa,wBAAC,UAClB,UAAU,kBACV,UAAU,kBACV,UAAU,aACV,MAAM,QAAQ,YAAY,GAJT;AAMnB,MAAM,eAAe,wBAAC,UAAgD;AACpE,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA;AAGT,MAAI,aAAa,wCAAkB;AACnC,MAAI,eAAe,UAAa,eAAe,MAAM;AACnD,WAAO;AAAA;AAGT,eAAe,eAAc,KAAO,eAAe,OAAQ;AAE3D,SAAO;AAAA,GAZY;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __export = (target, all) => {
5
+ __markAsModule(target);
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ __export(exports, {
10
+ prevent: () => prevent
11
+ });
12
+ const prevent = /* @__PURE__ */ __name((e) => [e.preventDefault(), e.stopPropagation()], "prevent");
13
+ //# sourceMappingURL=prevent.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/prevent.tsx"],
4
+ "sourcesContent": ["export const prevent = (e) => [e.preventDefault(), e.stopPropagation()]\n"],
5
+ "mappings": ";;;;;;;;AAAA;AAAA;AAAA;AAAO,MAAM,UAAU,wBAAC,MAAM,CAAC,EAAE,kBAAkB,EAAE,oBAA9B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,51 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ __markAsModule(target);
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && key !== "default")
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toModule = (module2) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ __export(exports, {
26
+ useControllableProp: () => useControllableProp,
27
+ useControllableState: () => useControllableState
28
+ });
29
+ var import_react = __toModule(require("react"));
30
+ function useControllableProp(prop, state) {
31
+ const { current: isControlled } = import_react.default.useRef(prop !== void 0);
32
+ const value = isControlled && typeof prop !== "undefined" ? prop : state;
33
+ return [isControlled, value];
34
+ }
35
+ __name(useControllableProp, "useControllableProp");
36
+ function useControllableState(props) {
37
+ const { value: valueProp, defaultValue, onChange } = props;
38
+ const [valueState, setValue] = import_react.default.useState(defaultValue);
39
+ const isControlled = valueProp !== void 0;
40
+ const value = isControlled ? valueProp : valueState;
41
+ const updateValue = import_react.default.useCallback((next) => {
42
+ const nextValue = typeof next === "function" ? next(value) : next;
43
+ if (!isControlled) {
44
+ setValue(nextValue);
45
+ }
46
+ onChange && onChange(nextValue);
47
+ }, [isControlled, onChange, value]);
48
+ return [value, updateValue];
49
+ }
50
+ __name(useControllableState, "useControllableState");
51
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useControllableState.ts"],
4
+ "sourcesContent": ["// forked from NativeBase\n// The MIT License (MIT)\n\n// Copyright (c) 2021 GeekyAnts India Pvt Ltd\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy of\n// this software and associated documentation files (the \"Software\"), to deal in\n// the Software without restriction, including without limitation the rights to\n// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n// the Software, and to permit persons to whom the Software is furnished to do so,\n// subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nimport React from 'react'\n\nexport function useControllableProp<T>(prop: T | undefined, state: T) {\n const { current: isControlled } = React.useRef(prop !== undefined)\n const value = isControlled && typeof prop !== 'undefined' ? prop : state\n return [isControlled, value] as const\n}\n\nexport interface UseControllableStateProps<T> {\n /**\n * The value to used in controlled mode\n */\n value?: T\n /**\n * The initial value to be used, in uncontrolled mode\n */\n defaultValue?: T | (() => T)\n /**\n * The callback fired when the value changes\n */\n onChange?: (value: T) => void\n /**\n * The component name (for warnings)\n */\n name?: string\n}\n\n/**\n * React hook for using controlling component state.\n * @param props\n */\nexport function useControllableState<T>(props: UseControllableStateProps<T>) {\n const { value: valueProp, defaultValue, onChange } = props\n\n const [valueState, setValue] = React.useState(defaultValue as T)\n const isControlled = valueProp !== undefined\n\n const value = isControlled ? (valueProp as T) : valueState\n\n const updateValue = React.useCallback(\n (next: any) => {\n const nextValue = typeof next === 'function' ? next(value) : next\n if (!isControlled) {\n setValue(nextValue)\n }\n onChange && onChange(nextValue)\n },\n [isControlled, onChange, value]\n )\n\n return [value, updateValue] as [T, React.Dispatch<React.SetStateAction<T>>]\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAsBA,mBAAkB;AAEX,6BAAgC,MAAqB,OAAU;AACpE,QAAM,EAAE,SAAS,iBAAiB,qBAAM,OAAO,SAAS;AACxD,QAAM,QAAQ,gBAAgB,OAAO,SAAS,cAAc,OAAO;AACnE,SAAO,CAAC,cAAc;AAAA;AAHR;AA6BT,8BAAiC,OAAqC;AAC3E,QAAM,EAAE,OAAO,WAAW,cAAc,aAAa;AAErD,QAAM,CAAC,YAAY,YAAY,qBAAM,SAAS;AAC9C,QAAM,eAAe,cAAc;AAEnC,QAAM,QAAQ,eAAgB,YAAkB;AAEhD,QAAM,cAAc,qBAAM,YACxB,CAAC,SAAc;AACb,UAAM,YAAY,OAAO,SAAS,aAAa,KAAK,SAAS;AAC7D,QAAI,CAAC,cAAc;AACjB,eAAS;AAAA;AAEX,gBAAY,SAAS;AAAA,KAEvB,CAAC,cAAc,UAAU;AAG3B,SAAO,CAAC,OAAO;AAAA;AAnBD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,89 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ __markAsModule(target);
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && key !== "default")
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toModule = (module2) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ __export(exports, {
26
+ debounce: () => debounce,
27
+ useDebounce: () => useDebounce,
28
+ useDebounceValue: () => useDebounceValue
29
+ });
30
+ var import_react = __toModule(require("react"));
31
+ function debounce(func, wait, leading) {
32
+ let timeout;
33
+ let isCancelled;
34
+ function debounced() {
35
+ isCancelled = false;
36
+ let context = this;
37
+ let args = arguments;
38
+ if (leading && !timeout) {
39
+ func.apply(context, args);
40
+ }
41
+ clearTimeout(timeout);
42
+ timeout = setTimeout(function() {
43
+ timeout = null;
44
+ if (!leading && !isCancelled) {
45
+ func.apply(context, args);
46
+ }
47
+ isCancelled = false;
48
+ }, wait);
49
+ }
50
+ __name(debounced, "debounced");
51
+ debounced.cancel = () => {
52
+ isCancelled = true;
53
+ };
54
+ return debounced;
55
+ }
56
+ __name(debounce, "debounce");
57
+ const defaultOpts = { leading: false };
58
+ function useDebounce(fn, wait, options = defaultOpts, mountArgs = []) {
59
+ const dbEffect = (0, import_react.useRef)(null);
60
+ (0, import_react.useEffect)(() => {
61
+ return () => {
62
+ var _a;
63
+ (_a = dbEffect.current) == null ? void 0 : _a.cancel();
64
+ };
65
+ }, []);
66
+ return (0, import_react.useMemo)(() => {
67
+ dbEffect.current = debounce(fn, wait, options.leading);
68
+ return dbEffect.current;
69
+ }, [options.leading, ...mountArgs]);
70
+ }
71
+ __name(useDebounce, "useDebounce");
72
+ function useDebounceValue(val, amt = 0) {
73
+ const [state, setState] = (0, import_react.useState)(val);
74
+ (0, import_react.useEffect)(() => {
75
+ let tm = setTimeout(() => {
76
+ setState((prev) => {
77
+ if (prev === val)
78
+ return prev;
79
+ return val;
80
+ });
81
+ }, amt);
82
+ return () => {
83
+ clearTimeout(tm);
84
+ };
85
+ }, [val]);
86
+ return state;
87
+ }
88
+ __name(useDebounceValue, "useDebounceValue");
89
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useDebounce.ts"],
4
+ "sourcesContent": ["import { useEffect, useMemo, useRef, useState } from 'react'\n\ntype DebounceSettings = {\n leading?: boolean\n}\n\nexport function debounce<A extends Function>(\n func: A,\n wait?: number,\n leading?: boolean\n): A & {\n cancel: Function\n} {\n let timeout: any\n let isCancelled\n function debounced() {\n isCancelled = false\n // @ts-ignore\n let context = this\n let args = arguments\n if (leading && !timeout) {\n func.apply(context, args)\n }\n clearTimeout(timeout)\n timeout = setTimeout(function () {\n timeout = null\n if (!leading && !isCancelled) {\n func.apply(context, args)\n }\n isCancelled = false\n }, wait)\n }\n debounced.cancel = () => {\n isCancelled = true\n }\n return debounced as any\n}\n\nconst defaultOpts = { leading: false }\n\nexport function useDebounce<\n A extends (...args: any) => any | undefined | null,\n DebouncedFn extends A & {\n cancel: () => void\n }\n>(fn: A, wait: number, options: DebounceSettings = defaultOpts, mountArgs: any[] = []): DebouncedFn {\n const dbEffect = useRef<DebouncedFn | null>(null)\n\n useEffect(() => {\n return () => {\n dbEffect.current?.cancel()\n }\n }, [])\n\n return useMemo(() => {\n dbEffect.current = debounce(fn, wait, options.leading) as unknown as DebouncedFn\n return dbEffect.current\n }, [options.leading, ...mountArgs])\n}\n\n/**\n * Returns a value once it stops changing after \"amt\" time.\n * Note: you may need to memo or this will keep re-rendering\n */\nexport function useDebounceValue<A>(val: A, amt = 0): A {\n const [state, setState] = useState(val)\n\n useEffect(() => {\n let tm = setTimeout(() => {\n setState((prev) => {\n if (prev === val) return prev\n return val\n })\n }, amt)\n\n return () => {\n clearTimeout(tm)\n }\n }, [val])\n\n return state\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqD;AAM9C,kBACL,MACA,MACA,SAGA;AACA,MAAI;AACJ,MAAI;AACJ,uBAAqB;AACnB,kBAAc;AAEd,QAAI,UAAU;AACd,QAAI,OAAO;AACX,QAAI,WAAW,CAAC,SAAS;AACvB,WAAK,MAAM,SAAS;AAAA;AAEtB,iBAAa;AACb,cAAU,WAAW,WAAY;AAC/B,gBAAU;AACV,UAAI,CAAC,WAAW,CAAC,aAAa;AAC5B,aAAK,MAAM,SAAS;AAAA;AAEtB,oBAAc;AAAA,OACb;AAAA;AAfI;AAiBT,YAAU,SAAS,MAAM;AACvB,kBAAc;AAAA;AAEhB,SAAO;AAAA;AA7BO;AAgChB,MAAM,cAAc,EAAE,SAAS;AAExB,qBAKL,IAAO,MAAc,UAA4B,aAAa,YAAmB,IAAiB;AAClG,QAAM,WAAW,yBAA2B;AAE5C,8BAAU,MAAM;AACd,WAAO,MAAM;AAjDjB;AAkDM,qBAAS,YAAT,mBAAkB;AAAA;AAAA,KAEnB;AAEH,SAAO,0BAAQ,MAAM;AACnB,aAAS,UAAU,SAAS,IAAI,MAAM,QAAQ;AAC9C,WAAO,SAAS;AAAA,KACf,CAAC,QAAQ,SAAS,GAAG;AAAA;AAjBV;AAwBT,0BAA6B,KAAQ,MAAM,GAAM;AACtD,QAAM,CAAC,OAAO,YAAY,2BAAS;AAEnC,8BAAU,MAAM;AACd,QAAI,KAAK,WAAW,MAAM;AACxB,eAAS,CAAC,SAAS;AACjB,YAAI,SAAS;AAAK,iBAAO;AACzB,eAAO;AAAA;AAAA,OAER;AAEH,WAAO,MAAM;AACX,mBAAa;AAAA;AAAA,KAEd,CAAC;AAEJ,SAAO;AAAA;AAhBO;",
6
+ "names": []
7
+ }
@@ -0,0 +1,94 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ __markAsModule(target);
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && key !== "default")
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toModule = (module2) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ __export(exports, {
26
+ keyboardDismissHandlerManager: () => keyboardDismissHandlerManager,
27
+ useBackHandler: () => useBackHandler,
28
+ useKeyboardDismissable: () => useKeyboardDismissable
29
+ });
30
+ var import_core = __toModule(require("@tamagui/core"));
31
+ var import_react = __toModule(require("react"));
32
+ var import_react_native = __toModule(require("react-native"));
33
+ let keyboardDismissHandlers = [];
34
+ const keyboardDismissHandlerManager = {
35
+ push: (handler) => {
36
+ keyboardDismissHandlers.push(handler);
37
+ return () => {
38
+ keyboardDismissHandlers = keyboardDismissHandlers.filter((h) => h !== handler);
39
+ };
40
+ },
41
+ length: () => keyboardDismissHandlers.length,
42
+ pop: () => {
43
+ return keyboardDismissHandlers.pop();
44
+ }
45
+ };
46
+ const useKeyboardDismissable = /* @__PURE__ */ __name(({ enabled, callback }) => {
47
+ (0, import_react.useEffect)(() => {
48
+ let cleanupFn = /* @__PURE__ */ __name(() => {
49
+ }, "cleanupFn");
50
+ if (enabled) {
51
+ cleanupFn = keyboardDismissHandlerManager.push(callback);
52
+ } else {
53
+ cleanupFn();
54
+ }
55
+ return () => {
56
+ cleanupFn();
57
+ };
58
+ }, [enabled, callback]);
59
+ useBackHandler({ enabled, callback });
60
+ }, "useKeyboardDismissable");
61
+ const callbackOnEscape = /* @__PURE__ */ __name((callback) => (e) => {
62
+ if (e.key === "Escape") {
63
+ if (!(document.activeElement instanceof HTMLInputElement) && !(document.activeElement instanceof HTMLTextAreaElement)) {
64
+ e.preventDefault();
65
+ e.stopPropagation();
66
+ callback();
67
+ }
68
+ }
69
+ }, "callbackOnEscape");
70
+ function useBackHandler({ enabled, callback }) {
71
+ (0, import_react.useEffect)(() => {
72
+ let backHandler = /* @__PURE__ */ __name(() => {
73
+ callback();
74
+ return true;
75
+ }, "backHandler");
76
+ const keyHandler = callbackOnEscape(callback);
77
+ if (enabled) {
78
+ import_react_native.BackHandler.addEventListener("hardwareBackPress", backHandler);
79
+ if (import_core.isWeb) {
80
+ window.addEventListener("keydown", keyHandler);
81
+ }
82
+ } else {
83
+ import_react_native.BackHandler.removeEventListener("hardwareBackPress", backHandler);
84
+ }
85
+ return () => {
86
+ import_react_native.BackHandler.removeEventListener("hardwareBackPress", backHandler);
87
+ if (import_core.isWeb) {
88
+ window.removeEventListener("keydown", keyHandler);
89
+ }
90
+ };
91
+ }, [enabled, callback]);
92
+ }
93
+ __name(useBackHandler, "useBackHandler");
94
+ //# sourceMappingURL=useKeyboardDismissable.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useKeyboardDismissable.tsx"],
4
+ "sourcesContent": ["// forked from NativeBase\n// The MIT License (MIT)\n\n// Copyright (c) 2021 GeekyAnts India Pvt Ltd\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy of\n// this software and associated documentation files (the \"Software\"), to deal in\n// the Software without restriction, including without limitation the rights to\n// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n// the Software, and to permit persons to whom the Software is furnished to do so,\n// subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nimport { isWeb } from '@tamagui/core'\nimport { useEffect } from 'react'\nimport { BackHandler } from 'react-native'\n\ntype IParams = {\n enabled?: boolean\n callback: () => any\n}\n\nlet keyboardDismissHandlers: Array<() => any> = []\nexport const keyboardDismissHandlerManager = {\n push: (handler: () => any) => {\n keyboardDismissHandlers.push(handler)\n return () => {\n keyboardDismissHandlers = keyboardDismissHandlers.filter((h) => h !== handler)\n }\n },\n length: () => keyboardDismissHandlers.length,\n pop: () => {\n return keyboardDismissHandlers.pop()\n },\n}\n\nexport const useKeyboardDismissable = ({ enabled, callback }: IParams) => {\n useEffect(() => {\n let cleanupFn = () => {}\n if (enabled) {\n cleanupFn = keyboardDismissHandlerManager.push(callback)\n } else {\n cleanupFn()\n }\n return () => {\n cleanupFn()\n }\n }, [enabled, callback])\n\n useBackHandler({ enabled, callback })\n}\n\nconst callbackOnEscape = (callback) => (e) => {\n if (e.key === 'Escape') {\n if (\n !(document.activeElement instanceof HTMLInputElement) &&\n !(document.activeElement instanceof HTMLTextAreaElement)\n ) {\n e.preventDefault()\n e.stopPropagation()\n callback()\n }\n }\n}\n\nexport function useBackHandler({ enabled, callback }: IParams) {\n useEffect(() => {\n let backHandler = () => {\n callback()\n return true\n }\n const keyHandler = callbackOnEscape(callback)\n if (enabled) {\n BackHandler.addEventListener('hardwareBackPress', backHandler)\n if (isWeb) {\n window.addEventListener('keydown', keyHandler)\n }\n } else {\n BackHandler.removeEventListener('hardwareBackPress', backHandler)\n }\n return () => {\n BackHandler.removeEventListener('hardwareBackPress', backHandler)\n if (isWeb) {\n window.removeEventListener('keydown', keyHandler)\n }\n }\n }, [enabled, callback])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,kBAAsB;AACtB,mBAA0B;AAC1B,0BAA4B;AAO5B,IAAI,0BAA4C;AACzC,MAAM,gCAAgC;AAAA,EAC3C,MAAM,CAAC,YAAuB;AAC5B,4BAAwB,KAAK;AAC7B,WAAO,MAAM;AACX,gCAA0B,wBAAwB,OAAO,CAAC,MAAM,MAAM;AAAA;AAAA;AAAA,EAG1E,QAAQ,MAAM,wBAAwB;AAAA,EACtC,KAAK,MAAM;AACT,WAAO,wBAAwB;AAAA;AAAA;AAI5B,MAAM,yBAAyB,wBAAC,EAAE,SAAS,eAAwB;AACxE,8BAAU,MAAM;AACd,QAAI,YAAY,6BAAM;AAAA,OAAN;AAChB,QAAI,SAAS;AACX,kBAAY,8BAA8B,KAAK;AAAA,WAC1C;AACL;AAAA;AAEF,WAAO,MAAM;AACX;AAAA;AAAA,KAED,CAAC,SAAS;AAEb,iBAAe,EAAE,SAAS;AAAA,GAbU;AAgBtC,MAAM,mBAAmB,wBAAC,aAAa,CAAC,MAAM;AAC5C,MAAI,EAAE,QAAQ,UAAU;AACtB,QACE,CAAE,UAAS,yBAAyB,qBACpC,CAAE,UAAS,yBAAyB,sBACpC;AACA,QAAE;AACF,QAAE;AACF;AAAA;AAAA;AAAA,GARmB;AAalB,wBAAwB,EAAE,SAAS,YAAqB;AAC7D,8BAAU,MAAM;AACd,QAAI,cAAc,6BAAM;AACtB;AACA,aAAO;AAAA,OAFS;AAIlB,UAAM,aAAa,iBAAiB;AACpC,QAAI,SAAS;AACX,sCAAY,iBAAiB,qBAAqB;AAClD,UAAI,mBAAO;AACT,eAAO,iBAAiB,WAAW;AAAA;AAAA,WAEhC;AACL,sCAAY,oBAAoB,qBAAqB;AAAA;AAEvD,WAAO,MAAM;AACX,sCAAY,oBAAoB,qBAAqB;AACrD,UAAI,mBAAO;AACT,eAAO,oBAAoB,WAAW;AAAA;AAAA;AAAA,KAGzC,CAAC,SAAS;AAAA;AArBC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,79 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ __markAsModule(target);
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && key !== "default")
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toModule = (module2) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ __export(exports, {
26
+ useLayout: () => useLayout
27
+ });
28
+ var import_core = __toModule(require("@tamagui/core"));
29
+ var import_react = __toModule(require("react"));
30
+ const useLayout = /* @__PURE__ */ __name((props = {}) => {
31
+ const [layout, setLayout] = (0, import_react.useState)(null);
32
+ if (!import_core.isWeb) {
33
+ return {
34
+ layout,
35
+ onLayout: props.onLayout
36
+ };
37
+ }
38
+ const ref = (0, import_react.useRef)(null);
39
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
40
+ const node = ref.current;
41
+ if (!node)
42
+ return;
43
+ let last = null;
44
+ const getNextAndCallback = /* @__PURE__ */ __name((rect) => {
45
+ var _a;
46
+ let next;
47
+ const width = Math.max(1, Math.round(rect.width));
48
+ const height = Math.max(1, Math.round(rect.height));
49
+ if (!last || width !== last.width || height !== last.height) {
50
+ next = { width, height };
51
+ }
52
+ if (next) {
53
+ (_a = props.onLayout) == null ? void 0 : _a.call(props, { nativeEvent: { layout: next } });
54
+ last = next;
55
+ return next;
56
+ }
57
+ return last;
58
+ }, "getNextAndCallback");
59
+ const update = /* @__PURE__ */ __name((rect) => {
60
+ if (props.stateless) {
61
+ getNextAndCallback(rect);
62
+ } else {
63
+ setLayout((p) => getNextAndCallback(rect));
64
+ }
65
+ }, "update");
66
+ const ro = new ResizeObserver(([{ contentRect }] = []) => {
67
+ update(contentRect);
68
+ });
69
+ ro.observe(node);
70
+ return () => {
71
+ ro.disconnect();
72
+ };
73
+ }, [ref]);
74
+ return {
75
+ layout,
76
+ ref
77
+ };
78
+ }, "useLayout");
79
+ //# sourceMappingURL=useLayout.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useLayout.tsx"],
4
+ "sourcesContent": ["import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { useRef, useState } from 'react'\nimport { LayoutChangeEvent, LayoutRectangle } from 'react-native'\n\nexport const useLayout = (props: { stateless?: boolean; onLayout?: (rect: LayoutChangeEvent) => void } = {}) => {\n const [layout, setLayout] = useState<LayoutRectangle | null>(null)\n\n if (!isWeb) {\n return {\n layout,\n onLayout: props.onLayout,\n }\n }\n\n const ref = useRef<any>(null)\n\n useIsomorphicLayoutEffect(() => {\n const node = ref.current\n if (!node) return\n // let hasUpdatedOnce = false\n let last: LayoutRectangle | null = null\n\n const getNextAndCallback = (rect: LayoutRectangle) => {\n let next\n const width = Math.max(1, Math.round(rect.width))\n const height = Math.max(1, Math.round(rect.height))\n // don't set new layout state unless the layout has actually changed\n if (!last || width !== last.width || height !== last.height) {\n next = { width, height }\n }\n if (next) {\n // @ts-expect-error\n props.onLayout?.({ nativeEvent: { layout: next } })\n last = next\n return next\n }\n return last\n }\n\n const update = (rect: LayoutRectangle) => {\n if (props.stateless) {\n getNextAndCallback(rect)\n } else {\n setLayout((p) => getNextAndCallback(rect))\n }\n }\n\n const ro = new ResizeObserver(([{ contentRect }] = []) => {\n update(contentRect)\n })\n ro.observe(node)\n\n return () => {\n ro.disconnect()\n }\n }, [ref])\n\n return {\n layout,\n ref,\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,kBAAiD;AACjD,mBAAiC;AAG1B,MAAM,YAAY,wBAAC,QAA+E,OAAO;AAC9G,QAAM,CAAC,QAAQ,aAAa,2BAAiC;AAE7D,MAAI,CAAC,mBAAO;AACV,WAAO;AAAA,MACL;AAAA,MACA,UAAU,MAAM;AAAA;AAAA;AAIpB,QAAM,MAAM,yBAAY;AAExB,6CAA0B,MAAM;AAC9B,UAAM,OAAO,IAAI;AACjB,QAAI,CAAC;AAAM;AAEX,QAAI,OAA+B;AAEnC,UAAM,qBAAqB,wBAAC,SAA0B;AAtB1D;AAuBM,UAAI;AACJ,YAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK;AAC1C,YAAM,SAAS,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK;AAE3C,UAAI,CAAC,QAAQ,UAAU,KAAK,SAAS,WAAW,KAAK,QAAQ;AAC3D,eAAO,EAAE,OAAO;AAAA;AAElB,UAAI,MAAM;AAER,oBAAM,aAAN,+BAAiB,EAAE,aAAa,EAAE,QAAQ;AAC1C,eAAO;AACP,eAAO;AAAA;AAET,aAAO;AAAA,OAdkB;AAiB3B,UAAM,SAAS,wBAAC,SAA0B;AACxC,UAAI,MAAM,WAAW;AACnB,2BAAmB;AAAA,aACd;AACL,kBAAU,CAAC,MAAM,mBAAmB;AAAA;AAAA,OAJzB;AAQf,UAAM,KAAK,IAAI,eAAe,CAAC,CAAC,EAAE,iBAAiB,OAAO;AACxD,aAAO;AAAA;AAET,OAAG,QAAQ;AAEX,WAAO,MAAM;AACX,SAAG;AAAA;AAAA,KAEJ,CAAC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA;AAAA,GAvDqB;",
6
+ "names": []
7
+ }