dce-reactkit 3.5.10 → 3.5.11
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/index.js +19 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +19 -16
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +24 -18
package/package.json
CHANGED
|
@@ -215,7 +215,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
215
215
|
// Initialize refs
|
|
216
216
|
const lastItemIds = useRef<(string | number)[]>([]);
|
|
217
217
|
const container = useRef<HTMLDivElement | null>(null);
|
|
218
|
-
const
|
|
218
|
+
const wasLastScrolledToBottom = useRef<boolean>(true);
|
|
219
219
|
|
|
220
220
|
/*------------------------------------------------------------------------*/
|
|
221
221
|
/* ------------------------- Component Functions ------------------------ */
|
|
@@ -253,7 +253,12 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
253
253
|
);
|
|
254
254
|
|
|
255
255
|
// Figure out if we're scrolled to the bottom
|
|
256
|
-
|
|
256
|
+
const atBottom = (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
257
|
+
|
|
258
|
+
// Remember if we scrolled to the bottom
|
|
259
|
+
wasLastScrolledToBottom.current = atBottom;
|
|
260
|
+
|
|
261
|
+
return atBottom;
|
|
257
262
|
};
|
|
258
263
|
|
|
259
264
|
/**
|
|
@@ -272,7 +277,13 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
272
277
|
});
|
|
273
278
|
|
|
274
279
|
// Scroll to bottom
|
|
275
|
-
container.current.scrollTop =
|
|
280
|
+
container.current.scrollTop = (
|
|
281
|
+
container.current.scrollHeight
|
|
282
|
+
- container.current.clientHeight
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Remember that we scrolled to the bottom
|
|
286
|
+
wasLastScrolledToBottom.current = true;
|
|
276
287
|
};
|
|
277
288
|
|
|
278
289
|
/*----------------------------------------*/
|
|
@@ -289,8 +300,9 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
289
300
|
return;
|
|
290
301
|
}
|
|
291
302
|
|
|
292
|
-
// If scrolled to bottom, hide the button
|
|
303
|
+
// If scrolled to bottom, hide the button and remember position
|
|
293
304
|
if (isScrolledToBottom()) {
|
|
305
|
+
// Hide button
|
|
294
306
|
dispatch({
|
|
295
307
|
type: ActionType.HideJumpToBottomButton,
|
|
296
308
|
});
|
|
@@ -324,22 +336,24 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
324
336
|
|
|
325
337
|
// Check if new content appeared at bottom
|
|
326
338
|
const newContentAppeared = (
|
|
339
|
+
// There are items
|
|
327
340
|
currentItemIds.length > 0
|
|
328
|
-
|
|
329
|
-
&& lastItemIds.current.
|
|
330
|
-
|
|
331
|
-
currentItemIds[currentItemIds.length - 1]
|
|
332
|
-
!== lastItemIds.current[lastItemIds.current.length - 1]
|
|
341
|
+
// The last item is new
|
|
342
|
+
&& !lastItemIds.current.includes(
|
|
343
|
+
currentItemIds[currentItemIds.length - 1],
|
|
333
344
|
)
|
|
334
345
|
);
|
|
335
346
|
|
|
347
|
+
// Update last item ids
|
|
348
|
+
lastItemIds.current = currentItemIds;
|
|
349
|
+
|
|
336
350
|
// Do nothing if no new content
|
|
337
351
|
if (!newContentAppeared) {
|
|
338
352
|
return;
|
|
339
353
|
}
|
|
340
354
|
|
|
341
355
|
// Check if used to be scrolled to the bottom
|
|
342
|
-
if (
|
|
356
|
+
if (wasLastScrolledToBottom.current) {
|
|
343
357
|
// Was scrolled to the bottom! Autoscroll.
|
|
344
358
|
scrollToBottom();
|
|
345
359
|
} else {
|
|
@@ -348,14 +362,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
348
362
|
type: ActionType.ShowJumpToBottomButton,
|
|
349
363
|
});
|
|
350
364
|
}
|
|
351
|
-
|
|
352
|
-
// Update last item ids
|
|
353
|
-
lastItemIds.current = currentItemIds;
|
|
354
|
-
|
|
355
|
-
// Remember if we were scrolled to the bottom before the update
|
|
356
|
-
return () => {
|
|
357
|
-
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
358
|
-
};
|
|
359
365
|
},
|
|
360
366
|
[items],
|
|
361
367
|
);
|