@tamagui/core 1.126.13 → 1.126.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useElementLayout.cjs +62 -63
- package/dist/cjs/hooks/useElementLayout.js +55 -62
- package/dist/cjs/hooks/useElementLayout.js.map +1 -1
- package/dist/cjs/hooks/useElementLayout.native.js +63 -94
- package/dist/cjs/hooks/useElementLayout.native.js.map +2 -2
- package/dist/cjs/index.cjs +5 -2
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +6 -2
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +59 -63
- package/dist/esm/hooks/useElementLayout.js.map +1 -1
- package/dist/esm/hooks/useElementLayout.mjs +62 -64
- package/dist/esm/hooks/useElementLayout.mjs.map +1 -1
- package/dist/esm/hooks/useElementLayout.native.js +77 -106
- package/dist/esm/hooks/useElementLayout.native.js.map +1 -1
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +3 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/native.js +144 -154
- package/dist/native.js.map +3 -3
- package/dist/test.native.js +141 -153
- package/dist/test.native.js.map +3 -3
- package/package.json +7 -7
- package/src/hooks/useElementLayout.tsx +106 -88
- package/src/index.tsx +8 -1
- package/types/hooks/useElementLayout.d.ts +5 -2
- package/types/hooks/useElementLayout.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/dist/cjs/index.native.js
CHANGED
|
@@ -25,10 +25,12 @@ __export(index_exports, {
|
|
|
25
25
|
Stack: () => Stack,
|
|
26
26
|
Text: () => Text,
|
|
27
27
|
View: () => View,
|
|
28
|
-
createTamagui: () => createTamagui
|
|
28
|
+
createTamagui: () => createTamagui,
|
|
29
|
+
getElementLayoutEvent: () => import_useElementLayout2.getElementLayoutEvent,
|
|
30
|
+
setOnLayoutStrategy: () => import_useElementLayout2.setOnLayoutStrategy
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
var import_react_native_media_driver = require("@tamagui/react-native-media-driver"), import_react_native_use_responder_events = require("@tamagui/react-native-use-responder-events"), import_web = require("@tamagui/web"), import_react = __toESM(require("react")), import_createOptimizedView = require("./createOptimizedView"), import_getBaseViews = require("./getBaseViews"), import_getRect = require("./helpers/getRect"), import_useElementLayout = require("./hooks/useElementLayout"), import_Pressability = require("./vendor/Pressability"),
|
|
33
|
+
var import_react_native_media_driver = require("@tamagui/react-native-media-driver"), import_react_native_use_responder_events = require("@tamagui/react-native-use-responder-events"), import_web = require("@tamagui/web"), import_react = __toESM(require("react")), import_addNativeValidStyles = require("./addNativeValidStyles"), import_createOptimizedView = require("./createOptimizedView"), import_getBaseViews = require("./getBaseViews"), import_getRect = require("./helpers/getRect"), import_useElementLayout = require("./hooks/useElementLayout"), import_Pressability = require("./vendor/Pressability"), import_useElementLayout2 = require("./hooks/useElementLayout");
|
|
32
34
|
__reExport(index_exports, require("@tamagui/web"), module.exports);
|
|
33
35
|
__reExport(index_exports, require("./reactNativeTypes"), module.exports);
|
|
34
36
|
(0, import_addNativeValidStyles.addNativeValidStyles)();
|
|
@@ -97,6 +99,8 @@ var dontComposePressabilityKeys = {
|
|
|
97
99
|
Text,
|
|
98
100
|
View,
|
|
99
101
|
createTamagui,
|
|
102
|
+
getElementLayoutEvent,
|
|
103
|
+
setOnLayoutStrategy,
|
|
100
104
|
...require("@tamagui/web"),
|
|
101
105
|
...require("./reactNativeTypes")
|
|
102
106
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
5
|
-
"names": ["addNativeValidStyles", "createTamagui", "conf", "media", "createMedia", "createTamaguiWeb", "baseViews", "getBaseViews", "setupHooks", "setElementProps", "node", "measure", "callback", "measureLayout", "relativeToNode", "success", "measureInWindow", "setTimeout", "height", "left", "top", "width", "getRect", "usePropsTransform", "elementType", "propsIn", "stateRef", "willHydrate", "process", "isDOM", "onMoveShouldSetResponder", "onMoveShouldSetResponderCapture", "onResponderEnd", "onResponderGrant", "onResponderMove", "onResponderReject", "onResponderRelease", "onResponderStart", "onResponderTerminate", "onResponderTerminationRequest", "onScrollShouldSetResponder", "onScrollShouldSetResponderCapture", "onSelectionChangeShouldSetResponder", "onSelectionChangeShouldSetResponderCapture", "onStartShouldSetResponder", "onStartShouldSetResponderCapture", "collapsable", "focusable", "accessible", "accessibilityDisabled", "onLayout", "hrefAttrs", "plainDOMProps", "href", "download", "rel", "target", "useEvents", "viewProps", "events", "setStateShallow", "staticConfig", "pseudos", "onFocus", "onBlur", "isInput", "onPressIn", "onPressOut", "onPress", "inputEvents", "composeEventHandlers", "Object", "assign", "hitSlop", "pressability", "usePressability", "env", "NODE_ENV", "console", "info", "keys", "key", "og", "val", "dontComposePressabilityKeys", "useChildren", "children", "View", "createOptimizedView", "TAMAGUI_OPTIMIZE_NATIVE_VIEWS", "Text", "React", "createElement", "onClick", "WebView", "Stack", "WebStack", "WebText"]
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;uCAA4B,+CAC5B,2CAAmC,uDAYnC,aAOO,yBACP,eAAkB,2BAElB,8BAAqC,mCACrC,6BAAoC,kCACpC,sBAA6B,2BAC7B,iBAAwB,8BACxB,0BAAgD,qCAEhD,sBAAgC,kCAGhCA,2BAIO;AAkCP,0BAAc,yBAtEd;AAyEA,0BAAc,+BAzEd;IAuCAC,kDAAAA;AAqCO,IAAMC,gBAAyC,SAACC,MAAAA;AAEnD,SAAIA,KAAKC,UACPD,KAAKC,YAAQC,8CAAYF,KAAKC,KAAK,QAGhCE,WAAA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AAcC,YAEhBC,YAAYF,iBAAaG,iCAAqBF,SAASD,UAAAA,IAEzDI,OAAOC,OAAOd,WAAWW,WAAAA;MAC3B;WACK;AAGL,MAAIV,UAAUD,UAAUe,YACtBd,OAAOc,UAAUf,UAAUe;AAI7B,UAAMC,mBAAeC,qCAAgBhB,MAAAA;AAErC,UAAIA,WACE/B,QAAQgD,IAAIC,aAAa,iBACvBnB,UAAU,SACZoB,QAAQC,KACN,sBAAsB,CAAC,CAACpB,OAAOS,OAAO,sCAAsCG,OAAOS,KACjFN,gBAAgB,CAAC,CAAA,CAAA,EAChB,GAKLf,OAAOS;AACT,iBAAWa,OAAOP,cAAc;AAC9B,cAAMQ,KAAKxB,UAAUuB,GAAAA,GACfE,MAAMT,aAAaO,GAAAA;AACzBvB,oBAAUuB,GAAAA,IACRC,MAAM,CAACE,4BAA4BH,GAAAA,QAC/BX,iCAAqBY,IAAIC,GAAAA,IACzBA;QACR;IAGN;EAEJ;EAIEE,YAAY7D,aAAa8D,UAAU5B,WAAS;AAC1C,QAAI9B,QAAQgD,IAAIC,aAAa,QAK7B;UAAIrD,gBAAgBlB,UAAUiF;AAE5B,mBAAOC,gDAAoBF,UAAU5B,WAAWpD,SAAAA;AAGlD,UAAIsB,QAAQgD,IAAIa,iCACVjE,gBAAgBlB,UAAUoF;AAE5BhC,yBAAU4B,WAAWA,UACdK,6BAAAA,QAAMC,cAAc,WAAWlC,SAAAA;;EAG5C;AAEJ,CAAA;AAEA,IAAM0B,8BAA8B;EAClCS,SAAS;AACX,GAIaN,OAAOO,WAAAA,MACPC,QAAQC,WAAAA,OACRN,OAAOO,WAAAA;",
|
|
5
|
+
"names": ["import_useElementLayout", "addNativeValidStyles", "createTamagui", "conf", "media", "createMedia", "createTamaguiWeb", "baseViews", "getBaseViews", "setupHooks", "setElementProps", "node", "measure", "callback", "measureLayout", "relativeToNode", "success", "measureInWindow", "setTimeout", "height", "left", "top", "width", "getRect", "usePropsTransform", "elementType", "propsIn", "stateRef", "willHydrate", "process", "isDOM", "onMoveShouldSetResponder", "onMoveShouldSetResponderCapture", "onResponderEnd", "onResponderGrant", "onResponderMove", "onResponderReject", "onResponderRelease", "onResponderStart", "onResponderTerminate", "onResponderTerminationRequest", "onScrollShouldSetResponder", "onScrollShouldSetResponderCapture", "onSelectionChangeShouldSetResponder", "onSelectionChangeShouldSetResponderCapture", "onStartShouldSetResponder", "onStartShouldSetResponderCapture", "collapsable", "focusable", "accessible", "accessibilityDisabled", "onLayout", "hrefAttrs", "plainDOMProps", "href", "download", "rel", "target", "useEvents", "viewProps", "events", "setStateShallow", "staticConfig", "pseudos", "onFocus", "onBlur", "isInput", "onPressIn", "onPressOut", "onPress", "inputEvents", "composeEventHandlers", "Object", "assign", "hitSlop", "pressability", "usePressability", "env", "NODE_ENV", "console", "info", "keys", "key", "og", "val", "dontComposePressabilityKeys", "useChildren", "children", "View", "createOptimizedView", "TAMAGUI_OPTIMIZE_NATIVE_VIEWS", "Text", "React", "createElement", "onClick", "WebView", "Stack", "WebStack", "WebText"]
|
|
6
6
|
}
|
|
@@ -1,85 +1,81 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
onLayout(event);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}), typeof window.addEventListener == "function")) {
|
|
14
|
-
let tm;
|
|
15
|
-
window.addEventListener("resize", () => {
|
|
16
|
-
clearTimeout(tm), tm = setTimeout(() => {
|
|
17
|
-
resizeListeners.forEach((cb) => cb());
|
|
18
|
-
}, 4);
|
|
19
|
-
});
|
|
1
|
+
import { isClient, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
isEqualShallow,
|
|
4
|
+
___onDidFinishClientRender
|
|
5
|
+
} from "@tamagui/web";
|
|
6
|
+
const LayoutHandlers = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set();
|
|
7
|
+
let status = "active";
|
|
8
|
+
function setOnLayoutStrategy(state) {
|
|
9
|
+
status = state;
|
|
20
10
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
const NodeRectCache = /* @__PURE__ */ new WeakMap(), ParentRectCache = /* @__PURE__ */ new WeakMap(), rAF = typeof window < "u" ? window.requestAnimationFrame : void 0;
|
|
12
|
+
if (isClient)
|
|
13
|
+
if (rAF) {
|
|
14
|
+
let updateLayoutIfChanged = function(node) {
|
|
15
|
+
const nodeRect = node.getBoundingClientRect(), parentNode = node.parentElement, parentRect = parentNode?.getBoundingClientRect(), onLayout = LayoutHandlers.get(node);
|
|
16
|
+
if (typeof onLayout != "function") return;
|
|
17
|
+
const cachedRect = NodeRectCache.get(node), cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
18
|
+
if (!cachedRect || // has changed one rect
|
|
19
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
20
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
21
|
+
const event = getElementLayoutEvent(node);
|
|
22
|
+
avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
|
|
23
|
+
}
|
|
24
|
+
}, layoutOnAnimationFrame = function() {
|
|
25
|
+
status !== "inactive" && Nodes.forEach(updateLayoutIfChanged), rAF(layoutOnAnimationFrame);
|
|
26
|
+
}, avoidUpdates = !0;
|
|
27
|
+
const queuedUpdates = /* @__PURE__ */ new Map();
|
|
28
|
+
___onDidFinishClientRender(() => {
|
|
29
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach((cb) => cb()), queuedUpdates.clear());
|
|
30
|
+
}), rAF(layoutOnAnimationFrame);
|
|
31
|
+
} else
|
|
32
|
+
process.env.NODE_ENV === "development" && console.warn(
|
|
33
|
+
"No requestAnimationFrame - please polyfill for onLayout to work correctly"
|
|
34
|
+
);
|
|
35
|
+
const getElementLayoutEvent = (target) => {
|
|
36
|
+
let res = null;
|
|
37
|
+
if (measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
38
|
+
res = {
|
|
24
39
|
nativeEvent: {
|
|
25
40
|
layout: { x, y, width, height, left, top },
|
|
26
41
|
target
|
|
27
42
|
},
|
|
28
43
|
timeStamp: Date.now()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
};
|
|
45
|
+
}), !res)
|
|
46
|
+
throw new Error("\u203C\uFE0F");
|
|
47
|
+
return res;
|
|
48
|
+
}, measureLayout = (node, relativeTo, callback) => {
|
|
49
|
+
const relativeNode = relativeTo || node?.parentElement;
|
|
33
50
|
if (relativeNode instanceof HTMLElement) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
relativeNodeDim
|
|
43
|
-
);
|
|
44
|
-
callback(x, y, width, height, left, top);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
51
|
+
const nodeDim = node.getBoundingClientRect(), relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
52
|
+
if (relativeNodeDim && nodeDim) {
|
|
53
|
+
const { x, y, width, height, left, top } = getRelativeDimensions(
|
|
54
|
+
nodeDim,
|
|
55
|
+
relativeNodeDim
|
|
56
|
+
);
|
|
57
|
+
callback(x, y, width, height, left, top);
|
|
58
|
+
}
|
|
47
59
|
}
|
|
48
60
|
}, getRelativeDimensions = (a, b) => {
|
|
49
61
|
const { height, left, top, width } = a, x = left - b.left, y = top - b.top;
|
|
50
62
|
return { x, y, width, height, left, top };
|
|
51
|
-
}
|
|
52
|
-
function fallbackToSync() {
|
|
53
|
-
resolve(getBoundingClientRect(element));
|
|
54
|
-
}
|
|
55
|
-
const tm = setTimeout(fallbackToSync, 10);
|
|
56
|
-
new IntersectionObserver(
|
|
57
|
-
(entries, ob) => {
|
|
58
|
-
clearTimeout(tm), ob.disconnect(), resolve(entries[0]?.boundingClientRect);
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
threshold: 1e-4
|
|
62
|
-
}
|
|
63
|
-
).observe(element);
|
|
64
|
-
});
|
|
63
|
+
};
|
|
65
64
|
function useElementLayout(ref, onLayout) {
|
|
66
65
|
const node = ref.current?.host;
|
|
67
66
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(() => {
|
|
68
|
-
if (!
|
|
67
|
+
if (!onLayout) return;
|
|
69
68
|
const node2 = ref.current?.host;
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
return resizeListeners.add(onResize), resizeObserver.observe(node2), () => {
|
|
76
|
-
LayoutHandlers.delete(node2), resizeListeners.delete(onResize), resizeObserver?.unobserve(node2);
|
|
77
|
-
};
|
|
69
|
+
if (node2)
|
|
70
|
+
return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), () => {
|
|
71
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
72
|
+
};
|
|
78
73
|
}, [ref, !!onLayout]);
|
|
79
74
|
}
|
|
80
75
|
export {
|
|
81
|
-
|
|
76
|
+
getElementLayoutEvent,
|
|
82
77
|
measureLayout,
|
|
78
|
+
setOnLayoutStrategy,
|
|
83
79
|
useElementLayout
|
|
84
80
|
};
|
|
85
81
|
//# sourceMappingURL=useElementLayout.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useElementLayout.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,iCAAiC;
|
|
4
|
+
"mappings": "AAAA,SAAS,UAAU,iCAAiC;AACpD;AAAA,EACE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A,KAAI,GACjB,eAAe,OAAOA,KAAI,GAC1B,cAAc,OAAOA,KAAI;AAAA,MAC3B;AAAA,EACF,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;AACtB;",
|
|
5
5
|
"names": ["node"]
|
|
6
6
|
}
|
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
-
import {
|
|
1
|
+
import { isClient, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { isEqualShallow, ___onDidFinishClientRender } from "@tamagui/web";
|
|
3
3
|
const LayoutHandlers = /* @__PURE__ */new WeakMap(),
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
target
|
|
9
|
-
} of entries) {
|
|
10
|
-
const onLayout = LayoutHandlers.get(target);
|
|
11
|
-
if (typeof onLayout != "function") return;
|
|
12
|
-
measureElement(target).then(event => {
|
|
13
|
-
onLayout(event);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}), typeof window.addEventListener == "function")) {
|
|
17
|
-
let tm;
|
|
18
|
-
window.addEventListener("resize", () => {
|
|
19
|
-
clearTimeout(tm), tm = setTimeout(() => {
|
|
20
|
-
resizeListeners.forEach(cb => cb());
|
|
21
|
-
}, 4);
|
|
22
|
-
});
|
|
4
|
+
Nodes = /* @__PURE__ */new Set();
|
|
5
|
+
let status = "active";
|
|
6
|
+
function setOnLayoutStrategy(state) {
|
|
7
|
+
status = state;
|
|
23
8
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
const NodeRectCache = /* @__PURE__ */new WeakMap(),
|
|
10
|
+
ParentRectCache = /* @__PURE__ */new WeakMap(),
|
|
11
|
+
rAF = typeof window < "u" ? window.requestAnimationFrame : void 0;
|
|
12
|
+
if (isClient) if (rAF) {
|
|
13
|
+
let updateLayoutIfChanged = function (node) {
|
|
14
|
+
const nodeRect = node.getBoundingClientRect(),
|
|
15
|
+
parentNode = node.parentElement,
|
|
16
|
+
parentRect = parentNode?.getBoundingClientRect(),
|
|
17
|
+
onLayout = LayoutHandlers.get(node);
|
|
18
|
+
if (typeof onLayout != "function") return;
|
|
19
|
+
const cachedRect = NodeRectCache.get(node),
|
|
20
|
+
cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
21
|
+
if (!cachedRect ||
|
|
22
|
+
// has changed one rect
|
|
23
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
24
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
25
|
+
const event = getElementLayoutEvent(node);
|
|
26
|
+
avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
layoutOnAnimationFrame = function () {
|
|
30
|
+
status !== "inactive" && Nodes.forEach(updateLayoutIfChanged), rAF(layoutOnAnimationFrame);
|
|
31
|
+
},
|
|
32
|
+
avoidUpdates = !0;
|
|
33
|
+
const queuedUpdates = /* @__PURE__ */new Map();
|
|
34
|
+
___onDidFinishClientRender(() => {
|
|
35
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(cb => cb()), queuedUpdates.clear());
|
|
36
|
+
}), rAF(layoutOnAnimationFrame);
|
|
37
|
+
} else process.env.NODE_ENV === "development" && console.warn("No requestAnimationFrame - please polyfill for onLayout to work correctly");
|
|
38
|
+
const getElementLayoutEvent = target => {
|
|
39
|
+
let res = null;
|
|
40
|
+
if (measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
41
|
+
res = {
|
|
27
42
|
nativeEvent: {
|
|
28
43
|
layout: {
|
|
29
44
|
x,
|
|
@@ -36,27 +51,26 @@ const measureElement = async target => new Promise(res => {
|
|
|
36
51
|
target
|
|
37
52
|
},
|
|
38
53
|
timeStamp: Date.now()
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
};
|
|
55
|
+
}), !res) throw new Error("\u203C\uFE0F");
|
|
56
|
+
return res;
|
|
57
|
+
},
|
|
43
58
|
measureLayout = (node, relativeTo, callback) => {
|
|
44
|
-
const relativeNode = relativeTo || node?.
|
|
59
|
+
const relativeNode = relativeTo || node?.parentElement;
|
|
45
60
|
if (relativeNode instanceof HTMLElement) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
61
|
+
const nodeDim = node.getBoundingClientRect(),
|
|
62
|
+
relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
63
|
+
if (relativeNodeDim && nodeDim) {
|
|
64
|
+
const {
|
|
65
|
+
x,
|
|
66
|
+
y,
|
|
67
|
+
width,
|
|
68
|
+
height,
|
|
69
|
+
left,
|
|
70
|
+
top
|
|
71
|
+
} = getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
72
|
+
callback(x, y, width, height, left, top);
|
|
73
|
+
}
|
|
60
74
|
}
|
|
61
75
|
},
|
|
62
76
|
getRelativeDimensions = (a, b) => {
|
|
@@ -76,32 +90,16 @@ const measureElement = async target => new Promise(res => {
|
|
|
76
90
|
left,
|
|
77
91
|
top
|
|
78
92
|
};
|
|
79
|
-
}
|
|
80
|
-
getBoundingClientRectAsync = element => new Promise(resolve => {
|
|
81
|
-
function fallbackToSync() {
|
|
82
|
-
resolve(getBoundingClientRect(element));
|
|
83
|
-
}
|
|
84
|
-
const tm = setTimeout(fallbackToSync, 10);
|
|
85
|
-
new IntersectionObserver((entries, ob) => {
|
|
86
|
-
clearTimeout(tm), ob.disconnect(), resolve(entries[0]?.boundingClientRect);
|
|
87
|
-
}, {
|
|
88
|
-
threshold: 1e-4
|
|
89
|
-
}).observe(element);
|
|
90
|
-
});
|
|
93
|
+
};
|
|
91
94
|
function useElementLayout(ref, onLayout) {
|
|
92
95
|
const node = ref.current?.host;
|
|
93
96
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(() => {
|
|
94
|
-
if (!
|
|
97
|
+
if (!onLayout) return;
|
|
95
98
|
const node2 = ref.current?.host;
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
const onResize = () => {
|
|
99
|
-
measureElement(node2).then(onLayout);
|
|
100
|
-
};
|
|
101
|
-
return resizeListeners.add(onResize), resizeObserver.observe(node2), () => {
|
|
102
|
-
LayoutHandlers.delete(node2), resizeListeners.delete(onResize), resizeObserver?.unobserve(node2);
|
|
99
|
+
if (node2) return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), () => {
|
|
100
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
103
101
|
};
|
|
104
102
|
}, [ref, !!onLayout]);
|
|
105
103
|
}
|
|
106
|
-
export {
|
|
104
|
+
export { getElementLayoutEvent, measureLayout, setOnLayoutStrategy, useElementLayout };
|
|
107
105
|
//# sourceMappingURL=useElementLayout.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useIsomorphicLayoutEffect","
|
|
1
|
+
{"version":3,"names":["isClient","useIsomorphicLayoutEffect","isEqualShallow","___onDidFinishClientRender","LayoutHandlers","WeakMap","Nodes","Set","status","setOnLayoutStrategy","state","NodeRectCache","ParentRectCache","rAF","window","requestAnimationFrame","updateLayoutIfChanged","node","nodeRect","getBoundingClientRect","parentNode","parentElement","parentRect","onLayout","get","cachedRect","cachedParentRect","set","event","getElementLayoutEvent","avoidUpdates","queuedUpdates","layoutOnAnimationFrame","forEach","Map","cb","clear","process","env","NODE_ENV","console","warn","target","res","measureLayout","x","y","width","height","left","top","nativeEvent","layout","timeStamp","Date","now","Error","relativeTo","callback","relativeNode","HTMLElement","nodeDim","relativeNodeDim","getRelativeDimensions","a","b","useElementLayout","ref","current","host","node2","add","delete"],"sources":["../../../src/hooks/useElementLayout.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,EAAUC,yBAAA,QAAiC;AACpD,SACEC,cAAA,EAEAC,0BAAA,QACK;AAGP,MAAMC,cAAA,GAAiB,mBAAIC,OAAA,CAA+B;EACpDC,KAAA,GAAQ,mBAAIC,GAAA,CAAiB;AAInC,IAAIC,MAAA,GAAkC;AAC/B,SAASC,oBAAoBC,KAAA,EAAgC;EAClEF,MAAA,GAASE,KAAA;AACX;AAmBA,MAAMC,aAAA,GAAgB,mBAAIN,OAAA,CAA8B;EAClDO,eAAA,GAAkB,mBAAIP,OAAA,CAA8B;EAEpDQ,GAAA,GAAM,OAAOC,MAAA,GAAW,MAAcA,MAAA,CAAOC,qBAAA,GAAwB;AAE3E,IAAIf,QAAA,EACF,IAAIa,GAAA,EAAK;EAaP,IAASG,qBAAA,GAAT,SAAAA,CAA+BC,IAAA,EAAmB;MAChD,MAAMC,QAAA,GAAWD,IAAA,CAAKE,qBAAA,CAAsB;QACtCC,UAAA,GAAaH,IAAA,CAAKI,aAAA;QAClBC,UAAA,GAAaF,UAAA,EAAYD,qBAAA,CAAsB;QAE/CI,QAAA,GAAWnB,cAAA,CAAeoB,GAAA,CAAIP,IAAI;MACxC,IAAI,OAAOM,QAAA,IAAa,YAAY;MAEpC,MAAME,UAAA,GAAad,aAAA,CAAca,GAAA,CAAIP,IAAI;QACnCS,gBAAA,GAAmBN,UAAA,GAAaT,aAAA,CAAca,GAAA,CAAIJ,UAAU,IAAI;MAEtE,IACE,CAACK,UAAA;MAAA;MAEA,CAACvB,cAAA,CAAeuB,UAAA,EAAYP,QAAQ,MAClC,CAACQ,gBAAA,IAAoB,CAACxB,cAAA,CAAewB,gBAAA,EAAkBJ,UAAU,IACpE;QACAX,aAAA,CAAcgB,GAAA,CAAIV,IAAA,EAAMC,QAAQ,GAC5BI,UAAA,I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AAA,EAEL,OAAAlE,cAAA,CAAeuB,GAAA,CAAI2C,KAAA,EAAM/C,QAAQ,GACjCjB,KAAA,CAAMiE,GAAA,CAAID,KAAI,GACd/C,QAAA,CAASM,qBAAA,CAAsByC,KAAI,CAAC,GAE7B,MAAM;MACXhE,KAAA,CAAMkE,MAAA,CAAOF,KAAI,GACjBlE,cAAA,CAAeoE,MAAA,CAAOF,KAAI,GAC1B3D,aAAA,CAAc6D,MAAA,CAAOF,KAAI;IAC3B;EACF,GAAG,CAACH,GAAA,EAAK,CAAC,CAAC5C,QAAQ,CAAC;AACtB","ignoreList":[]}
|
|
@@ -1,91 +1,83 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
-
import {
|
|
3
|
-
function _type_of(obj) {
|
|
4
|
-
"@swc/helpers - typeof";
|
|
5
|
-
|
|
6
|
-
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
7
|
-
}
|
|
1
|
+
import { isClient, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { isEqualShallow, ___onDidFinishClientRender } from "@tamagui/web";
|
|
8
3
|
var LayoutHandlers = /* @__PURE__ */new WeakMap(),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
_didIteratorError = !1,
|
|
14
|
-
_iteratorError = void 0;
|
|
15
|
-
try {
|
|
16
|
-
for (var _loop = function () {
|
|
17
|
-
var {
|
|
18
|
-
target
|
|
19
|
-
} = _step.value,
|
|
20
|
-
onLayout = LayoutHandlers.get(target);
|
|
21
|
-
if (typeof onLayout != "function") return {
|
|
22
|
-
v: void 0
|
|
23
|
-
};
|
|
24
|
-
measureElement(target).then(function (event) {
|
|
25
|
-
onLayout(event);
|
|
26
|
-
});
|
|
27
|
-
}, _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
28
|
-
var _ret = _loop();
|
|
29
|
-
if (_type_of(_ret) === "object") return _ret.v;
|
|
30
|
-
}
|
|
31
|
-
} catch (err) {
|
|
32
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
33
|
-
} finally {
|
|
34
|
-
try {
|
|
35
|
-
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
36
|
-
} finally {
|
|
37
|
-
if (_didIteratorError) throw _iteratorError;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}), typeof window.addEventListener == "function")) {
|
|
41
|
-
var tm;
|
|
42
|
-
window.addEventListener("resize", function () {
|
|
43
|
-
clearTimeout(tm), tm = setTimeout(function () {
|
|
44
|
-
resizeListeners.forEach(function (cb) {
|
|
45
|
-
return cb();
|
|
46
|
-
});
|
|
47
|
-
}, 4);
|
|
48
|
-
});
|
|
4
|
+
Nodes = /* @__PURE__ */new Set(),
|
|
5
|
+
status = "active";
|
|
6
|
+
function setOnLayoutStrategy(state) {
|
|
7
|
+
status = state;
|
|
49
8
|
}
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
9
|
+
var NodeRectCache = /* @__PURE__ */new WeakMap(),
|
|
10
|
+
ParentRectCache = /* @__PURE__ */new WeakMap(),
|
|
11
|
+
rAF = typeof window < "u" ? window.requestAnimationFrame : void 0;
|
|
12
|
+
if (isClient) if (rAF) {
|
|
13
|
+
let updateLayoutIfChanged = function (node) {
|
|
14
|
+
var nodeRect = node.getBoundingClientRect(),
|
|
15
|
+
parentNode = node.parentElement,
|
|
16
|
+
parentRect = parentNode?.getBoundingClientRect(),
|
|
17
|
+
onLayout = LayoutHandlers.get(node);
|
|
18
|
+
if (typeof onLayout == "function") {
|
|
19
|
+
var cachedRect = NodeRectCache.get(node),
|
|
20
|
+
cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
21
|
+
if (!cachedRect ||
|
|
22
|
+
// has changed one rect
|
|
23
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
24
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
25
|
+
var event = getElementLayoutEvent(node);
|
|
26
|
+
avoidUpdates ? queuedUpdates.set(node, function () {
|
|
27
|
+
return onLayout(event);
|
|
28
|
+
}) : onLayout(event);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
layoutOnAnimationFrame = function () {
|
|
33
|
+
status !== "inactive" && Nodes.forEach(updateLayoutIfChanged), rAF(layoutOnAnimationFrame);
|
|
34
|
+
};
|
|
35
|
+
var updateLayoutIfChanged2 = updateLayoutIfChanged,
|
|
36
|
+
layoutOnAnimationFrame2 = layoutOnAnimationFrame,
|
|
37
|
+
avoidUpdates = !0,
|
|
38
|
+
queuedUpdates = /* @__PURE__ */new Map();
|
|
39
|
+
___onDidFinishClientRender(function () {
|
|
40
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(function (cb) {
|
|
41
|
+
return cb();
|
|
42
|
+
}), queuedUpdates.clear());
|
|
43
|
+
}), rAF(layoutOnAnimationFrame);
|
|
44
|
+
} else process.env.NODE_ENV === "development" && console.warn("No requestAnimationFrame - please polyfill for onLayout to work correctly");
|
|
45
|
+
var getElementLayoutEvent = function (target) {
|
|
46
|
+
var res = null;
|
|
47
|
+
if (measureLayout(target, null, function (x, y, width, height, left, top) {
|
|
48
|
+
res = {
|
|
49
|
+
nativeEvent: {
|
|
50
|
+
layout: {
|
|
79
51
|
x,
|
|
80
52
|
y,
|
|
81
53
|
width,
|
|
82
54
|
height,
|
|
83
55
|
left,
|
|
84
56
|
top
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
57
|
+
},
|
|
58
|
+
target
|
|
59
|
+
},
|
|
60
|
+
timeStamp: Date.now()
|
|
61
|
+
};
|
|
62
|
+
}), !res) throw new Error("\u203C\uFE0F");
|
|
63
|
+
return res;
|
|
64
|
+
},
|
|
65
|
+
measureLayout = function (node, relativeTo, callback) {
|
|
66
|
+
var relativeNode = relativeTo || node?.parentElement;
|
|
67
|
+
if (relativeNode instanceof HTMLElement) {
|
|
68
|
+
var nodeDim = node.getBoundingClientRect(),
|
|
69
|
+
relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
70
|
+
if (relativeNodeDim && nodeDim) {
|
|
71
|
+
var {
|
|
72
|
+
x,
|
|
73
|
+
y,
|
|
74
|
+
width,
|
|
75
|
+
height,
|
|
76
|
+
left,
|
|
77
|
+
top
|
|
78
|
+
} = getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
79
|
+
callback(x, y, width, height, left, top);
|
|
80
|
+
}
|
|
89
81
|
}
|
|
90
82
|
},
|
|
91
83
|
getRelativeDimensions = function (a, b) {
|
|
@@ -105,40 +97,19 @@ var measureElement = async function (target) {
|
|
|
105
97
|
left,
|
|
106
98
|
top
|
|
107
99
|
};
|
|
108
|
-
},
|
|
109
|
-
getBoundingClientRectAsync = function (element) {
|
|
110
|
-
return new Promise(function (resolve) {
|
|
111
|
-
function fallbackToSync() {
|
|
112
|
-
resolve(getBoundingClientRect(element));
|
|
113
|
-
}
|
|
114
|
-
var tm = setTimeout(fallbackToSync, 10),
|
|
115
|
-
observer = new IntersectionObserver(function (entries, ob) {
|
|
116
|
-
var _entries_;
|
|
117
|
-
clearTimeout(tm), ob.disconnect(), resolve((_entries_ = entries[0]) === null || _entries_ === void 0 ? void 0 : _entries_.boundingClientRect);
|
|
118
|
-
}, {
|
|
119
|
-
threshold: 1e-4
|
|
120
|
-
});
|
|
121
|
-
observer.observe(element);
|
|
122
|
-
});
|
|
123
100
|
};
|
|
124
101
|
function useElementLayout(ref, onLayout) {
|
|
125
102
|
var _ref_current,
|
|
126
103
|
node = (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host;
|
|
127
104
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(function () {
|
|
128
105
|
var _ref_current2;
|
|
129
|
-
if (
|
|
106
|
+
if (onLayout) {
|
|
130
107
|
var node2 = (_ref_current2 = ref.current) === null || _ref_current2 === void 0 ? void 0 : _ref_current2.host;
|
|
131
|
-
if (node2) {
|
|
132
|
-
LayoutHandlers.
|
|
133
|
-
|
|
134
|
-
measureElement(node2).then(onLayout);
|
|
135
|
-
};
|
|
136
|
-
return resizeListeners.add(onResize), resizeObserver.observe(node2), function () {
|
|
137
|
-
LayoutHandlers.delete(node2), resizeListeners.delete(onResize), resizeObserver?.unobserve(node2);
|
|
138
|
-
};
|
|
139
|
-
}
|
|
108
|
+
if (node2) return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), function () {
|
|
109
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
110
|
+
};
|
|
140
111
|
}
|
|
141
112
|
}, [ref, !!onLayout]);
|
|
142
113
|
}
|
|
143
|
-
export {
|
|
114
|
+
export { getElementLayoutEvent, measureLayout, setOnLayoutStrategy, useElementLayout };
|
|
144
115
|
//# sourceMappingURL=useElementLayout.native.js.map
|