@legendapp/list 1.0.0-beta.3 → 1.0.0-beta.4

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
@@ -16,7 +16,7 @@ declare class ScrollAdjustHandler {
16
16
  }
17
17
 
18
18
  type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition' | 'stickyHeaderIndices'> & {
19
- data: ArrayLike<any> & ItemT[];
19
+ data: ReadonlyArray<ItemT>;
20
20
  initialScrollOffset?: number;
21
21
  initialScrollIndex?: number;
22
22
  drawDistance?: number;
@@ -45,7 +45,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
45
45
  ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
46
46
  ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
47
47
  ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
48
- ListEmptyComponentStyle?: StyleProp<ViewStyle> | undefined;
49
48
  ItemSeparatorComponent?: React.ComponentType<any>;
50
49
  viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
51
50
  viewabilityConfig?: ViewabilityConfig;
@@ -87,7 +86,7 @@ interface InternalState {
87
86
  isEndReached: boolean;
88
87
  isAtBottom: boolean;
89
88
  isAtTop: boolean;
90
- data: any[];
89
+ data: readonly any[];
91
90
  idsInFirstRender: Set<string>;
92
91
  hasScrolled: boolean;
93
92
  scrollLength: number;
package/index.d.ts CHANGED
@@ -16,7 +16,7 @@ declare class ScrollAdjustHandler {
16
16
  }
17
17
 
18
18
  type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof ScrollView> | ComponentProps<typeof Animated.ScrollView>> = Omit<TScrollView, 'contentOffset' | 'contentInset' | 'maintainVisibleContentPosition' | 'stickyHeaderIndices'> & {
19
- data: ArrayLike<any> & ItemT[];
19
+ data: ReadonlyArray<ItemT>;
20
20
  initialScrollOffset?: number;
21
21
  initialScrollIndex?: number;
22
22
  drawDistance?: number;
@@ -45,7 +45,6 @@ type LegendListPropsBase<ItemT, TScrollView extends ComponentProps<typeof Scroll
45
45
  ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
46
46
  ListFooterComponentStyle?: StyleProp<ViewStyle> | undefined;
47
47
  ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null | undefined;
48
- ListEmptyComponentStyle?: StyleProp<ViewStyle> | undefined;
49
48
  ItemSeparatorComponent?: React.ComponentType<any>;
50
49
  viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs | undefined;
51
50
  viewabilityConfig?: ViewabilityConfig;
@@ -87,7 +86,7 @@ interface InternalState {
87
86
  isEndReached: boolean;
88
87
  isAtBottom: boolean;
89
88
  isAtTop: boolean;
90
- data: any[];
89
+ data: readonly any[];
91
90
  idsInFirstRender: Set<string>;
92
91
  hasScrolled: boolean;
93
92
  scrollLength: number;
package/index.js CHANGED
@@ -176,6 +176,7 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
176
176
  };
177
177
 
178
178
  // src/Container.tsx
179
+ var isNewArchitecture = global.nativeFabricUIManager != null;
179
180
  var Container = ({
180
181
  id,
181
182
  recycleItems,
@@ -184,7 +185,7 @@ var Container = ({
184
185
  updateItemSize,
185
186
  ItemSeparatorComponent
186
187
  }) => {
187
- const ctx = useStateContext();
188
+ useStateContext();
188
189
  const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
189
190
  const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
190
191
  const column = use$(`containerColumn${id}`) || 0;
@@ -209,44 +210,36 @@ var Container = ({
209
210
  const itemKey = use$(`containerItemKey${id}`);
210
211
  const data = use$(`containerItemData${id}`);
211
212
  const extraData = use$("extraData");
212
- const refLastSize = React5.useRef();
213
213
  const renderedItemInfo = React5.useMemo(
214
214
  () => itemKey !== void 0 && getRenderedItem(itemKey),
215
215
  [itemKey, data, extraData]
216
216
  );
217
217
  const { index, renderedItem } = renderedItemInfo || {};
218
- React5.useEffect(() => {
219
- if (itemKey) {
220
- const timeout = setTimeout(() => {
221
- if (refLastSize.current) {
222
- updateItemSize(id, itemKey, refLastSize.current);
223
- }
224
- }, 16);
225
- return () => {
226
- clearTimeout(timeout);
227
- };
228
- }
229
- }, [itemKey]);
230
218
  const onLayout = (event) => {
231
- const key = peek$(ctx, `containerItemKey${id}`);
232
- if (key !== void 0) {
219
+ if (itemKey !== void 0) {
233
220
  const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
234
- updateItemSize(id, key, size);
221
+ if (size === 0) {
222
+ console.log("[WARN] Container 0 height reported, possible bug in LegendList", id, itemKey);
223
+ return;
224
+ }
225
+ updateItemSize(id, itemKey, size);
235
226
  }
236
227
  };
237
228
  const ref = React5.useRef(null);
238
- React5.useLayoutEffect(() => {
239
- var _a, _b;
240
- if (itemKey) {
241
- const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
242
- if (measured) {
243
- const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
244
- if (size) {
245
- updateItemSize(id, itemKey, size);
229
+ if (isNewArchitecture) {
230
+ React5.useLayoutEffect(() => {
231
+ var _a, _b;
232
+ if (itemKey) {
233
+ const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
234
+ if (measured) {
235
+ const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
236
+ if (size) {
237
+ updateItemSize(id, itemKey, size);
238
+ }
246
239
  }
247
240
  }
248
- }
249
- }, [itemKey]);
241
+ }, [itemKey]);
242
+ }
250
243
  const contextValue = React5.useMemo(
251
244
  () => ({ containerId: id, itemKey, index, value: data }),
252
245
  [id, itemKey, index, data]
@@ -254,7 +247,7 @@ var Container = ({
254
247
  const contentFragment = /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React5__namespace.default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
255
248
  if (maintainVisibleContentPosition) {
256
249
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
257
- return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style, ref }, /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout }, contentFragment));
250
+ return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style }, /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment));
258
251
  }
259
252
  return /* @__PURE__ */ React5__namespace.default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
260
253
  };
@@ -330,7 +323,6 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
330
323
  ListFooterComponent,
331
324
  ListFooterComponentStyle,
332
325
  ListEmptyComponent,
333
- ListEmptyComponentStyle,
334
326
  getRenderedItem,
335
327
  updateItemSize,
336
328
  refScrollView,
@@ -379,7 +371,7 @@ var ListComponent = React5__namespace.memo(function ListComponent2({
379
371
  },
380
372
  getComponent(ListHeaderComponent)
381
373
  ),
382
- ListEmptyComponent && /* @__PURE__ */ React5__namespace.createElement(reactNative.Animated.View, { style: ListEmptyComponentStyle }, getComponent(ListEmptyComponent)),
374
+ ListEmptyComponent && getComponent(ListEmptyComponent),
383
375
  /* @__PURE__ */ React5__namespace.createElement(
384
376
  Containers,
385
377
  {
@@ -736,7 +728,6 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
736
728
  isAboveAnchor = true;
737
729
  }
738
730
  }
739
- state.totalSize;
740
731
  if (key === null) {
741
732
  state.totalSize = add;
742
733
  state.totalSizeBelowAnchor = totalSizeBelowAnchor;
@@ -837,7 +828,17 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
837
828
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
838
829
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
839
830
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
840
- const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
831
+ const scroll = scrollState - previousScrollAdjust - topPad;
832
+ let scrollBufferTop = scrollBuffer;
833
+ let scrollBufferBottom = scrollBuffer;
834
+ if (scrollExtra > 8) {
835
+ scrollBufferTop = 0;
836
+ scrollBufferBottom = scrollBuffer + scrollExtra;
837
+ }
838
+ if (scrollExtra < -8) {
839
+ scrollBufferTop = scrollBuffer - scrollExtra;
840
+ scrollBufferBottom = 0;
841
+ }
841
842
  if (state.scrollForNextCalculateItemsInView) {
842
843
  const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
843
844
  if (scroll > top2 && scroll < bottom) {
@@ -909,7 +910,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
909
910
  if (startNoBuffer === null && top + size > scroll) {
910
911
  startNoBuffer = i;
911
912
  }
912
- if (startBuffered === null && top + size > scroll - scrollBuffer) {
913
+ if (startBuffered === null && top + size > scroll - scrollBufferTop) {
913
914
  startBuffered = i;
914
915
  startBufferedId = id;
915
916
  }
@@ -917,7 +918,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
917
918
  if (top <= scrollBottom) {
918
919
  endNoBuffer = i;
919
920
  }
920
- if (top <= scrollBottom + scrollBuffer) {
921
+ if (top <= scrollBottom + scrollBufferBottom) {
921
922
  endBuffered = i;
922
923
  } else {
923
924
  break;
@@ -1244,7 +1245,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1244
1245
  set$(ctx, "extraData", extraData);
1245
1246
  }, [extraData]);
1246
1247
  refState.current.renderItem = renderItem;
1247
- const lastItemKey = getId(data[data.length - 1]);
1248
+ const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1248
1249
  const stylePaddingTop = (_e = (_d = (_b = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _b.paddingTop) != null ? _d : (_c = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _c.paddingTop) != null ? _e : 0;
1249
1250
  const initalizeStateVars = () => {
1250
1251
  set$(ctx, "lastItemKey", lastItemKey);
package/index.mjs CHANGED
@@ -155,6 +155,7 @@ var ANCHORED_POSITION_OUT_OF_VIEW = {
155
155
  };
156
156
 
157
157
  // src/Container.tsx
158
+ var isNewArchitecture = global.nativeFabricUIManager != null;
158
159
  var Container = ({
159
160
  id,
160
161
  recycleItems,
@@ -163,7 +164,7 @@ var Container = ({
163
164
  updateItemSize,
164
165
  ItemSeparatorComponent
165
166
  }) => {
166
- const ctx = useStateContext();
167
+ useStateContext();
167
168
  const maintainVisibleContentPosition = use$("maintainVisibleContentPosition");
168
169
  const position = use$(`containerPosition${id}`) || ANCHORED_POSITION_OUT_OF_VIEW;
169
170
  const column = use$(`containerColumn${id}`) || 0;
@@ -188,44 +189,36 @@ var Container = ({
188
189
  const itemKey = use$(`containerItemKey${id}`);
189
190
  const data = use$(`containerItemData${id}`);
190
191
  const extraData = use$("extraData");
191
- const refLastSize = useRef();
192
192
  const renderedItemInfo = useMemo(
193
193
  () => itemKey !== void 0 && getRenderedItem(itemKey),
194
194
  [itemKey, data, extraData]
195
195
  );
196
196
  const { index, renderedItem } = renderedItemInfo || {};
197
- useEffect(() => {
198
- if (itemKey) {
199
- const timeout = setTimeout(() => {
200
- if (refLastSize.current) {
201
- updateItemSize(id, itemKey, refLastSize.current);
202
- }
203
- }, 16);
204
- return () => {
205
- clearTimeout(timeout);
206
- };
207
- }
208
- }, [itemKey]);
209
197
  const onLayout = (event) => {
210
- const key = peek$(ctx, `containerItemKey${id}`);
211
- if (key !== void 0) {
198
+ if (itemKey !== void 0) {
212
199
  const size = Math.floor(event.nativeEvent.layout[horizontal ? "width" : "height"] * 8) / 8;
213
- updateItemSize(id, key, size);
200
+ if (size === 0) {
201
+ console.log("[WARN] Container 0 height reported, possible bug in LegendList", id, itemKey);
202
+ return;
203
+ }
204
+ updateItemSize(id, itemKey, size);
214
205
  }
215
206
  };
216
207
  const ref = useRef(null);
217
- useLayoutEffect(() => {
218
- var _a, _b;
219
- if (itemKey) {
220
- const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
221
- if (measured) {
222
- const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
223
- if (size) {
224
- updateItemSize(id, itemKey, size);
208
+ if (isNewArchitecture) {
209
+ useLayoutEffect(() => {
210
+ var _a, _b;
211
+ if (itemKey) {
212
+ const measured = (_b = (_a = ref.current) == null ? void 0 : _a.unstable_getBoundingClientRect) == null ? void 0 : _b.call(_a);
213
+ if (measured) {
214
+ const size = Math.floor(measured[horizontal ? "width" : "height"] * 8) / 8;
215
+ if (size) {
216
+ updateItemSize(id, itemKey, size);
217
+ }
225
218
  }
226
219
  }
227
- }
228
- }, [itemKey]);
220
+ }, [itemKey]);
221
+ }
229
222
  const contextValue = useMemo(
230
223
  () => ({ containerId: id, itemKey, index, value: data }),
231
224
  [id, itemKey, index, data]
@@ -233,7 +226,7 @@ var Container = ({
233
226
  const contentFragment = /* @__PURE__ */ React5__default.createElement(React5__default.Fragment, { key: recycleItems ? void 0 : itemKey }, /* @__PURE__ */ React5__default.createElement(ContextContainer.Provider, { value: contextValue }, renderedItem, renderedItem && ItemSeparatorComponent && itemKey !== lastItemKey && ItemSeparatorComponent));
234
227
  if (maintainVisibleContentPosition) {
235
228
  const anchorStyle = position.type === "top" ? { position: "absolute", top: 0, left: 0, right: 0 } : { position: "absolute", bottom: 0, left: 0, right: 0 };
236
- return /* @__PURE__ */ React5__default.createElement(LeanView, { style, ref }, /* @__PURE__ */ React5__default.createElement(LeanView, { style: anchorStyle, onLayout }, contentFragment));
229
+ return /* @__PURE__ */ React5__default.createElement(LeanView, { style }, /* @__PURE__ */ React5__default.createElement(LeanView, { style: anchorStyle, onLayout, ref }, contentFragment));
237
230
  }
238
231
  return /* @__PURE__ */ React5__default.createElement(LeanView, { style, onLayout, ref }, contentFragment);
239
232
  };
@@ -309,7 +302,6 @@ var ListComponent = React5.memo(function ListComponent2({
309
302
  ListFooterComponent,
310
303
  ListFooterComponentStyle,
311
304
  ListEmptyComponent,
312
- ListEmptyComponentStyle,
313
305
  getRenderedItem,
314
306
  updateItemSize,
315
307
  refScrollView,
@@ -358,7 +350,7 @@ var ListComponent = React5.memo(function ListComponent2({
358
350
  },
359
351
  getComponent(ListHeaderComponent)
360
352
  ),
361
- ListEmptyComponent && /* @__PURE__ */ React5.createElement(Animated.View, { style: ListEmptyComponentStyle }, getComponent(ListEmptyComponent)),
353
+ ListEmptyComponent && getComponent(ListEmptyComponent),
362
354
  /* @__PURE__ */ React5.createElement(
363
355
  Containers,
364
356
  {
@@ -715,7 +707,6 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
715
707
  isAboveAnchor = true;
716
708
  }
717
709
  }
718
- state.totalSize;
719
710
  if (key === null) {
720
711
  state.totalSize = add;
721
712
  state.totalSizeBelowAnchor = totalSizeBelowAnchor;
@@ -816,7 +807,17 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
816
807
  const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
817
808
  const previousScrollAdjust = scrollAdjustHandler.getAppliedAdjust();
818
809
  const scrollExtra = Math.max(-16, Math.min(16, speed)) * 16;
819
- const scroll = scrollState - previousScrollAdjust - topPad - scrollExtra;
810
+ const scroll = scrollState - previousScrollAdjust - topPad;
811
+ let scrollBufferTop = scrollBuffer;
812
+ let scrollBufferBottom = scrollBuffer;
813
+ if (scrollExtra > 8) {
814
+ scrollBufferTop = 0;
815
+ scrollBufferBottom = scrollBuffer + scrollExtra;
816
+ }
817
+ if (scrollExtra < -8) {
818
+ scrollBufferTop = scrollBuffer - scrollExtra;
819
+ scrollBufferBottom = 0;
820
+ }
820
821
  if (state.scrollForNextCalculateItemsInView) {
821
822
  const { top: top2, bottom } = state.scrollForNextCalculateItemsInView;
822
823
  if (scroll > top2 && scroll < bottom) {
@@ -888,7 +889,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
888
889
  if (startNoBuffer === null && top + size > scroll) {
889
890
  startNoBuffer = i;
890
891
  }
891
- if (startBuffered === null && top + size > scroll - scrollBuffer) {
892
+ if (startBuffered === null && top + size > scroll - scrollBufferTop) {
892
893
  startBuffered = i;
893
894
  startBufferedId = id;
894
895
  }
@@ -896,7 +897,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
896
897
  if (top <= scrollBottom) {
897
898
  endNoBuffer = i;
898
899
  }
899
- if (top <= scrollBottom + scrollBuffer) {
900
+ if (top <= scrollBottom + scrollBufferBottom) {
900
901
  endBuffered = i;
901
902
  } else {
902
903
  break;
@@ -1223,7 +1224,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1223
1224
  set$(ctx, "extraData", extraData);
1224
1225
  }, [extraData]);
1225
1226
  refState.current.renderItem = renderItem;
1226
- const lastItemKey = getId(data[data.length - 1]);
1227
+ const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1227
1228
  const stylePaddingTop = (_e = (_d = (_b = StyleSheet.flatten(style)) == null ? void 0 : _b.paddingTop) != null ? _d : (_c = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _c.paddingTop) != null ? _e : 0;
1228
1229
  const initalizeStateVars = () => {
1229
1230
  set$(ctx, "lastItemKey", lastItemKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "legend-list",
5
5
  "sideEffects": false,
6
6
  "private": false,