react-native-laminar 1.4.4 → 1.4.5
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/lib/commonjs/hooks/use-inline-auto-width.js +24 -1
- package/lib/commonjs/hooks/use-inline-auto-width.js.map +1 -1
- package/lib/module/hooks/use-inline-auto-width.js +24 -1
- package/lib/module/hooks/use-inline-auto-width.js.map +1 -1
- package/lib/typescript/commonjs/hooks/use-inline-auto-width.d.ts.map +1 -1
- package/lib/typescript/module/hooks/use-inline-auto-width.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/use-inline-auto-width.ts +33 -1
|
@@ -19,12 +19,18 @@ const useInlineAutoWidth = ({
|
|
|
19
19
|
const measuredWidthRef = (0, _react.useRef)(null);
|
|
20
20
|
const bootstrappedRef = (0, _react.useRef)(false);
|
|
21
21
|
const widthCacheRef = (0, _react.useRef)(new Map());
|
|
22
|
+
const firstEnabledMeasurementKeyRef = (0, _react.useRef)(null);
|
|
22
23
|
const hasCapturedVisibleLayoutRef = (0, _react.useRef)(false);
|
|
23
24
|
const initialMeasurementKeyRef = (0, _react.useRef)(null);
|
|
24
25
|
const firstProbeRef = (0, _react.useRef)(null);
|
|
25
26
|
const latestProbeRef = (0, _react.useRef)(null);
|
|
26
27
|
const bootstrapTimerRef = (0, _react.useRef)(null);
|
|
27
28
|
const [readyMeasurementKey, setReadyMeasurementKey] = (0, _react.useState)(null);
|
|
29
|
+
|
|
30
|
+
// latch the first enabled key so a pending visible layout cannot use a later key
|
|
31
|
+
if (enabled && firstEnabledMeasurementKeyRef.current === null) {
|
|
32
|
+
firstEnabledMeasurementKeyRef.current = measurementKey;
|
|
33
|
+
}
|
|
28
34
|
const markMeasurementReady = (0, _react.useCallback)(key => {
|
|
29
35
|
setReadyMeasurementKey(currentKey => currentKey === key ? currentKey : key);
|
|
30
36
|
}, []);
|
|
@@ -79,11 +85,28 @@ const useInlineAutoWidth = ({
|
|
|
79
85
|
// bootstrap from the visible tree so the first explicit width matches
|
|
80
86
|
// the geometry that was already painted to the user
|
|
81
87
|
const nextWidth = Math.max(0, event.nativeEvent.layout.width);
|
|
88
|
+
const firstEnabledMeasurementKey = firstEnabledMeasurementKeyRef.current;
|
|
89
|
+
const visibleKeyMatchesInitialKey = firstEnabledMeasurementKey === null || firstEnabledMeasurementKey === measurementKey;
|
|
90
|
+
const firstProbe = firstProbeRef.current;
|
|
91
|
+
if (!visibleKeyMatchesInitialKey) {
|
|
92
|
+
// ignore a visible layout from the initial row when the key has changed
|
|
93
|
+
const currentProbeWidth = firstProbe?.key === measurementKey ? firstProbe.width : widthCacheRef.current.get(measurementKey);
|
|
94
|
+
if (currentProbeWidth !== undefined) {
|
|
95
|
+
initialMeasurementKeyRef.current = measurementKey;
|
|
96
|
+
applyWidth(currentProbeWidth);
|
|
97
|
+
markMeasurementReady(measurementKey);
|
|
98
|
+
} else if (firstProbe) {
|
|
99
|
+
// use the old probe as the shell baseline until the current key is measured
|
|
100
|
+
initialMeasurementKeyRef.current = firstProbe.key;
|
|
101
|
+
applyWidth(firstProbe.width);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
82
106
|
// retain the visible width for the initial key so a later cache hit does
|
|
83
107
|
// not reintroduce the probe-to-visible mismatch
|
|
84
108
|
widthCacheRef.current.delete(measurementKey);
|
|
85
109
|
widthCacheRef.current.set(measurementKey, nextWidth);
|
|
86
|
-
const firstProbe = firstProbeRef.current;
|
|
87
110
|
if (firstProbe && firstProbe.key !== measurementKey) {
|
|
88
111
|
initialMeasurementKeyRef.current = firstProbe.key;
|
|
89
112
|
applyWidth(firstProbe.width);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNativeReanimated","WIDTH_CACHE_LIMIT","useInlineAutoWidth","enabled","driveToWidth","measurementKey","widthValue","useSharedValue","hasBootstrappedWidth","measuredWidthRef","useRef","bootstrappedRef","widthCacheRef","Map","hasCapturedVisibleLayoutRef","initialMeasurementKeyRef","firstProbeRef","latestProbeRef","bootstrapTimerRef","readyMeasurementKey","setReadyMeasurementKey","useState","markMeasurementReady","useCallback","key","currentKey","applyWidth","nextWidth","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNativeReanimated","WIDTH_CACHE_LIMIT","useInlineAutoWidth","enabled","driveToWidth","measurementKey","widthValue","useSharedValue","hasBootstrappedWidth","measuredWidthRef","useRef","bootstrappedRef","widthCacheRef","Map","firstEnabledMeasurementKeyRef","hasCapturedVisibleLayoutRef","initialMeasurementKeyRef","firstProbeRef","latestProbeRef","bootstrapTimerRef","readyMeasurementKey","setReadyMeasurementKey","useState","current","markMeasurementReady","useCallback","key","currentKey","applyWidth","nextWidth","value","bootstrapFromProbe","firstProbe","width","latestProbe","captureVisibleLayout","event","clearTimeout","Math","max","nativeEvent","layout","firstEnabledMeasurementKey","visibleKeyMatchesInitialKey","currentProbeWidth","get","undefined","delete","set","captureLayout","ceil","isInitialMeasurement","size","oldestKey","keys","next","probe","setTimeout","cachedWidth","useLayoutEffect","useEffect","animatedWidthStyle","useAnimatedStyle","isReady","shouldMeasure","exports"],"sourceRoot":"../../../src","sources":["hooks/use-inline-auto-width.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAQA,IAAAC,sBAAA,GAAAD,OAAA;AAaA,MAAME,iBAAiB,GAAG,EAAE;;AAE5B;AACO,MAAMC,kBAAkB,GAAGA,CAAC;EACjCC,OAAO;EACPC,YAAY;EACZC;AACM,CAAC,KAAK;EACZ,MAAMC,UAAU,GAAG,IAAAC,qCAAc,EAAC,CAAC,CAAC;EACpC,MAAMC,oBAAoB,GAAG,IAAAD,qCAAc,EAAC,KAAK,CAAC;EAClD,MAAME,gBAAgB,GAAG,IAAAC,aAAM,EAAgB,IAAI,CAAC;EACpD,MAAMC,eAAe,GAAG,IAAAD,aAAM,EAAC,KAAK,CAAC;EACrC,MAAME,aAAa,GAAG,IAAAF,aAAM,EAAC,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AAAA,kBAAA","ignoreList":[]}
|
|
@@ -15,12 +15,18 @@ export const useInlineAutoWidth = ({
|
|
|
15
15
|
const measuredWidthRef = useRef(null);
|
|
16
16
|
const bootstrappedRef = useRef(false);
|
|
17
17
|
const widthCacheRef = useRef(new Map());
|
|
18
|
+
const firstEnabledMeasurementKeyRef = useRef(null);
|
|
18
19
|
const hasCapturedVisibleLayoutRef = useRef(false);
|
|
19
20
|
const initialMeasurementKeyRef = useRef(null);
|
|
20
21
|
const firstProbeRef = useRef(null);
|
|
21
22
|
const latestProbeRef = useRef(null);
|
|
22
23
|
const bootstrapTimerRef = useRef(null);
|
|
23
24
|
const [readyMeasurementKey, setReadyMeasurementKey] = useState(null);
|
|
25
|
+
|
|
26
|
+
// latch the first enabled key so a pending visible layout cannot use a later key
|
|
27
|
+
if (enabled && firstEnabledMeasurementKeyRef.current === null) {
|
|
28
|
+
firstEnabledMeasurementKeyRef.current = measurementKey;
|
|
29
|
+
}
|
|
24
30
|
const markMeasurementReady = useCallback(key => {
|
|
25
31
|
setReadyMeasurementKey(currentKey => currentKey === key ? currentKey : key);
|
|
26
32
|
}, []);
|
|
@@ -75,11 +81,28 @@ export const useInlineAutoWidth = ({
|
|
|
75
81
|
// bootstrap from the visible tree so the first explicit width matches
|
|
76
82
|
// the geometry that was already painted to the user
|
|
77
83
|
const nextWidth = Math.max(0, event.nativeEvent.layout.width);
|
|
84
|
+
const firstEnabledMeasurementKey = firstEnabledMeasurementKeyRef.current;
|
|
85
|
+
const visibleKeyMatchesInitialKey = firstEnabledMeasurementKey === null || firstEnabledMeasurementKey === measurementKey;
|
|
86
|
+
const firstProbe = firstProbeRef.current;
|
|
87
|
+
if (!visibleKeyMatchesInitialKey) {
|
|
88
|
+
// ignore a visible layout from the initial row when the key has changed
|
|
89
|
+
const currentProbeWidth = firstProbe?.key === measurementKey ? firstProbe.width : widthCacheRef.current.get(measurementKey);
|
|
90
|
+
if (currentProbeWidth !== undefined) {
|
|
91
|
+
initialMeasurementKeyRef.current = measurementKey;
|
|
92
|
+
applyWidth(currentProbeWidth);
|
|
93
|
+
markMeasurementReady(measurementKey);
|
|
94
|
+
} else if (firstProbe) {
|
|
95
|
+
// use the old probe as the shell baseline until the current key is measured
|
|
96
|
+
initialMeasurementKeyRef.current = firstProbe.key;
|
|
97
|
+
applyWidth(firstProbe.width);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
78
102
|
// retain the visible width for the initial key so a later cache hit does
|
|
79
103
|
// not reintroduce the probe-to-visible mismatch
|
|
80
104
|
widthCacheRef.current.delete(measurementKey);
|
|
81
105
|
widthCacheRef.current.set(measurementKey, nextWidth);
|
|
82
|
-
const firstProbe = firstProbeRef.current;
|
|
83
106
|
if (firstProbe && firstProbe.key !== measurementKey) {
|
|
84
107
|
initialMeasurementKeyRef.current = firstProbe.key;
|
|
85
108
|
applyWidth(firstProbe.width);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","useAnimatedStyle","useSharedValue","WIDTH_CACHE_LIMIT","useInlineAutoWidth","enabled","driveToWidth","measurementKey","widthValue","hasBootstrappedWidth","measuredWidthRef","bootstrappedRef","widthCacheRef","Map","hasCapturedVisibleLayoutRef","initialMeasurementKeyRef","firstProbeRef","latestProbeRef","bootstrapTimerRef","readyMeasurementKey","setReadyMeasurementKey","markMeasurementReady","key","currentKey","applyWidth","nextWidth","
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","useAnimatedStyle","useSharedValue","WIDTH_CACHE_LIMIT","useInlineAutoWidth","enabled","driveToWidth","measurementKey","widthValue","hasBootstrappedWidth","measuredWidthRef","bootstrappedRef","widthCacheRef","Map","firstEnabledMeasurementKeyRef","hasCapturedVisibleLayoutRef","initialMeasurementKeyRef","firstProbeRef","latestProbeRef","bootstrapTimerRef","readyMeasurementKey","setReadyMeasurementKey","current","markMeasurementReady","key","currentKey","applyWidth","nextWidth","value","bootstrapFromProbe","firstProbe","width","latestProbe","captureVisibleLayout","event","clearTimeout","Math","max","nativeEvent","layout","firstEnabledMeasurementKey","visibleKeyMatchesInitialKey","currentProbeWidth","get","undefined","delete","set","captureLayout","ceil","isInitialMeasurement","size","oldestKey","keys","next","probe","setTimeout","cachedWidth","animatedWidthStyle","isReady","shouldMeasure"],"sourceRoot":"../../../src","sources":["hooks/use-inline-auto-width.ts"],"mappings":";;AAAA,SACEA,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,yBAAyB;AAa1E,MAAMC,iBAAiB,GAAG,EAAE;;AAE5B;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAAC;EACjCC,OAAO;EACPC,YAAY;EACZC;AACM,CAAC,KAAK;EACZ,MAAMC,UAAU,GAAGN,cAAc,CAAC,CAAC,CAAC;EACpC,MAAMO,oBAAoB,GAAGP,cAAc,CAAC,KAAK,CAAC;EAClD,MAAMQ,gBAAgB,GAAGX,MAAM,CAAgB,IAAI,CAAC;EACpD,MAAMY,eAAe,GAAGZ,MAAM,CAAC,KAAK,CAAC;EACrC,MAAMa,aAAa,GAAGb,MAAM,CAAC,IAAIc,GAAG,CAAiB,CAAC,CAAC;EACvD,MAAMC,6BAA6B,GAAGf,MAAM,CAAgB,IAAI,CAAC;EACjE,MAAMgB,2BAA2B,GAAGhB,MAAM,CAAC,KAAK,CAAC;EACjD,MAAMiB,wBAAwB,GAAGjB,MAAM,CAAgB,IAAI,CAAC;EAC5D,MAAMkB,aAAa,GAAGlB,MAAM,CAAsB,IAAI,CAAC;EACvD,MAAMmB,cAAc,GAAGnB,MAAM,CAAsB,IAAI,CAAC;EACxD,MAAMoB,iBAAiB,GAAGpB,MAAM,CAAuC,IAAI,CAAC;EAC5E,MAAM,CAACqB,mBAAmB,EAAEC,sBAAsB,CAAC,GAAGrB,QAAQ,CAC5D,IACF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AAC,EAAE,CACDmB,UAAU,EACV8B,WAAW,EACXnD,OAAO,EACPkB,oBAAoB,EACpBhB,cAAc,CACf,CAAC;EAEFV,SAAS,CACP,MAAM,MAAM;IACV,IAAIsB,iBAAiB,CAACG,OAAO,KAAK,IAAI,EAAE;MACtCa,YAAY,CAAChB,iBAAiB,CAACG,OAAO,CAAC;IACzC;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMmC,kBAAkB,GAAGxD,gBAAgB,CACzC,MACEI,OAAO,IAAII,oBAAoB,CAACmB,KAAK,GACjC;IACEG,KAAK,EAAEvB,UAAU,CAACoB;EACpB,CAAC,GACD,CAAC,CAAC,EACR,CAACvB,OAAO,CACV,CAAC;EAED,OAAO;IACL0C,aAAa;IACbd,oBAAoB;IACpBwB,kBAAkB;IAClBC,OAAO,EACL,CAACrD,OAAO,IACRmD,WAAW,KAAKZ,SAAS,IACzBxB,mBAAmB,KAAKb,cAAc;IACxCoD,aAAa,EAAEtD,OAAO,IAAImD,WAAW,KAAKZ;EAC5C,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-inline-auto-width.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-inline-auto-width.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD,KAAK,MAAM,GAAG;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAUF,eAAO,MAAM,kBAAkB,GAAI,4CAIhC,MAAM;
|
|
1
|
+
{"version":3,"file":"use-inline-auto-width.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-inline-auto-width.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD,KAAK,MAAM,GAAG;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAUF,eAAO,MAAM,kBAAkB,GAAI,4CAIhC,MAAM;2BAyIG,iBAAiB;kCA5DjB,iBAAiB;;;;;;;;CAwK5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-inline-auto-width.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-inline-auto-width.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD,KAAK,MAAM,GAAG;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAUF,eAAO,MAAM,kBAAkB,GAAI,4CAIhC,MAAM;
|
|
1
|
+
{"version":3,"file":"use-inline-auto-width.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-inline-auto-width.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD,KAAK,MAAM,GAAG;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAUF,eAAO,MAAM,kBAAkB,GAAI,4CAIhC,MAAM;2BAyIG,iBAAiB;kCA5DjB,iBAAiB;;;;;;;;CAwK5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -32,6 +32,7 @@ export const useInlineAutoWidth = ({
|
|
|
32
32
|
const measuredWidthRef = useRef<number | null>(null);
|
|
33
33
|
const bootstrappedRef = useRef(false);
|
|
34
34
|
const widthCacheRef = useRef(new Map<string, number>());
|
|
35
|
+
const firstEnabledMeasurementKeyRef = useRef<string | null>(null);
|
|
35
36
|
const hasCapturedVisibleLayoutRef = useRef(false);
|
|
36
37
|
const initialMeasurementKeyRef = useRef<string | null>(null);
|
|
37
38
|
const firstProbeRef = useRef<PendingProbe | null>(null);
|
|
@@ -41,6 +42,11 @@ export const useInlineAutoWidth = ({
|
|
|
41
42
|
null
|
|
42
43
|
);
|
|
43
44
|
|
|
45
|
+
// latch the first enabled key so a pending visible layout cannot use a later key
|
|
46
|
+
if (enabled && firstEnabledMeasurementKeyRef.current === null) {
|
|
47
|
+
firstEnabledMeasurementKeyRef.current = measurementKey;
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
const markMeasurementReady = useCallback((key: string) => {
|
|
45
51
|
setReadyMeasurementKey((currentKey) =>
|
|
46
52
|
currentKey === key ? currentKey : key
|
|
@@ -111,11 +117,37 @@ export const useInlineAutoWidth = ({
|
|
|
111
117
|
// bootstrap from the visible tree so the first explicit width matches
|
|
112
118
|
// the geometry that was already painted to the user
|
|
113
119
|
const nextWidth = Math.max(0, event.nativeEvent.layout.width);
|
|
120
|
+
const firstEnabledMeasurementKey =
|
|
121
|
+
firstEnabledMeasurementKeyRef.current;
|
|
122
|
+
const visibleKeyMatchesInitialKey =
|
|
123
|
+
firstEnabledMeasurementKey === null ||
|
|
124
|
+
firstEnabledMeasurementKey === measurementKey;
|
|
125
|
+
const firstProbe = firstProbeRef.current;
|
|
126
|
+
|
|
127
|
+
if (!visibleKeyMatchesInitialKey) {
|
|
128
|
+
// ignore a visible layout from the initial row when the key has changed
|
|
129
|
+
const currentProbeWidth =
|
|
130
|
+
firstProbe?.key === measurementKey
|
|
131
|
+
? firstProbe.width
|
|
132
|
+
: widthCacheRef.current.get(measurementKey);
|
|
133
|
+
|
|
134
|
+
if (currentProbeWidth !== undefined) {
|
|
135
|
+
initialMeasurementKeyRef.current = measurementKey;
|
|
136
|
+
applyWidth(currentProbeWidth);
|
|
137
|
+
markMeasurementReady(measurementKey);
|
|
138
|
+
} else if (firstProbe) {
|
|
139
|
+
// use the old probe as the shell baseline until the current key is measured
|
|
140
|
+
initialMeasurementKeyRef.current = firstProbe.key;
|
|
141
|
+
applyWidth(firstProbe.width);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
114
147
|
// retain the visible width for the initial key so a later cache hit does
|
|
115
148
|
// not reintroduce the probe-to-visible mismatch
|
|
116
149
|
widthCacheRef.current.delete(measurementKey);
|
|
117
150
|
widthCacheRef.current.set(measurementKey, nextWidth);
|
|
118
|
-
const firstProbe = firstProbeRef.current;
|
|
119
151
|
if (firstProbe && firstProbe.key !== measurementKey) {
|
|
120
152
|
initialMeasurementKeyRef.current = firstProbe.key;
|
|
121
153
|
applyWidth(firstProbe.width);
|