@tamagui/core 1.126.13-1747874018127 → 1.126.14
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 +6 -5
- package/dist/cjs/hooks/useElementLayout.js +24 -20
- package/dist/cjs/hooks/useElementLayout.js.map +1 -1
- package/dist/cjs/hooks/useElementLayout.native.js +26 -24
- package/dist/cjs/hooks/useElementLayout.native.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +24 -20
- package/dist/esm/hooks/useElementLayout.js.map +1 -1
- package/dist/esm/hooks/useElementLayout.mjs +6 -5
- package/dist/esm/hooks/useElementLayout.mjs.map +1 -1
- package/dist/esm/hooks/useElementLayout.native.js +6 -5
- package/dist/esm/hooks/useElementLayout.native.js.map +1 -1
- package/dist/native.js +40 -26
- package/dist/native.js.map +2 -2
- package/dist/test.native.js +18 -6
- package/dist/test.native.js.map +2 -2
- package/package.json +7 -7
- package/src/hooks/useElementLayout.tsx +54 -44
- package/types/hooks/useElementLayout.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.126.
|
|
3
|
+
"version": "1.126.14",
|
|
4
4
|
"source": "src/index.tsx",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"native-test.d.ts"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tamagui/react-native-media-driver": "1.126.
|
|
39
|
-
"@tamagui/react-native-use-pressable": "1.126.
|
|
40
|
-
"@tamagui/react-native-use-responder-events": "1.126.
|
|
41
|
-
"@tamagui/use-event": "1.126.
|
|
42
|
-
"@tamagui/web": "1.126.
|
|
38
|
+
"@tamagui/react-native-media-driver": "1.126.14",
|
|
39
|
+
"@tamagui/react-native-use-pressable": "1.126.14",
|
|
40
|
+
"@tamagui/react-native-use-responder-events": "1.126.14",
|
|
41
|
+
"@tamagui/use-event": "1.126.14",
|
|
42
|
+
"@tamagui/web": "1.126.14"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@tamagui/build": "1.126.
|
|
45
|
+
"@tamagui/build": "1.126.14",
|
|
46
46
|
"@testing-library/react": "^16.1.0",
|
|
47
47
|
"csstype": "^3.0.10",
|
|
48
48
|
"typescript": "^5.8.2",
|
|
@@ -29,54 +29,64 @@ export type LayoutEvent = {
|
|
|
29
29
|
const NodeRectCache = new WeakMap<HTMLElement, DOMRect>()
|
|
30
30
|
const ParentRectCache = new WeakMap<HTMLElement, DOMRect>()
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function updateLayoutIfChanged(node: HTMLElement) {
|
|
46
|
-
const nodeRect = node.getBoundingClientRect()
|
|
47
|
-
const parentNode = node.parentElement
|
|
48
|
-
const parentRect = parentNode?.getBoundingClientRect()
|
|
49
|
-
|
|
50
|
-
const onLayout = LayoutHandlers.get(node)
|
|
51
|
-
if (typeof onLayout !== 'function') return
|
|
52
|
-
|
|
53
|
-
const cachedRect = NodeRectCache.get(node)
|
|
54
|
-
const cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
!cachedRect ||
|
|
58
|
-
// has changed one rect
|
|
59
|
-
(!isEqualShallow(cachedRect, nodeRect) &&
|
|
60
|
-
(!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect)))
|
|
61
|
-
) {
|
|
62
|
-
NodeRectCache.set(node, nodeRect)
|
|
63
|
-
if (parentRect && parentNode) {
|
|
64
|
-
ParentRectCache.set(parentNode, parentRect)
|
|
32
|
+
const rAF = typeof window !== 'undefined' ? window.requestAnimationFrame : undefined
|
|
33
|
+
|
|
34
|
+
if (isClient) {
|
|
35
|
+
if (rAF) {
|
|
36
|
+
// prevent thrashing during first hydration (somewhat, streaming gets trickier)
|
|
37
|
+
let avoidUpdates = true
|
|
38
|
+
const queuedUpdates = new Map<HTMLElement, Function>()
|
|
39
|
+
|
|
40
|
+
___onDidFinishClientRender(() => {
|
|
41
|
+
avoidUpdates = false
|
|
42
|
+
if (queuedUpdates) {
|
|
43
|
+
queuedUpdates.forEach((cb) => cb())
|
|
44
|
+
queuedUpdates.clear()
|
|
65
45
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
function updateLayoutIfChanged(node: HTMLElement) {
|
|
49
|
+
const nodeRect = node.getBoundingClientRect()
|
|
50
|
+
const parentNode = node.parentElement
|
|
51
|
+
const parentRect = parentNode?.getBoundingClientRect()
|
|
52
|
+
|
|
53
|
+
const onLayout = LayoutHandlers.get(node)
|
|
54
|
+
if (typeof onLayout !== 'function') return
|
|
55
|
+
|
|
56
|
+
const cachedRect = NodeRectCache.get(node)
|
|
57
|
+
const cachedParentRect = parentNode ? NodeRectCache.get(parentNode) : null
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
!cachedRect ||
|
|
61
|
+
// has changed one rect
|
|
62
|
+
(!isEqualShallow(cachedRect, nodeRect) &&
|
|
63
|
+
(!cachedParentRect || !isEqualShallow(cachedParentRect, parentRect)))
|
|
64
|
+
) {
|
|
65
|
+
NodeRectCache.set(node, nodeRect)
|
|
66
|
+
if (parentRect && parentNode) {
|
|
67
|
+
ParentRectCache.set(parentNode, parentRect)
|
|
68
|
+
}
|
|
69
|
+
const event = getElementLayoutEvent(node)
|
|
70
|
+
if (avoidUpdates) {
|
|
71
|
+
queuedUpdates.set(node, () => onLayout(event))
|
|
72
|
+
} else {
|
|
73
|
+
onLayout(event)
|
|
74
|
+
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
|
-
}
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
// note that getBoundingClientRect() does not thrash layout if its after an animation frame
|
|
79
|
+
rAF!(layoutOnAnimationFrame)
|
|
80
|
+
function layoutOnAnimationFrame() {
|
|
81
|
+
Nodes.forEach(updateLayoutIfChanged)
|
|
82
|
+
rAF!(layoutOnAnimationFrame)
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
if (process.env.NODE_ENV === 'development') {
|
|
86
|
+
console.warn(
|
|
87
|
+
`No requestAnimationFrame - please polyfill for onLayout to work correctly`
|
|
88
|
+
)
|
|
89
|
+
}
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementLayout.d.ts","sourceRoot":"","sources":["../../src/hooks/useElementLayout.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAE9B,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE;QACX,MAAM,EAAE,WAAW,CAAA;QACnB,MAAM,EAAE,GAAG,CAAA;KACZ,CAAA;IACD,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;
|
|
1
|
+
{"version":3,"file":"useElementLayout.d.ts","sourceRoot":"","sources":["../../src/hooks/useElementLayout.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wB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