@legendapp/list 0.5.8 → 0.5.9

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/index.d.mts CHANGED
@@ -77,6 +77,7 @@ interface InternalState {
77
77
  scroll: number;
78
78
  time: number;
79
79
  }>;
80
+ scrollTimer: Timer | undefined;
80
81
  }
81
82
  interface ViewableRange<T> {
82
83
  startBuffered: number;
package/index.d.ts CHANGED
@@ -77,6 +77,7 @@ interface InternalState {
77
77
  scroll: number;
78
78
  time: number;
79
79
  }>;
80
+ scrollTimer: Timer | undefined;
80
81
  }
81
82
  interface ViewableRange<T> {
82
83
  startBuffered: number;
package/index.js CHANGED
@@ -42,11 +42,11 @@ function useStateContext() {
42
42
  }
43
43
  function use$(signalName) {
44
44
  const ctx = React5__namespace.useContext(ContextState);
45
- const [, forceUpdate] = React5__namespace.useReducer((x) => x + 1, 0);
46
- React5.useMemo(() => {
47
- listen$(ctx, signalName, forceUpdate);
48
- }, []);
49
- return ctx.values.get(signalName);
45
+ const value = React5.useSyncExternalStore(
46
+ (onStoreChange) => listen$(ctx, signalName, onStoreChange),
47
+ () => ctx.values.get(signalName)
48
+ );
49
+ return value;
50
50
  }
51
51
  function listen$(ctx, signalName, cb) {
52
52
  const { listeners } = ctx;
@@ -148,10 +148,13 @@ var Container = ({
148
148
  /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent)
149
149
  );
150
150
  };
151
+ var useAnimatedValue = reactNative.useAnimatedValue || ((initialValue) => {
152
+ return React5.useRef(new reactNative.Animated.Value(initialValue)).current;
153
+ });
151
154
  function useValue$(key, getValue, key2) {
152
155
  var _a;
153
156
  const ctx = useStateContext();
154
- const animValue = reactNative.useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
157
+ const animValue = useAnimatedValue((_a = getValue ? getValue(peek$(ctx, key)) : peek$(ctx, key)) != null ? _a : 0);
155
158
  React5.useMemo(() => {
156
159
  listen$(ctx, key, (v) => animValue.setValue(getValue ? getValue(v) : v));
157
160
  }, []);
@@ -548,7 +551,8 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
548
551
  scrollVelocity: 0,
549
552
  contentSize: { width: 0, height: 0 },
550
553
  sizesLaidOut: __DEV__ ? /* @__PURE__ */ new Map() : void 0,
551
- timeoutSizeMessage: 0
554
+ timeoutSizeMessage: 0,
555
+ scrollTimer: void 0
552
556
  };
553
557
  refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
554
558
  set$(ctx, "scrollAdjust", refState.current.scrollAdjustPending);
@@ -1128,10 +1132,18 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1128
1132
  state.contentSize = event.nativeEvent.contentSize;
1129
1133
  const currentTime = performance.now();
1130
1134
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1131
- state.scrollHistory.push({ scroll: newScroll, time: currentTime });
1135
+ if (!(state.scrollHistory.length === 0 && newScroll === initialContentOffset)) {
1136
+ state.scrollHistory.push({ scroll: newScroll, time: currentTime });
1137
+ }
1132
1138
  if (state.scrollHistory.length > 5) {
1133
1139
  state.scrollHistory.shift();
1134
1140
  }
1141
+ if (state.scrollTimer !== void 0) {
1142
+ clearTimeout(state.scrollTimer);
1143
+ }
1144
+ state.scrollTimer = setTimeout(() => {
1145
+ state.scrollVelocity = 0;
1146
+ }, 500);
1135
1147
  let velocity = 0;
1136
1148
  if (state.scrollHistory.length >= 2) {
1137
1149
  const newest = state.scrollHistory[state.scrollHistory.length - 1];
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React5 from 'react';
2
- import React5__default, { forwardRef, useRef, useMemo, useCallback, useImperativeHandle, useEffect, useState } from 'react';
3
- import { Platform, StyleSheet, ScrollView, Animated, View, Dimensions, useAnimatedValue } from 'react-native';
2
+ import React5__default, { forwardRef, useRef, useMemo, useCallback, useImperativeHandle, useSyncExternalStore, useEffect, useState } from 'react';
3
+ import { Platform, StyleSheet, ScrollView, Animated, View, Dimensions, useAnimatedValue as useAnimatedValue$1 } from 'react-native';
4
4
 
5
5
  // src/LegendList.tsx
6
6
  var USE_CONTENT_INSET = Platform.OS === "ios";
@@ -21,11 +21,11 @@ function useStateContext() {
21
21
  }
22
22
  function use$(signalName) {
23
23
  const ctx = React5.useContext(ContextState);
24
- const [, forceUpdate] = React5.useReducer((x) => x + 1, 0);
25
- useMemo(() => {
26
- listen$(ctx, signalName, forceUpdate);
27
- }, []);
28
- return ctx.values.get(signalName);
24
+ const value = useSyncExternalStore(
25
+ (onStoreChange) => listen$(ctx, signalName, onStoreChange),
26
+ () => ctx.values.get(signalName)
27
+ );
28
+ return value;
29
29
  }
30
30
  function listen$(ctx, signalName, cb) {
31
31
  const { listeners } = ctx;
@@ -127,6 +127,9 @@ var Container = ({
127
127
  /* @__PURE__ */ React5__default.createElement(React5__default.Fragment, { key: recycleItems ? void 0 : itemKey }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent)
128
128
  );
129
129
  };
130
+ var useAnimatedValue = useAnimatedValue$1 || ((initialValue) => {
131
+ return useRef(new Animated.Value(initialValue)).current;
132
+ });
130
133
  function useValue$(key, getValue, key2) {
131
134
  var _a;
132
135
  const ctx = useStateContext();
@@ -527,7 +530,8 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
527
530
  scrollVelocity: 0,
528
531
  contentSize: { width: 0, height: 0 },
529
532
  sizesLaidOut: __DEV__ ? /* @__PURE__ */ new Map() : void 0,
530
- timeoutSizeMessage: 0
533
+ timeoutSizeMessage: 0,
534
+ scrollTimer: void 0
531
535
  };
532
536
  refState.current.idsInFirstRender = new Set(data.map((_, i) => getId(i)));
533
537
  set$(ctx, "scrollAdjust", refState.current.scrollAdjustPending);
@@ -1107,10 +1111,18 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1107
1111
  state.contentSize = event.nativeEvent.contentSize;
1108
1112
  const currentTime = performance.now();
1109
1113
  const newScroll = event.nativeEvent.contentOffset[horizontal ? "x" : "y"];
1110
- state.scrollHistory.push({ scroll: newScroll, time: currentTime });
1114
+ if (!(state.scrollHistory.length === 0 && newScroll === initialContentOffset)) {
1115
+ state.scrollHistory.push({ scroll: newScroll, time: currentTime });
1116
+ }
1111
1117
  if (state.scrollHistory.length > 5) {
1112
1118
  state.scrollHistory.shift();
1113
1119
  }
1120
+ if (state.scrollTimer !== void 0) {
1121
+ clearTimeout(state.scrollTimer);
1122
+ }
1123
+ state.scrollTimer = setTimeout(() => {
1124
+ state.scrollVelocity = 0;
1125
+ }, 500);
1114
1126
  let velocity = 0;
1115
1127
  if (state.scrollHistory.length >= 2) {
1116
1128
  const newest = state.scrollHistory[state.scrollHistory.length - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "legend-list",
5
5
  "sideEffects": false,
6
6
  "private": false,