@legendapp/list 1.0.0-beta.7 → 1.0.0-beta.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.
Files changed (3) hide show
  1. package/index.js +36 -34
  2. package/index.mjs +36 -34
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -595,7 +595,7 @@ var LegendList = React5.forwardRef(function LegendList2(props, forwardedRef) {
595
595
  return /* @__PURE__ */ React5__namespace.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.createElement(LegendListInner, { ...props, ref: forwardedRef }));
596
596
  });
597
597
  var LegendListInner = React5.forwardRef(function LegendListInner2(props, forwardedRef) {
598
- var _a, _b, _c, _d, _e;
598
+ var _a, _b, _c, _d, _e, _f, _g;
599
599
  const {
600
600
  data,
601
601
  initialScrollIndex,
@@ -1219,35 +1219,37 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1219
1219
  }
1220
1220
  refState.current.indexByKey = indexByKey;
1221
1221
  refState.current.positions = newPositions;
1222
- if (maintainVisibleContentPosition) {
1223
- if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1224
- if (data.length) {
1225
- const newAnchorElement = {
1226
- coordinate: 0,
1227
- id: getId(0)
1228
- };
1229
- refState.current.anchorElement = newAnchorElement;
1230
- (_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1231
- refScroller.current.scrollTo({ x: 0, y: 0, animated: false });
1222
+ if (!isFirst) {
1223
+ if (maintainVisibleContentPosition) {
1224
+ if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1225
+ if (data.length) {
1226
+ const newAnchorElement = {
1227
+ coordinate: 0,
1228
+ id: getId(0)
1229
+ };
1230
+ refState.current.anchorElement = newAnchorElement;
1231
+ (_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1232
+ (_b = refScroller.current) == null ? void 0 : _b.scrollTo({ x: 0, y: 0, animated: false });
1233
+ setTimeout(() => {
1234
+ calculateItemsInView(0);
1235
+ }, 0);
1236
+ } else {
1237
+ refState.current.startBufferedId = void 0;
1238
+ }
1239
+ }
1240
+ } else {
1241
+ if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1242
+ if (data.length) {
1243
+ refState.current.startBufferedId = getId(0);
1244
+ } else {
1245
+ refState.current.startBufferedId = void 0;
1246
+ }
1247
+ (_c = refScroller.current) == null ? void 0 : _c.scrollTo({ x: 0, y: 0, animated: false });
1232
1248
  setTimeout(() => {
1233
1249
  calculateItemsInView(0);
1234
1250
  }, 0);
1235
- } else {
1236
- refState.current.startBufferedId = void 0;
1237
1251
  }
1238
1252
  }
1239
- } else {
1240
- if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1241
- if (data.length) {
1242
- refState.current.startBufferedId = getId(0);
1243
- } else {
1244
- refState.current.startBufferedId = void 0;
1245
- }
1246
- refScroller.current.scrollTo({ x: 0, y: 0, animated: false });
1247
- setTimeout(() => {
1248
- calculateItemsInView(0);
1249
- }, 0);
1250
- }
1251
1253
  }
1252
1254
  const anchorElementIndex = getAnchorElementIndex();
1253
1255
  for (let i = 0; i < data.length; i++) {
@@ -1280,7 +1282,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1280
1282
  }, [extraData]);
1281
1283
  refState.current.renderItem = renderItem;
1282
1284
  const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1283
- 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;
1285
+ const stylePaddingTop = (_g = (_f = (_d = reactNative.StyleSheet.flatten(style)) == null ? void 0 : _d.paddingTop) != null ? _f : (_e = reactNative.StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _e.paddingTop) != null ? _g : 0;
1284
1286
  const initalizeStateVars = () => {
1285
1287
  set$(ctx, "lastItemKey", lastItemKey);
1286
1288
  set$(ctx, "numColumns", numColumnsProp);
@@ -1341,22 +1343,18 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1341
1343
  calculateItemsInView(state.scrollVelocity);
1342
1344
  });
1343
1345
  const updateItemSize = React5.useCallback((containerId, itemKey, size) => {
1344
- var _a2;
1345
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
1346
+ const state = refState.current;
1347
+ const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1346
1348
  if (!data2) {
1347
1349
  return;
1348
1350
  }
1349
- const state = refState.current;
1350
- const { sizes, indexByKey, columns, sizesLaidOut } = state;
1351
1351
  const index = indexByKey.get(itemKey);
1352
1352
  const numColumns = peek$(ctx, "numColumns");
1353
1353
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1354
- const row = Math.floor(index / numColumns);
1355
- const prevSize = getRowHeight(row);
1354
+ const prevSize = getItemSize(itemKey, index, data2);
1356
1355
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1357
1356
  let diff;
1358
1357
  if (numColumns > 1) {
1359
- const prevMaxSizeInRow = getRowHeight(row);
1360
1358
  sizes.set(itemKey, size);
1361
1359
  const column = columns.get(itemKey);
1362
1360
  const loopStart = index - (column - 1);
@@ -1366,7 +1364,7 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1366
1364
  const size2 = getItemSize(id, i, data2[i]);
1367
1365
  nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1368
1366
  }
1369
- diff = nextMaxSizeInRow - prevMaxSizeInRow;
1367
+ diff = nextMaxSizeInRow - prevSize;
1370
1368
  } else {
1371
1369
  sizes.set(itemKey, size);
1372
1370
  diff = size - prevSize;
@@ -1419,11 +1417,15 @@ var LegendListInner = React5.forwardRef(function LegendListInner2(props, forward
1419
1417
  }, []);
1420
1418
  const onLayout = React5.useCallback((event) => {
1421
1419
  const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
1420
+ const didChange = scrollLength !== refState.current.scrollLength;
1422
1421
  refState.current.scrollLength = scrollLength;
1423
1422
  doMaintainScrollAtEnd(false);
1424
1423
  doUpdatePaddingTop();
1425
1424
  checkAtBottom();
1426
1425
  checkAtTop();
1426
+ if (didChange) {
1427
+ calculateItemsInView(0);
1428
+ }
1427
1429
  if (__DEV__) {
1428
1430
  const isWidthZero = event.nativeEvent.layout.width === 0;
1429
1431
  const isHeightZero = event.nativeEvent.layout.height === 0;
package/index.mjs CHANGED
@@ -574,7 +574,7 @@ var LegendList = forwardRef(function LegendList2(props, forwardedRef) {
574
574
  return /* @__PURE__ */ React5.createElement(StateProvider, null, /* @__PURE__ */ React5.createElement(LegendListInner, { ...props, ref: forwardedRef }));
575
575
  });
576
576
  var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef) {
577
- var _a, _b, _c, _d, _e;
577
+ var _a, _b, _c, _d, _e, _f, _g;
578
578
  const {
579
579
  data,
580
580
  initialScrollIndex,
@@ -1198,35 +1198,37 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1198
1198
  }
1199
1199
  refState.current.indexByKey = indexByKey;
1200
1200
  refState.current.positions = newPositions;
1201
- if (maintainVisibleContentPosition) {
1202
- if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1203
- if (data.length) {
1204
- const newAnchorElement = {
1205
- coordinate: 0,
1206
- id: getId(0)
1207
- };
1208
- refState.current.anchorElement = newAnchorElement;
1209
- (_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1210
- refScroller.current.scrollTo({ x: 0, y: 0, animated: false });
1201
+ if (!isFirst) {
1202
+ if (maintainVisibleContentPosition) {
1203
+ if (refState.current.anchorElement == null || indexByKey.get(refState.current.anchorElement.id) == null) {
1204
+ if (data.length) {
1205
+ const newAnchorElement = {
1206
+ coordinate: 0,
1207
+ id: getId(0)
1208
+ };
1209
+ refState.current.anchorElement = newAnchorElement;
1210
+ (_a = refState.current.belowAnchorElementPositions) == null ? void 0 : _a.clear();
1211
+ (_b = refScroller.current) == null ? void 0 : _b.scrollTo({ x: 0, y: 0, animated: false });
1212
+ setTimeout(() => {
1213
+ calculateItemsInView(0);
1214
+ }, 0);
1215
+ } else {
1216
+ refState.current.startBufferedId = void 0;
1217
+ }
1218
+ }
1219
+ } else {
1220
+ if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1221
+ if (data.length) {
1222
+ refState.current.startBufferedId = getId(0);
1223
+ } else {
1224
+ refState.current.startBufferedId = void 0;
1225
+ }
1226
+ (_c = refScroller.current) == null ? void 0 : _c.scrollTo({ x: 0, y: 0, animated: false });
1211
1227
  setTimeout(() => {
1212
1228
  calculateItemsInView(0);
1213
1229
  }, 0);
1214
- } else {
1215
- refState.current.startBufferedId = void 0;
1216
1230
  }
1217
1231
  }
1218
- } else {
1219
- if (refState.current.startBufferedId != null && newPositions.get(refState.current.startBufferedId) == null) {
1220
- if (data.length) {
1221
- refState.current.startBufferedId = getId(0);
1222
- } else {
1223
- refState.current.startBufferedId = void 0;
1224
- }
1225
- refScroller.current.scrollTo({ x: 0, y: 0, animated: false });
1226
- setTimeout(() => {
1227
- calculateItemsInView(0);
1228
- }, 0);
1229
- }
1230
1232
  }
1231
1233
  const anchorElementIndex = getAnchorElementIndex();
1232
1234
  for (let i = 0; i < data.length; i++) {
@@ -1259,7 +1261,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1259
1261
  }, [extraData]);
1260
1262
  refState.current.renderItem = renderItem;
1261
1263
  const lastItemKey = data.length > 0 ? getId(data.length - 1) : void 0;
1262
- 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;
1264
+ const stylePaddingTop = (_g = (_f = (_d = StyleSheet.flatten(style)) == null ? void 0 : _d.paddingTop) != null ? _f : (_e = StyleSheet.flatten(contentContainerStyle)) == null ? void 0 : _e.paddingTop) != null ? _g : 0;
1263
1265
  const initalizeStateVars = () => {
1264
1266
  set$(ctx, "lastItemKey", lastItemKey);
1265
1267
  set$(ctx, "numColumns", numColumnsProp);
@@ -1320,22 +1322,18 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1320
1322
  calculateItemsInView(state.scrollVelocity);
1321
1323
  });
1322
1324
  const updateItemSize = useCallback((containerId, itemKey, size) => {
1323
- var _a2;
1324
- const data2 = (_a2 = refState.current) == null ? void 0 : _a2.data;
1325
+ const state = refState.current;
1326
+ const { sizes, indexByKey, columns, sizesLaidOut, data: data2 } = state;
1325
1327
  if (!data2) {
1326
1328
  return;
1327
1329
  }
1328
- const state = refState.current;
1329
- const { sizes, indexByKey, columns, sizesLaidOut } = state;
1330
1330
  const index = indexByKey.get(itemKey);
1331
1331
  const numColumns = peek$(ctx, "numColumns");
1332
1332
  state.minIndexSizeChanged = state.minIndexSizeChanged !== void 0 ? Math.min(state.minIndexSizeChanged, index) : index;
1333
- const row = Math.floor(index / numColumns);
1334
- const prevSize = getRowHeight(row);
1333
+ const prevSize = getItemSize(itemKey, index, data2);
1335
1334
  if (!prevSize || Math.abs(prevSize - size) > 0.5) {
1336
1335
  let diff;
1337
1336
  if (numColumns > 1) {
1338
- const prevMaxSizeInRow = getRowHeight(row);
1339
1337
  sizes.set(itemKey, size);
1340
1338
  const column = columns.get(itemKey);
1341
1339
  const loopStart = index - (column - 1);
@@ -1345,7 +1343,7 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1345
1343
  const size2 = getItemSize(id, i, data2[i]);
1346
1344
  nextMaxSizeInRow = Math.max(nextMaxSizeInRow, size2);
1347
1345
  }
1348
- diff = nextMaxSizeInRow - prevMaxSizeInRow;
1346
+ diff = nextMaxSizeInRow - prevSize;
1349
1347
  } else {
1350
1348
  sizes.set(itemKey, size);
1351
1349
  diff = size - prevSize;
@@ -1398,11 +1396,15 @@ var LegendListInner = forwardRef(function LegendListInner2(props, forwardedRef)
1398
1396
  }, []);
1399
1397
  const onLayout = useCallback((event) => {
1400
1398
  const scrollLength = event.nativeEvent.layout[horizontal ? "width" : "height"];
1399
+ const didChange = scrollLength !== refState.current.scrollLength;
1401
1400
  refState.current.scrollLength = scrollLength;
1402
1401
  doMaintainScrollAtEnd(false);
1403
1402
  doUpdatePaddingTop();
1404
1403
  checkAtBottom();
1405
1404
  checkAtTop();
1405
+ if (didChange) {
1406
+ calculateItemsInView(0);
1407
+ }
1406
1408
  if (__DEV__) {
1407
1409
  const isWidthZero = event.nativeEvent.layout.width === 0;
1408
1410
  const isHeightZero = event.nativeEvent.layout.height === 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "legend-list",
5
5
  "sideEffects": false,
6
6
  "private": false,