@tamagui/core 1.112.1 → 1.112.3
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.js +10 -12
- package/dist/cjs/hooks/useElementLayout.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.native.js +12 -16
- package/dist/cjs/hooks/useElementLayout.native.js.map +2 -2
- package/dist/cjs/index.js +33 -43
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +16 -3
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +10 -12
- package/dist/esm/hooks/useElementLayout.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.mjs +10 -12
- package/dist/esm/hooks/useElementLayout.mjs.map +1 -1
- package/dist/esm/hooks/useElementLayout.native.js +12 -13
- package/dist/esm/hooks/useElementLayout.native.js.map +1 -1
- package/dist/esm/index.js +32 -35
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +34 -29
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +23 -4
- package/dist/esm/index.native.js.map +1 -1
- package/dist/native.js +535 -272
- package/dist/native.js.map +3 -3
- package/dist/test.native.js +517 -252
- package/dist/test.native.js.map +3 -3
- package/package.json +7 -7
- package/src/hooks/useElementLayout.tsx +17 -11
- package/src/index.tsx +24 -16
- package/types/hooks/useElementLayout.d.ts +2 -1
- package/types/hooks/useElementLayout.d.ts.map +1 -1
- package/types/hooks/usePlatformMethods.d.ts +2 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/src/hooks/usePlatformMethods.ts +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.112.
|
|
3
|
+
"version": "1.112.3",
|
|
4
4
|
"source": "src/index.tsx",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"native-test.d.ts"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tamagui/react-native-use-pressable": "1.112.
|
|
39
|
-
"@tamagui/react-native-use-responder-events": "1.112.
|
|
40
|
-
"@tamagui/use-event": "1.112.
|
|
41
|
-
"@tamagui/web": "1.112.
|
|
38
|
+
"@tamagui/react-native-use-pressable": "1.112.3",
|
|
39
|
+
"@tamagui/react-native-use-responder-events": "1.112.3",
|
|
40
|
+
"@tamagui/use-event": "1.112.3",
|
|
41
|
+
"@tamagui/web": "1.112.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@tamagui/build": "1.112.
|
|
44
|
+
"@tamagui/build": "1.112.3",
|
|
45
45
|
"@testing-library/react": "^16.0.0",
|
|
46
46
|
"csstype": "^3.0.10",
|
|
47
47
|
"typescript": "^5.5.2",
|
|
48
|
-
"vitest": "
|
|
48
|
+
"vitest": "2.1.1"
|
|
49
49
|
},
|
|
50
50
|
"exports": {
|
|
51
51
|
"./package.json": "./package.json",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
|
+
import type { TamaguiComponentStateRef } from '@tamagui/web'
|
|
2
3
|
import type { RefObject } from 'react'
|
|
3
4
|
import { getBoundingClientRect } from '../helpers/getBoundingClientRect'
|
|
4
5
|
|
|
@@ -125,30 +126,35 @@ const getBoundingClientRectAsync = (
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
export function useElementLayout(
|
|
128
|
-
ref: RefObject<
|
|
129
|
+
ref: RefObject<TamaguiComponentStateRef>,
|
|
129
130
|
onLayout?: ((e: LayoutEvent) => void) | null
|
|
130
131
|
) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!node) return
|
|
132
|
+
const node = ref.current?.host as Element
|
|
133
|
+
|
|
134
|
+
// ensure always up to date so we can avoid re-running effect
|
|
135
|
+
if (node && onLayout) {
|
|
136
136
|
LayoutHandlers.set(node, onLayout)
|
|
137
|
-
}
|
|
137
|
+
}
|
|
138
138
|
|
|
139
139
|
useIsomorphicLayoutEffect(() => {
|
|
140
|
-
if (!resizeObserver) return
|
|
141
|
-
const node = ref.current
|
|
140
|
+
if (!resizeObserver || !onLayout) return
|
|
141
|
+
const node = ref.current?.host as Element
|
|
142
142
|
if (!node) return
|
|
143
|
-
|
|
143
|
+
|
|
144
|
+
// setup once
|
|
145
|
+
LayoutHandlers.set(node, onLayout)
|
|
146
|
+
|
|
144
147
|
const onResize = () => {
|
|
145
148
|
measureElement(node as HTMLElement).then(onLayout)
|
|
146
149
|
}
|
|
150
|
+
|
|
147
151
|
resizeListeners.add(onResize)
|
|
148
152
|
resizeObserver.observe(node)
|
|
153
|
+
|
|
149
154
|
return () => {
|
|
155
|
+
LayoutHandlers.delete(node)
|
|
150
156
|
resizeListeners.delete(onResize)
|
|
151
157
|
resizeObserver?.unobserve(node)
|
|
152
158
|
}
|
|
153
|
-
}, [ref])
|
|
159
|
+
}, [ref, !!onLayout])
|
|
154
160
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import { useResponderEvents } from '@tamagui/react-native-use-responder-events'
|
|
3
2
|
import type {
|
|
4
3
|
StackNonStyleProps,
|
|
5
4
|
StackStyleBase,
|
|
5
|
+
TamaDefer,
|
|
6
6
|
TamaguiComponent,
|
|
7
7
|
TamaguiElement,
|
|
8
8
|
TamaguiTextElement,
|
|
9
9
|
TextNonStyleProps,
|
|
10
10
|
TextProps,
|
|
11
11
|
TextStylePropsBase,
|
|
12
|
-
TamaDefer,
|
|
13
12
|
} from '@tamagui/web'
|
|
14
13
|
import {
|
|
15
14
|
Stack as WebStack,
|
|
@@ -18,11 +17,12 @@ import {
|
|
|
18
17
|
composeEventHandlers,
|
|
19
18
|
setupHooks,
|
|
20
19
|
} from '@tamagui/web'
|
|
20
|
+
import React from 'react'
|
|
21
21
|
|
|
22
22
|
import { createOptimizedView } from './createOptimizedView'
|
|
23
23
|
import { getBaseViews } from './getBaseViews'
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
24
|
+
import { getRect } from './helpers/getRect'
|
|
25
|
+
import { measureLayout, useElementLayout } from './hooks/useElementLayout'
|
|
26
26
|
import type { RNTextProps, RNViewProps } from './reactNativeTypes'
|
|
27
27
|
import { usePressability } from './vendor/Pressability'
|
|
28
28
|
|
|
@@ -67,6 +67,24 @@ const baseViews = getBaseViews()
|
|
|
67
67
|
setupHooks({
|
|
68
68
|
getBaseViews,
|
|
69
69
|
|
|
70
|
+
setElementProps: (node) => {
|
|
71
|
+
// web only
|
|
72
|
+
if (node && !node['measure']) {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
node.measure ||= (callback) => measureLayout(node, null, callback)
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
node.measureLayout ||= (relativeToNode, success) =>
|
|
77
|
+
measureLayout(node as HTMLElement, relativeToNode, success)
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
node.measureInWindow ||= (callback) => {
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
const { height, left, top, width } = getRect(node as HTMLElement)!
|
|
82
|
+
callback(left, top, width, height)
|
|
83
|
+
}, 0)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
|
|
70
88
|
usePropsTransform(elementType, propsIn, stateRef, willHydrate) {
|
|
71
89
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
72
90
|
const isDOM = typeof elementType === 'string'
|
|
@@ -106,19 +124,9 @@ setupHooks({
|
|
|
106
124
|
} = propsIn
|
|
107
125
|
|
|
108
126
|
if (willHydrate || isDOM) {
|
|
109
|
-
|
|
110
|
-
const hostRef = React.useMemo(
|
|
111
|
-
() => ({
|
|
112
|
-
get current() {
|
|
113
|
-
return stateRef.current.host as Element
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
[stateRef]
|
|
117
|
-
)
|
|
118
|
-
usePlatformMethods(hostRef)
|
|
119
|
-
useElementLayout(hostRef, !isDOM ? undefined : (onLayout as any))
|
|
127
|
+
useElementLayout(stateRef, !isDOM ? undefined : (onLayout as any))
|
|
120
128
|
useResponderEvents(
|
|
121
|
-
|
|
129
|
+
stateRef,
|
|
122
130
|
!isDOM
|
|
123
131
|
? undefined
|
|
124
132
|
: ({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TamaguiComponentStateRef } from '@tamagui/web';
|
|
1
2
|
import type { RefObject } from 'react';
|
|
2
3
|
export type LayoutValue = {
|
|
3
4
|
x: number;
|
|
@@ -16,5 +17,5 @@ export type LayoutEvent = {
|
|
|
16
17
|
};
|
|
17
18
|
export declare const measureElement: (target: HTMLElement) => Promise<LayoutEvent>;
|
|
18
19
|
export declare const measureLayout: (node: HTMLElement, relativeTo: HTMLElement | null, callback: (x: number, y: number, width: number, height: number, left: number, top: number) => void) => void;
|
|
19
|
-
export declare function useElementLayout(ref: RefObject<
|
|
20
|
+
export declare function useElementLayout(ref: RefObject<TamaguiComponentStateRef>, onLayout?: ((e: LayoutEvent) => void) | null): void;
|
|
20
21
|
//# sourceMappingURL=useElementLayout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementLayout.d.ts","sourceRoot":"","sources":["../../src/hooks/useElementLayout.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,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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AAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,KACR,IAAI,SAmBV,CAAA;AA+BD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,CAAC,wBAAwB,CAAC,EACxC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,IAAI,QA8B7C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
|
-
|
|
2
|
+
import type { TamaguiComponentStateRef } from '@tamagui/web';
|
|
3
|
+
export declare function usePlatformMethods(stateRef: RefObject<TamaguiComponentStateRef>, props?: Object): void;
|
|
3
4
|
//# sourceMappingURL=usePlatformMethods.d.ts.map
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StackNonStyleProps, StackStyleBase, TamaguiComponent, TamaguiElement, TamaguiTextElement, TextNonStyleProps, TextProps, TextStylePropsBase
|
|
1
|
+
import type { StackNonStyleProps, StackStyleBase, TamaDefer, TamaguiComponent, TamaguiElement, TamaguiTextElement, TextNonStyleProps, TextProps, TextStylePropsBase } from '@tamagui/web';
|
|
2
2
|
import type { RNTextProps, RNViewProps } from './reactNativeTypes';
|
|
3
3
|
type RNExclusiveViewProps = Omit<RNViewProps, keyof StackNonStyleProps>;
|
|
4
4
|
export interface RNTamaguiViewNonStyleProps extends StackNonStyleProps, RNExclusiveViewProps {
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACT,kBAAkB,EACnB,MAAM,cAAc,CAAA;AAcrB,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAKlE,KAAK,oBAAoB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,kBAAkB,CAAC,CAAA;AACvE,MAAM,WAAW,0BACf,SAAQ,kBAAkB,EACxB,oBAAoB;CAAG;AAE3B,KAAK,aAAa,GAAG,gBAAgB,CACnC,SAAS,EACT,cAAc,EACd,0BAA0B,EAC1B,cAAc,EACd,EAAE,CACH,CAAA;AAED,KAAK,oBAAoB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,SAAS,CAAC,CAAA;AAC9D,MAAM,WAAW,0BACf,SAAQ,iBAAiB,EACvB,oBAAoB;CAAG;AAE3B,KAAK,aAAa,GAAG,gBAAgB,CACnC,SAAS,EACT,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAClB,EAAE,CACH,CAAA;AAGD,cAAc,cAAc,CAAA;AAG5B,cAAc,oBAAoB,CAAA;AAyMlC,eAAO,MAAM,IAAI,EAAqB,aAAa,CAAA;AACnD,eAAO,MAAM,KAAK,EAAsB,aAAa,CAAA;AACrD,eAAO,MAAM,IAAI,EAAqB,aAAa,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
|
-
import type { RefObject } from 'react'
|
|
3
|
-
|
|
4
|
-
import { getRect } from '../helpers/getRect'
|
|
5
|
-
import { measureLayout } from './useElementLayout'
|
|
6
|
-
|
|
7
|
-
// react native compat (web only)
|
|
8
|
-
export function usePlatformMethods(hostRef: RefObject<Element>) {
|
|
9
|
-
useIsomorphicLayoutEffect(() => {
|
|
10
|
-
const node = hostRef.current
|
|
11
|
-
if (node) {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
node.measure ||= (callback) => measureLayout(node, null, callback)
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
node.measureLayout ||= (relativeToNode, success) =>
|
|
16
|
-
measureLayout(node as HTMLElement, relativeToNode, success)
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
node.measureInWindow ||= (callback) => {
|
|
19
|
-
if (!node) return
|
|
20
|
-
setTimeout(() => {
|
|
21
|
-
const { height, left, top, width } = getRect(node as HTMLElement)!
|
|
22
|
-
callback(left, top, width, height)
|
|
23
|
-
}, 0)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}, [hostRef])
|
|
27
|
-
}
|