tarojs-plugin-chucker 1.0.0 → 1.1.0
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/index.js +1 -1
- package/dist/runtime/hooks/useVirtual.js +27 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -178,7 +178,7 @@ exports.default = (ctx, options = {}) => {
|
|
|
178
178
|
const styles = `
|
|
179
179
|
.chucker-float-btn {
|
|
180
180
|
position: fixed !important;
|
|
181
|
-
bottom: calc(env(safe-area-inset-bottom) +
|
|
181
|
+
bottom: calc(env(safe-area-inset-bottom) + 200rpx) !important;
|
|
182
182
|
right: 15px !important;
|
|
183
183
|
width: 46px !important;
|
|
184
184
|
height: 46px !important;
|
|
@@ -178,6 +178,7 @@ function useVirtualList(options) {
|
|
|
178
178
|
setVlStyles(stylesList);
|
|
179
179
|
}
|
|
180
180
|
}, [items, itemHeight, chunkSize, columns, disabled]);
|
|
181
|
+
const lastMeasuredHeightsRef = (0, react_1.useRef)([]);
|
|
181
182
|
(0, react_1.useEffect)(() => {
|
|
182
183
|
if (disabled || vlChunks.length === 0) {
|
|
183
184
|
disconnectAll();
|
|
@@ -215,17 +216,37 @@ function useVirtualList(options) {
|
|
|
215
216
|
setVlStyles([...stylesRef.current]);
|
|
216
217
|
}
|
|
217
218
|
else if (!isIn && wasIn) {
|
|
219
|
+
// Measure the chunk's rendered height BEFORE hiding its content.
|
|
220
|
+
// The boundingClientRect query is async — we must capture the real height
|
|
221
|
+
// while the chunk is still rendered, otherwise we get 0px and the scroll
|
|
222
|
+
// space collapses, making it impossible to scroll back up.
|
|
218
223
|
const query = runtimeTaro.createSelectorQuery();
|
|
219
224
|
query
|
|
220
225
|
.select("#vl-chunk-" + targetIndex)
|
|
221
226
|
.boundingClientRect((rect) => {
|
|
222
|
-
if (rect)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
if (!rect)
|
|
228
|
+
return;
|
|
229
|
+
let measuredHeight = rect.height;
|
|
230
|
+
// Calculate a minimum fallback height based on chunk content
|
|
231
|
+
const chunkLength = chunksRef.current[targetIndex]
|
|
232
|
+
? chunksRef.current[targetIndex].length
|
|
233
|
+
: currentChunkSize;
|
|
234
|
+
const estimatedHeight = Math.ceil(chunkLength / columns) * itemHeight;
|
|
235
|
+
// If measured height is 0 or unreasonably small (race condition where
|
|
236
|
+
// content was already unmounted), use the last known good height or
|
|
237
|
+
// the estimated height to prevent scroll space from collapsing.
|
|
238
|
+
if (!measuredHeight || measuredHeight < estimatedHeight * 0.3) {
|
|
239
|
+
measuredHeight =
|
|
240
|
+
lastMeasuredHeightsRef.current[targetIndex] || estimatedHeight;
|
|
228
241
|
}
|
|
242
|
+
else {
|
|
243
|
+
// Cache this as a known good height
|
|
244
|
+
lastMeasuredHeightsRef.current[targetIndex] = measuredHeight;
|
|
245
|
+
}
|
|
246
|
+
visibleRef.current[targetIndex] = false;
|
|
247
|
+
stylesRef.current[targetIndex] = "height: " + measuredHeight + "px;";
|
|
248
|
+
setVlVisible([...visibleRef.current]);
|
|
249
|
+
setVlStyles([...stylesRef.current]);
|
|
229
250
|
})
|
|
230
251
|
.exec();
|
|
231
252
|
}
|
package/package.json
CHANGED