@tamagui/core 1.126.13-1747813753833 → 1.126.13-1747874018127
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 +56 -63
- package/dist/cjs/hooks/useElementLayout.js +44 -61
- package/dist/cjs/hooks/useElementLayout.js.map +1 -1
- package/dist/cjs/hooks/useElementLayout.native.js +55 -94
- package/dist/cjs/hooks/useElementLayout.native.js.map +2 -2
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +4 -2
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +48 -62
- package/dist/esm/hooks/useElementLayout.js.map +1 -1
- package/dist/esm/hooks/useElementLayout.mjs +57 -64
- package/dist/esm/hooks/useElementLayout.mjs.map +1 -1
- package/dist/esm/hooks/useElementLayout.native.js +72 -106
- package/dist/esm/hooks/useElementLayout.native.js.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/native.js +85 -115
- package/dist/native.js.map +2 -2
- package/dist/test.native.js +85 -115
- package/dist/test.native.js.map +2 -2
- package/package.json +7 -7
- package/src/hooks/useElementLayout.tsx +87 -88
- package/src/index.tsx +6 -0
- package/types/hooks/useElementLayout.d.ts +2 -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
|
@@ -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,6BAAoC,kCACpC,sBAA6B,2BAC7B,iBAAwB,8BACxB,0BAAgD,qCAEhD,sBAAgC,kCAChC,8BAAqC,mCAGrCA,2BAGO;AAkCP,0BAAc,yBArEd;AAwEA,0BAAc,+BAxEd;IAsCAC,kDAAAA;AAqCO,IAAMC,gBAAyC,SAACC,MAAAA;AAEnD,SAAIA,KAAKC,UACPD,KAAKC,YAAQC,8CAAYF,KAAKC,KAAK,QAGhCE,WAAAA,eAAiBH,IAAAA;AAC1B,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AaG,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,84 +1,70 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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(), NodeRectCache = /* @__PURE__ */ new WeakMap(), ParentRectCache = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
if (isClient && typeof requestAnimationFrame == "function") {
|
|
8
|
+
let updateLayoutIfChanged = function(node) {
|
|
9
|
+
const nodeRect = node.getBoundingClientRect(), parentNode = node.parentElement, parentRect = parentNode?.getBoundingClientRect(), onLayout = LayoutHandlers.get(node);
|
|
8
10
|
if (typeof onLayout != "function") return;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const cachedRect = NodeRectCache.get(node), cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
12
|
+
if (!cachedRect || // has changed one rect
|
|
13
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
14
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
15
|
+
const event = getElementLayoutEvent(node);
|
|
16
|
+
avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
|
|
17
|
+
}
|
|
18
|
+
}, layoutOnAnimationFrame = function() {
|
|
19
|
+
Nodes.forEach(updateLayoutIfChanged), requestAnimationFrame(layoutOnAnimationFrame);
|
|
20
|
+
}, avoidUpdates = !0;
|
|
21
|
+
const queuedUpdates = /* @__PURE__ */ new Map();
|
|
22
|
+
___onDidFinishClientRender(() => {
|
|
23
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach((cb) => cb()), queuedUpdates.clear());
|
|
24
|
+
}), requestAnimationFrame(layoutOnAnimationFrame);
|
|
20
25
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const getElementLayoutEvent = (target) => {
|
|
27
|
+
let res = null;
|
|
28
|
+
if (measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
29
|
+
res = {
|
|
24
30
|
nativeEvent: {
|
|
25
31
|
layout: { x, y, width, height, left, top },
|
|
26
32
|
target
|
|
27
33
|
},
|
|
28
34
|
timeStamp: Date.now()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
};
|
|
36
|
+
}), !res)
|
|
37
|
+
throw new Error("\u203C\uFE0F");
|
|
38
|
+
return res;
|
|
39
|
+
}, measureLayout = (node, relativeTo, callback) => {
|
|
40
|
+
const relativeNode = relativeTo || node?.parentElement;
|
|
33
41
|
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
|
-
});
|
|
42
|
+
const nodeDim = node.getBoundingClientRect(), relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
43
|
+
if (relativeNodeDim && nodeDim) {
|
|
44
|
+
const { x, y, width, height, left, top } = getRelativeDimensions(
|
|
45
|
+
nodeDim,
|
|
46
|
+
relativeNodeDim
|
|
47
|
+
);
|
|
48
|
+
callback(x, y, width, height, left, top);
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
}, getRelativeDimensions = (a, b) => {
|
|
49
52
|
const { height, left, top, width } = a, x = left - b.left, y = top - b.top;
|
|
50
53
|
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
|
-
});
|
|
54
|
+
};
|
|
65
55
|
function useElementLayout(ref, onLayout) {
|
|
66
56
|
const node = ref.current?.host;
|
|
67
57
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(() => {
|
|
68
|
-
if (!
|
|
58
|
+
if (!onLayout) return;
|
|
69
59
|
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
|
-
};
|
|
60
|
+
if (node2)
|
|
61
|
+
return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), () => {
|
|
62
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
63
|
+
};
|
|
78
64
|
}, [ref, !!onLayout]);
|
|
79
65
|
}
|
|
80
66
|
export {
|
|
81
|
-
|
|
67
|
+
getElementLayoutEvent,
|
|
82
68
|
measureLayout,
|
|
83
69
|
useElementLayout
|
|
84
70
|
};
|
|
@@ -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;AAAA,EAEA;AAAA,OACK;AAGP,MAAM,iBAAiB,oBAAI,QAA+B,GACpD,QAAQ,oBAAI,IAAiB,GAmB7B,gBAAgB,oBAAI,QAA8B,GAClD,kBAAkB,oBAAI,QAA8B;AAE1D,IAAI,YAAY,OAAO,yBAA0B,YAAY;AAa3D,MAAS,wBAAT,SAA+B,MAAmB;AAChD,UAAM,WAAW,KAAK,sBAAsB,GACtC,aAAa,KAAK,eAClB,aAAa,YAAY,sBAAsB,GAE/C,WAAW,eAAe,IAAI,IAAI;AACxC,QAAI,OAAO,YAAa,WAAY;AAEpC,UAAM,aAAa,cAAc,IAAI,IAAI,GACnC,mBAAmB,aAAa,cAAc,IAAI,UAAU,IAAI;AAEtE,QACE,CAAC;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S,GAAG,GAAG,OAAO,QAAQ,MAAM,GAAG;AAAA,IACzC;AAAA,EACF;AACF,GAEM,wBAAwB,CAAC,GAAoB,MAAuB;AACxE,QAAM,EAAE,QAAQ,MAAM,KAAK,MAAM,IAAI,GAC/B,IAAI,OAAO,EAAE,MACb,IAAI,MAAM,EAAE;AAClB,SAAO,EAAE,GAAG,GAAG,OAAO,QAAQ,MAAM,IAAI;AAC1C;AAEO,SAAS,iBACd,KACA,UACA;AAEA,QAAM,OAAO,IAAI,SAAS;AAC1B,EAAI,QAAQ,YACV,eAAe,IAAI,MAAM,QAAQ,GAGnC,0BAA0B,MAAM;AAC9B,QAAI,CAAC,SAAU;AACf,UAAMA,QAAO,IAAI,SAAS;AAC1B,QAAKA;AAEL,4BAAe,IAAIA,OAAM,QAAQ,GACjC,MAAM,IAAIA,KAAI,GACd,SAAS,sBAAsBA,KAAI,CAAC,GAE7B,MAAM;AACX,cAAM,OAAOA,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,39 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
onLayout
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
Nodes = /* @__PURE__ */new Set(),
|
|
5
|
+
NodeRectCache = /* @__PURE__ */new WeakMap(),
|
|
6
|
+
ParentRectCache = /* @__PURE__ */new WeakMap();
|
|
7
|
+
if (isClient && typeof requestAnimationFrame == "function") {
|
|
8
|
+
let updateLayoutIfChanged = function (node) {
|
|
9
|
+
const nodeRect = node.getBoundingClientRect(),
|
|
10
|
+
parentNode = node.parentElement,
|
|
11
|
+
parentRect = parentNode?.getBoundingClientRect(),
|
|
12
|
+
onLayout = LayoutHandlers.get(node);
|
|
13
|
+
if (typeof onLayout != "function") return;
|
|
14
|
+
const cachedRect = NodeRectCache.get(node),
|
|
15
|
+
cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
16
|
+
if (!cachedRect ||
|
|
17
|
+
// has changed one rect
|
|
18
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
19
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
20
|
+
const event = getElementLayoutEvent(node);
|
|
21
|
+
avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
layoutOnAnimationFrame = function () {
|
|
25
|
+
Nodes.forEach(updateLayoutIfChanged), requestAnimationFrame(layoutOnAnimationFrame);
|
|
26
|
+
},
|
|
27
|
+
avoidUpdates = !0;
|
|
28
|
+
const queuedUpdates = /* @__PURE__ */new Map();
|
|
29
|
+
___onDidFinishClientRender(() => {
|
|
30
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(cb => cb()), queuedUpdates.clear());
|
|
31
|
+
}), requestAnimationFrame(layoutOnAnimationFrame);
|
|
23
32
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
const getElementLayoutEvent = target => {
|
|
34
|
+
let res = null;
|
|
35
|
+
if (measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
36
|
+
res = {
|
|
27
37
|
nativeEvent: {
|
|
28
38
|
layout: {
|
|
29
39
|
x,
|
|
@@ -36,27 +46,26 @@ const measureElement = async target => new Promise(res => {
|
|
|
36
46
|
target
|
|
37
47
|
},
|
|
38
48
|
timeStamp: Date.now()
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
};
|
|
50
|
+
}), !res) throw new Error("\u203C\uFE0F");
|
|
51
|
+
return res;
|
|
52
|
+
},
|
|
43
53
|
measureLayout = (node, relativeTo, callback) => {
|
|
44
|
-
const relativeNode = relativeTo || node?.
|
|
54
|
+
const relativeNode = relativeTo || node?.parentElement;
|
|
45
55
|
if (relativeNode instanceof HTMLElement) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
56
|
+
const nodeDim = node.getBoundingClientRect(),
|
|
57
|
+
relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
58
|
+
if (relativeNodeDim && nodeDim) {
|
|
59
|
+
const {
|
|
60
|
+
x,
|
|
61
|
+
y,
|
|
62
|
+
width,
|
|
63
|
+
height,
|
|
64
|
+
left,
|
|
65
|
+
top
|
|
66
|
+
} = getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
67
|
+
callback(x, y, width, height, left, top);
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
},
|
|
62
71
|
getRelativeDimensions = (a, b) => {
|
|
@@ -76,32 +85,16 @@ const measureElement = async target => new Promise(res => {
|
|
|
76
85
|
left,
|
|
77
86
|
top
|
|
78
87
|
};
|
|
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
|
-
});
|
|
88
|
+
};
|
|
91
89
|
function useElementLayout(ref, onLayout) {
|
|
92
90
|
const node = ref.current?.host;
|
|
93
91
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(() => {
|
|
94
|
-
if (!
|
|
92
|
+
if (!onLayout) return;
|
|
95
93
|
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);
|
|
94
|
+
if (node2) return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), () => {
|
|
95
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
103
96
|
};
|
|
104
97
|
}, [ref, !!onLayout]);
|
|
105
98
|
}
|
|
106
|
-
export {
|
|
99
|
+
export { getElementLayoutEvent, measureLayout, useElementLayout };
|
|
107
100
|
//# sourceMappingURL=useElementLayout.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useIsomorphicLayoutEffect","
|
|
1
|
+
{"version":3,"names":["isClient","useIsomorphicLayoutEffect","isEqualShallow","___onDidFinishClientRender","LayoutHandlers","WeakMap","Nodes","Set","NodeRectCache","ParentRectCache","requestAnimationFrame","updateLayoutIfChanged","node","nodeRect","getBoundingClientRect","parentNode","parentElement","parentRect","onLayout","get","cachedRect","cachedParentRect","set","event","getElementLayoutEvent","avoidUpdates","queuedUpdates","layoutOnAnimationFrame","forEach","Map","cb","clear","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;EAmB7BC,aAAA,GAAgB,mBAAIH,OAAA,CAA8B;EAClDI,eAAA,GAAkB,mBAAIJ,OAAA,CAA8B;AAE1D,IAAIL,QAAA,IAAY,OAAOU,qBAAA,IAA0B,YAAY;EAa3D,IAASC,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,GAAWd,cAAA,CAAee,GAAA,CAAIP,IAAI;MACxC,IAAI,OAAOM,QAAA,IAAa,YAAY;MAEpC,MAAME,UAAA,GAAaZ,aAAA,CAAcW,GAAA,CAAIP,IAAI;QACnCS,gBAAA,GAAmBN,UAAA,GAAaP,aAAA,CAAcW,GAAA,CAAIJ,UAAU,IAAI;MAEtE,IACE,CAACK,UAAA;MAAA;MAEA,CAAClB,cAAA,CAAekB,UAAA,EAAYP,QAAQ,MAClC,CAACQ,gBAAA,IAAoB,CAACnB,cAAA,CAAemB,gBAAA,EAAkBJ,UAAU,IACpE;QACAT,aAAA,CAAcc,GAAA,CAAIV,IAAA,EAAMC,QAAQ,GAC5BI,UAAA,IAAcF,U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GACd1C,QAAA,CAASM,qBAAA,CAAsBoC,KAAI,CAAC,GAE7B,MAAM;MACXtD,KAAA,CAAMwD,MAAA,CAAOF,KAAI,GACjBxD,cAAA,CAAe0D,MAAA,CAAOF,KAAI,GAC1BpD,aAAA,CAAcsD,MAAA,CAAOF,KAAI;IAC3B;EACF,GAAG,CAACH,GAAA,EAAK,CAAC,CAACvC,QAAQ,CAAC;AACtB","ignoreList":[]}
|
|
@@ -1,91 +1,78 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
resizeListeners.forEach(function (cb) {
|
|
45
|
-
return cb();
|
|
46
|
-
});
|
|
47
|
-
}, 4);
|
|
48
|
-
});
|
|
4
|
+
Nodes = /* @__PURE__ */new Set(),
|
|
5
|
+
NodeRectCache = /* @__PURE__ */new WeakMap(),
|
|
6
|
+
ParentRectCache = /* @__PURE__ */new WeakMap();
|
|
7
|
+
if (isClient && typeof requestAnimationFrame == "function") {
|
|
8
|
+
let updateLayoutIfChanged = function (node) {
|
|
9
|
+
var nodeRect = node.getBoundingClientRect(),
|
|
10
|
+
parentNode = node.parentElement,
|
|
11
|
+
parentRect = parentNode?.getBoundingClientRect(),
|
|
12
|
+
onLayout = LayoutHandlers.get(node);
|
|
13
|
+
if (typeof onLayout == "function") {
|
|
14
|
+
var cachedRect = NodeRectCache.get(node),
|
|
15
|
+
cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null;
|
|
16
|
+
if (!cachedRect ||
|
|
17
|
+
// has changed one rect
|
|
18
|
+
!isEqualShallow(cachedRect, nodeRect) && (!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect))) {
|
|
19
|
+
NodeRectCache.set(node, nodeRect), parentRect && parentNode && ParentRectCache.set(parentNode, parentRect);
|
|
20
|
+
var event = getElementLayoutEvent(node);
|
|
21
|
+
avoidUpdates ? queuedUpdates.set(node, function () {
|
|
22
|
+
return onLayout(event);
|
|
23
|
+
}) : onLayout(event);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
layoutOnAnimationFrame = function () {
|
|
28
|
+
Nodes.forEach(updateLayoutIfChanged), requestAnimationFrame(layoutOnAnimationFrame);
|
|
29
|
+
};
|
|
30
|
+
var updateLayoutIfChanged2 = updateLayoutIfChanged,
|
|
31
|
+
layoutOnAnimationFrame2 = layoutOnAnimationFrame,
|
|
32
|
+
avoidUpdates = !0,
|
|
33
|
+
queuedUpdates = /* @__PURE__ */new Map();
|
|
34
|
+
___onDidFinishClientRender(function () {
|
|
35
|
+
avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(function (cb) {
|
|
36
|
+
return cb();
|
|
37
|
+
}), queuedUpdates.clear());
|
|
38
|
+
}), requestAnimationFrame(layoutOnAnimationFrame);
|
|
49
39
|
}
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
x,
|
|
57
|
-
y,
|
|
58
|
-
width,
|
|
59
|
-
height,
|
|
60
|
-
left,
|
|
61
|
-
top
|
|
62
|
-
},
|
|
63
|
-
target
|
|
64
|
-
},
|
|
65
|
-
timeStamp: Date.now()
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
cache = /* @__PURE__ */new WeakMap(),
|
|
71
|
-
measureLayout = function (node, relativeTo, callback) {
|
|
72
|
-
var relativeNode = relativeTo || node?.parentNode;
|
|
73
|
-
if (relativeNode instanceof HTMLElement) {
|
|
74
|
-
var now = Date.now();
|
|
75
|
-
cache.set(node, now), Promise.all([getBoundingClientRectAsync(node), getBoundingClientRectAsync(relativeNode)]).then(function (param) {
|
|
76
|
-
var [nodeDim, relativeNodeDim] = param;
|
|
77
|
-
if (relativeNodeDim && nodeDim && cache.get(node) === now) {
|
|
78
|
-
var {
|
|
40
|
+
var getElementLayoutEvent = function (target) {
|
|
41
|
+
var res = null;
|
|
42
|
+
if (measureLayout(target, null, function (x, y, width, height, left, top) {
|
|
43
|
+
res = {
|
|
44
|
+
nativeEvent: {
|
|
45
|
+
layout: {
|
|
79
46
|
x,
|
|
80
47
|
y,
|
|
81
48
|
width,
|
|
82
49
|
height,
|
|
83
50
|
left,
|
|
84
51
|
top
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
52
|
+
},
|
|
53
|
+
target
|
|
54
|
+
},
|
|
55
|
+
timeStamp: Date.now()
|
|
56
|
+
};
|
|
57
|
+
}), !res) throw new Error("\u203C\uFE0F");
|
|
58
|
+
return res;
|
|
59
|
+
},
|
|
60
|
+
measureLayout = function (node, relativeTo, callback) {
|
|
61
|
+
var relativeNode = relativeTo || node?.parentElement;
|
|
62
|
+
if (relativeNode instanceof HTMLElement) {
|
|
63
|
+
var nodeDim = node.getBoundingClientRect(),
|
|
64
|
+
relativeNodeDim = relativeNode.getBoundingClientRect();
|
|
65
|
+
if (relativeNodeDim && nodeDim) {
|
|
66
|
+
var {
|
|
67
|
+
x,
|
|
68
|
+
y,
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
left,
|
|
72
|
+
top
|
|
73
|
+
} = getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
74
|
+
callback(x, y, width, height, left, top);
|
|
75
|
+
}
|
|
89
76
|
}
|
|
90
77
|
},
|
|
91
78
|
getRelativeDimensions = function (a, b) {
|
|
@@ -105,40 +92,19 @@ var measureElement = async function (target) {
|
|
|
105
92
|
left,
|
|
106
93
|
top
|
|
107
94
|
};
|
|
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
95
|
};
|
|
124
96
|
function useElementLayout(ref, onLayout) {
|
|
125
97
|
var _ref_current,
|
|
126
98
|
node = (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host;
|
|
127
99
|
node && onLayout && LayoutHandlers.set(node, onLayout), useIsomorphicLayoutEffect(function () {
|
|
128
100
|
var _ref_current2;
|
|
129
|
-
if (
|
|
101
|
+
if (onLayout) {
|
|
130
102
|
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
|
-
}
|
|
103
|
+
if (node2) return LayoutHandlers.set(node2, onLayout), Nodes.add(node2), onLayout(getElementLayoutEvent(node2)), function () {
|
|
104
|
+
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2);
|
|
105
|
+
};
|
|
140
106
|
}
|
|
141
107
|
}, [ref, !!onLayout]);
|
|
142
108
|
}
|
|
143
|
-
export {
|
|
109
|
+
export { getElementLayoutEvent, measureLayout, useElementLayout };
|
|
144
110
|
//# sourceMappingURL=useElementLayout.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["isClient","useIsomorphicLayoutEffect","isEqualShallow","___onDidFinishClientRender","LayoutHandlers","WeakMap","Nodes","Set","NodeRectCache","ParentRectCache","requestAnimationFrame","updateLayoutIfChanged","node","nodeRect","getBoundingClientRect","parentNode","parentElement","parentRect","onLayout","get","cachedRect","cachedParentRect","set","event","getElementLayoutEvent","avoidUpdates","queuedUpdates","layoutOnAnimationFrame","forEach","updateLayoutIfChanged2","layoutOnAnimationFrame2","Map","cb","clear","target","res","measureLayout","x","y","width","height","left","top","nativeEvent","layout","timeStamp","Date","now","Error","relativeTo","callback","relativeNode","HTMLElement","nodeDim","relativeNodeDim","getRelativeDimensions","a","b"],"sources":["../../../src/hooks/useElementLayout.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,EAAUC,yBAAA,QAAiC;AACpD,SAAAC,cAAA,EAAAC,0BAAA;AAAA,IACEC,cAAA,sBAAAC,OAAA;EAAAC,KAAA,sBAAAC,GAAA;EAAAC,aAAA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,CAAA;MAAAnB,CAAA,GAAAI,IAAA,GAAAgB,CAAA,CAAAhB,IAAA;MAAAH,CAAA,GAAAI,GAAA,GAAAe,CAAA,CAAAf,GAAA;IACf;MACAL,CAAA;MAEAC,CAAA;MAKEC,KAAA;MAEyBC,MAC3B;MACFC,IAAI;MACNC","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -14,6 +14,9 @@ import { getRect } from "./helpers/getRect";
|
|
|
14
14
|
import { measureLayout, useElementLayout } from "./hooks/useElementLayout";
|
|
15
15
|
import "./vendor/Pressability";
|
|
16
16
|
import { addNativeValidStyles } from "./addNativeValidStyles";
|
|
17
|
+
import {
|
|
18
|
+
getElementLayoutEvent
|
|
19
|
+
} from "./hooks/useElementLayout";
|
|
17
20
|
export * from "@tamagui/web";
|
|
18
21
|
export * from "./reactNativeTypes";
|
|
19
22
|
addNativeValidStyles();
|
|
@@ -75,6 +78,7 @@ export {
|
|
|
75
78
|
Stack,
|
|
76
79
|
Text,
|
|
77
80
|
View,
|
|
78
|
-
createTamagui
|
|
81
|
+
createTamagui,
|
|
82
|
+
getElementLayoutEvent
|
|
79
83
|
};
|
|
80
84
|
//# sourceMappingURL=index.js.map
|