@onekeyfe/react-native-native-list 6.7.0-4 → 6.7.0-5

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/docs/SPEC.md CHANGED
@@ -1183,3 +1183,13 @@ listener on destroy. It measures the new content origin before Pager restores
1183
1183
  its C+B offset; a later ResizeObserver must not add that inset a second time.
1184
1184
  Ordinary subsequent slot-height changes retain the existing content-anchor
1185
1185
  compensation. Standalone lists continue listening on their own viewport.
1186
+
1187
+ ### Web History retained visual binding
1188
+
1189
+ Implemented contract: same-source History visuals retain their image, placeholder
1190
+ and corner nodes while image styles or table/stacked presentation change. Every
1191
+ bind restores the factory geometry and applies the current image style and
1192
+ presentation, including clearing omitted radius/contentFit/shape overrides.
1193
+ Presentation wrapper changes move the existing nodes and preserve asynchronous
1194
+ loading/error visibility; they do not recreate or reload an unchanged source.
1195
+ Changing the source set retains the existing rebuild/disposal behavior.
@@ -146,6 +146,7 @@ function createHistory(body, primitives) {
146
146
  actions,
147
147
  actionButtons: new Map(),
148
148
  visualKey: '',
149
+ visuals: [],
149
150
  primitives
150
151
  };
151
152
  histories.set(body, v);
@@ -237,73 +238,124 @@ function bindHistory(body, row, primitives) {
237
238
  if (v.visualKey !== visualKey) {
238
239
  Array.from(v.visual.children).forEach(n => primitives.dispose(n));
239
240
  v.visual.replaceChildren();
241
+ v.visuals = [];
240
242
  const sources = [row.leading, row.secondaryLeading].filter(Boolean);
241
- sources.forEach((source, index) => {
243
+ sources.forEach(source => {
242
244
  const visual = primitives.visual(source);
243
245
  if (!visual) return;
244
- const size = sources.length > 1 ? index ? 28 : 24 : 40;
245
- new RowVisualStyle(visual).apply(row.style?.image, size, size, 0);
246
- Object.assign(visual.style, {
247
- display: 'inline-flex',
248
- alignItems: 'center',
249
- justifyContent: 'center'
250
- });
251
- if (sources.length > 1) Object.assign(visual.style, {
252
- position: 'absolute',
253
- left: index ? '12px' : '0',
254
- top: index ? '12px' : '0',
255
- border: index ? '2px solid var(--nl-row)' : '0',
256
- boxSizing: 'border-box'
257
- });
258
246
  historyIcon(visual, source, table || sources.length > 1 ? 24 : 28);
259
- if (!table && sources.length > 1) {
260
- const token = visual.ownerDocument.createElement('span');
261
- Object.assign(token.style, {
262
- display: 'flex',
263
- alignItems: 'center',
264
- justifyContent: 'center',
265
- position: 'relative',
266
- width: '24px',
267
- height: '24px',
268
- flex: '0 0 24px',
269
- borderRadius: 'inherit',
270
- boxSizing: 'border-box',
271
- overflow: 'hidden',
272
- background: source && 'backgroundColor' in source ? source.backgroundColor ?? '' : '',
273
- border: source && 'borderColor' in source && source.borderColor ? `1px solid ${source.borderColor}` : '0'
247
+ const retained = {
248
+ node: visual,
249
+ style: new RowVisualStyle(visual),
250
+ background: visual.style.background,
251
+ loaded: false
252
+ };
253
+ // Only placeholder-backed sources restore their frame background on load.
254
+ const image = source && 'image' in source ? source.image : undefined;
255
+ if (image?.loadingStrategy && image.loadingStrategy !== 'none') {
256
+ visual.querySelector('.ok-native-list-visual-main')?.addEventListener('load', () => {
257
+ retained.background = source && 'backgroundColor' in source && source.backgroundColor ? source.backgroundColor : 'transparent';
258
+ retained.loaded = true;
274
259
  });
275
- token.append(...Array.from(visual.children).filter(child => !child.classList.contains('ok-native-list-visual-corner')));
276
- const fallback = token.querySelector(':scope > .ok-native-list-visual-fallback');
277
- if (fallback) {
278
- fallback.style.width = '24px';
279
- fallback.style.height = '24px';
280
- fallback.style.flexShrink = '0';
281
- }
282
- const mainImage = token.querySelector(':scope > .ok-native-list-visual-main');
283
- if (mainImage) {
284
- mainImage.style.width = '100%';
285
- mainImage.style.height = '100%';
286
- }
287
- visual.append(token);
288
- }
289
- if (table) {
290
- visual.style.background = source && 'backgroundColor' in source && source.backgroundColor ? source.backgroundColor : 'var(--nl-strong)';
291
- const borderColor = source && 'borderColor' in source && source.borderColor ? source.borderColor : 'var(--nl-separator)';
292
- visual.style.border = `1px solid ${borderColor}`;
293
- visual.style.boxSizing = 'border-box';
294
- } else if (sources.length === 1 && source?.kind === 'token') {
295
- visual.style.border = source.borderColor ? `1px solid ${source.borderColor}` : '0';
296
- visual.style.boxSizing = 'border-box';
297
- const mainImage = visual.querySelector(':scope > .ok-native-list-visual-main');
298
- if (mainImage) {
299
- mainImage.style.width = '100%';
300
- mainImage.style.height = '100%';
301
- }
302
260
  }
261
+ v.visuals.push(retained);
303
262
  v.visual.append(visual);
304
263
  });
305
264
  v.visualKey = visualKey;
306
265
  }
266
+ const sources = [row.leading, row.secondaryLeading].filter(Boolean);
267
+ v.visuals.forEach((retained, index) => {
268
+ const {
269
+ node: visual,
270
+ style,
271
+ background,
272
+ loaded
273
+ } = retained;
274
+ const source = sources[index];
275
+ const previousToken = visual.querySelector(':scope > .ok-native-list-history-token');
276
+ if (previousToken) {
277
+ visual.append(...Array.from(previousToken.children));
278
+ previousToken.remove();
279
+ }
280
+ const currentFallback = visual.querySelector(':scope > .ok-native-list-visual-fallback:not(.ok-native-list-visual-corner)');
281
+ if (currentFallback && retained.fallback !== currentFallback) {
282
+ retained.fallback = currentFallback;
283
+ retained.fallbackStyle = new RowVisualStyle(currentFallback);
284
+ }
285
+ // A terminal image error creates a new fallback node after the factory bind.
286
+ retained.fallbackStyle?.restore();
287
+ const size = sources.length > 1 ? index ? 28 : 24 : 40;
288
+ style.apply(row.style?.image, size, size, 0);
289
+ Object.assign(visual.style, {
290
+ background,
291
+ position: '',
292
+ left: '',
293
+ top: ''
294
+ });
295
+ const svg = visual.querySelector('.ok-native-list-visual-fallback > svg');
296
+ if (svg) {
297
+ const iconSize = String(table || sources.length > 1 ? 24 : 28);
298
+ svg.setAttribute('width', iconSize);
299
+ svg.setAttribute('height', iconSize);
300
+ }
301
+ Object.assign(visual.style, {
302
+ display: 'inline-flex',
303
+ alignItems: 'center',
304
+ justifyContent: 'center'
305
+ });
306
+ if (sources.length > 1) Object.assign(visual.style, {
307
+ position: 'absolute',
308
+ left: index ? '12px' : '0',
309
+ top: index ? '12px' : '0',
310
+ border: index ? '2px solid var(--nl-row)' : '0',
311
+ boxSizing: 'border-box'
312
+ });
313
+ if (!table && sources.length > 1) {
314
+ const token = visual.ownerDocument.createElement('span');
315
+ token.className = 'ok-native-list-history-token';
316
+ Object.assign(token.style, {
317
+ display: 'flex',
318
+ alignItems: 'center',
319
+ justifyContent: 'center',
320
+ position: 'relative',
321
+ width: '24px',
322
+ height: '24px',
323
+ flex: '0 0 24px',
324
+ borderRadius: 'inherit',
325
+ boxSizing: 'border-box',
326
+ overflow: 'hidden',
327
+ background: source && 'backgroundColor' in source ? source.backgroundColor ?? '' : '',
328
+ border: source && 'borderColor' in source && source.borderColor ? `1px solid ${source.borderColor}` : '0'
329
+ });
330
+ token.append(...Array.from(visual.children).filter(child => !child.classList.contains('ok-native-list-visual-corner')));
331
+ const fallback = token.querySelector(':scope > .ok-native-list-visual-fallback');
332
+ if (fallback) {
333
+ fallback.style.width = '24px';
334
+ fallback.style.height = '24px';
335
+ fallback.style.flexShrink = '0';
336
+ }
337
+ const mainImage = token.querySelector(':scope > .ok-native-list-visual-main');
338
+ if (mainImage) {
339
+ mainImage.style.width = '100%';
340
+ mainImage.style.height = '100%';
341
+ }
342
+ visual.append(token);
343
+ }
344
+ if (table) {
345
+ visual.style.background = loaded ? background : source && 'backgroundColor' in source && source.backgroundColor ? source.backgroundColor : 'var(--nl-strong)';
346
+ const borderColor = source && 'borderColor' in source && source.borderColor ? source.borderColor : 'var(--nl-separator)';
347
+ visual.style.border = `1px solid ${borderColor}`;
348
+ visual.style.boxSizing = 'border-box';
349
+ } else if (sources.length === 1 && source?.kind === 'token') {
350
+ visual.style.border = source.borderColor ? `1px solid ${source.borderColor}` : '0';
351
+ visual.style.boxSizing = 'border-box';
352
+ const mainImage = visual.querySelector(':scope > .ok-native-list-visual-main');
353
+ if (mainImage) {
354
+ mainImage.style.width = '100%';
355
+ mainImage.style.height = '100%';
356
+ }
357
+ }
358
+ });
307
359
  Object.assign(v.text.style, {
308
360
  minWidth: '0',
309
361
  flex: '1 1 auto',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "6.7.0-4",
3
+ "version": "6.7.0-5",
4
4
  "description": "Template-driven native RecyclerView and UICollectionView for React Native",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -86,8 +86,8 @@
86
86
  "typescript": "^5.9.2"
87
87
  },
88
88
  "peerDependencies": {
89
- "@onekeyfe/react-native-image": "6.7.0-4",
90
- "@onekeyfe/react-native-native-logger": "6.7.0-4",
89
+ "@onekeyfe/react-native-image": "6.7.0-5",
90
+ "@onekeyfe/react-native-native-logger": "6.7.0-5",
91
91
  "react": "*",
92
92
  "react-native": "*",
93
93
  "react-native-nitro-modules": "0.37.0"
@@ -179,6 +179,14 @@ type HistoryViews = {
179
179
  actions: HTMLElement;
180
180
  actionButtons: Map<string, HTMLButtonElement>;
181
181
  visualKey: string;
182
+ visuals: {
183
+ node: HTMLElement;
184
+ style: RowVisualStyle;
185
+ background: string;
186
+ loaded: boolean;
187
+ fallback?: HTMLElement;
188
+ fallbackStyle?: RowVisualStyle;
189
+ }[];
182
190
  primitives: RowPrimitives;
183
191
  };
184
192
  const histories = new WeakMap<HTMLElement, HistoryViews>();
@@ -255,6 +263,7 @@ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
255
263
  actions,
256
264
  actionButtons: new Map(),
257
265
  visualKey: '',
266
+ visuals: [],
258
267
  primitives,
259
268
  };
260
269
  histories.set(body, v);
@@ -400,98 +409,156 @@ function bindHistory(
400
409
  primitives.dispose(n as HTMLElement)
401
410
  );
402
411
  v.visual.replaceChildren();
412
+ v.visuals = [];
403
413
  const sources = [row.leading, row.secondaryLeading].filter(Boolean);
404
- sources.forEach((source, index) => {
414
+ sources.forEach((source) => {
405
415
  const visual = primitives.visual(source);
406
416
  if (!visual) return;
407
- const size = sources.length > 1 ? (index ? 28 : 24) : 40;
408
- new RowVisualStyle(visual).apply(row.style?.image, size, size, 0);
409
- Object.assign(visual.style, {
410
- display: 'inline-flex',
411
- alignItems: 'center',
412
- justifyContent: 'center',
413
- });
414
- if (sources.length > 1)
415
- Object.assign(visual.style, {
416
- position: 'absolute',
417
- left: index ? '12px' : '0',
418
- top: index ? '12px' : '0',
419
- border: index ? '2px solid var(--nl-row)' : '0',
420
- boxSizing: 'border-box',
421
- });
422
417
  historyIcon(visual, source, table || sources.length > 1 ? 24 : 28);
423
- if (!table && sources.length > 1) {
424
- const token = visual.ownerDocument.createElement('span');
425
- Object.assign(token.style, {
426
- display: 'flex',
427
- alignItems: 'center',
428
- justifyContent: 'center',
429
- position: 'relative',
430
- width: '24px',
431
- height: '24px',
432
- flex: '0 0 24px',
433
- borderRadius: 'inherit',
434
- boxSizing: 'border-box',
435
- overflow: 'hidden',
436
- background:
437
- source && 'backgroundColor' in source
438
- ? source.backgroundColor ?? ''
439
- : '',
440
- border:
441
- source && 'borderColor' in source && source.borderColor
442
- ? `1px solid ${source.borderColor}`
443
- : '0',
444
- });
445
- token.append(
446
- ...Array.from(visual.children).filter(
447
- (child) => !child.classList.contains('ok-native-list-visual-corner')
448
- )
449
- );
450
- const fallback = token.querySelector<HTMLElement>(
451
- ':scope > .ok-native-list-visual-fallback'
452
- );
453
- if (fallback) {
454
- fallback.style.width = '24px';
455
- fallback.style.height = '24px';
456
- fallback.style.flexShrink = '0';
457
- }
458
- const mainImage = token.querySelector<HTMLImageElement>(
459
- ':scope > .ok-native-list-visual-main'
460
- );
461
- if (mainImage) {
462
- mainImage.style.width = '100%';
463
- mainImage.style.height = '100%';
464
- }
465
- visual.append(token);
466
- }
467
- if (table) {
468
- visual.style.background =
469
- source && 'backgroundColor' in source && source.backgroundColor
470
- ? source.backgroundColor
471
- : 'var(--nl-strong)';
472
- const borderColor =
473
- source && 'borderColor' in source && source.borderColor
474
- ? source.borderColor
475
- : 'var(--nl-separator)';
476
- visual.style.border = `1px solid ${borderColor}`;
477
- visual.style.boxSizing = 'border-box';
478
- } else if (sources.length === 1 && source?.kind === 'token') {
479
- visual.style.border = source.borderColor
480
- ? `1px solid ${source.borderColor}`
481
- : '0';
482
- visual.style.boxSizing = 'border-box';
483
- const mainImage = visual.querySelector<HTMLImageElement>(
484
- ':scope > .ok-native-list-visual-main'
485
- );
486
- if (mainImage) {
487
- mainImage.style.width = '100%';
488
- mainImage.style.height = '100%';
489
- }
418
+ const retained = {
419
+ node: visual,
420
+ style: new RowVisualStyle(visual),
421
+ background: visual.style.background,
422
+ loaded: false,
423
+ };
424
+ // Only placeholder-backed sources restore their frame background on load.
425
+ const image = source && 'image' in source ? source.image : undefined;
426
+ if (image?.loadingStrategy && image.loadingStrategy !== 'none') {
427
+ visual
428
+ .querySelector('.ok-native-list-visual-main')
429
+ ?.addEventListener('load', () => {
430
+ retained.background =
431
+ source && 'backgroundColor' in source && source.backgroundColor
432
+ ? source.backgroundColor
433
+ : 'transparent';
434
+ retained.loaded = true;
435
+ });
490
436
  }
437
+ v.visuals.push(retained);
491
438
  v.visual.append(visual);
492
439
  });
493
440
  v.visualKey = visualKey;
494
441
  }
442
+ const sources = [row.leading, row.secondaryLeading].filter(Boolean);
443
+ v.visuals.forEach((retained, index) => {
444
+ const { node: visual, style, background, loaded } = retained;
445
+ const source = sources[index];
446
+ const previousToken = visual.querySelector<HTMLElement>(
447
+ ':scope > .ok-native-list-history-token'
448
+ );
449
+ if (previousToken) {
450
+ visual.append(...Array.from(previousToken.children));
451
+ previousToken.remove();
452
+ }
453
+ const currentFallback = visual.querySelector<HTMLElement>(
454
+ ':scope > .ok-native-list-visual-fallback:not(.ok-native-list-visual-corner)'
455
+ );
456
+ if (currentFallback && retained.fallback !== currentFallback) {
457
+ retained.fallback = currentFallback;
458
+ retained.fallbackStyle = new RowVisualStyle(currentFallback);
459
+ }
460
+ // A terminal image error creates a new fallback node after the factory bind.
461
+ retained.fallbackStyle?.restore();
462
+ const size = sources.length > 1 ? (index ? 28 : 24) : 40;
463
+ style.apply(row.style?.image, size, size, 0);
464
+ Object.assign(visual.style, {
465
+ background,
466
+ position: '',
467
+ left: '',
468
+ top: '',
469
+ });
470
+ const svg = visual.querySelector<SVGElement>(
471
+ '.ok-native-list-visual-fallback > svg'
472
+ );
473
+ if (svg) {
474
+ const iconSize = String(table || sources.length > 1 ? 24 : 28);
475
+ svg.setAttribute('width', iconSize);
476
+ svg.setAttribute('height', iconSize);
477
+ }
478
+ Object.assign(visual.style, {
479
+ display: 'inline-flex',
480
+ alignItems: 'center',
481
+ justifyContent: 'center',
482
+ });
483
+ if (sources.length > 1)
484
+ Object.assign(visual.style, {
485
+ position: 'absolute',
486
+ left: index ? '12px' : '0',
487
+ top: index ? '12px' : '0',
488
+ border: index ? '2px solid var(--nl-row)' : '0',
489
+ boxSizing: 'border-box',
490
+ });
491
+ if (!table && sources.length > 1) {
492
+ const token = visual.ownerDocument.createElement('span');
493
+ token.className = 'ok-native-list-history-token';
494
+ Object.assign(token.style, {
495
+ display: 'flex',
496
+ alignItems: 'center',
497
+ justifyContent: 'center',
498
+ position: 'relative',
499
+ width: '24px',
500
+ height: '24px',
501
+ flex: '0 0 24px',
502
+ borderRadius: 'inherit',
503
+ boxSizing: 'border-box',
504
+ overflow: 'hidden',
505
+ background:
506
+ source && 'backgroundColor' in source
507
+ ? source.backgroundColor ?? ''
508
+ : '',
509
+ border:
510
+ source && 'borderColor' in source && source.borderColor
511
+ ? `1px solid ${source.borderColor}`
512
+ : '0',
513
+ });
514
+ token.append(
515
+ ...Array.from(visual.children).filter(
516
+ (child) => !child.classList.contains('ok-native-list-visual-corner')
517
+ )
518
+ );
519
+ const fallback = token.querySelector<HTMLElement>(
520
+ ':scope > .ok-native-list-visual-fallback'
521
+ );
522
+ if (fallback) {
523
+ fallback.style.width = '24px';
524
+ fallback.style.height = '24px';
525
+ fallback.style.flexShrink = '0';
526
+ }
527
+ const mainImage = token.querySelector<HTMLImageElement>(
528
+ ':scope > .ok-native-list-visual-main'
529
+ );
530
+ if (mainImage) {
531
+ mainImage.style.width = '100%';
532
+ mainImage.style.height = '100%';
533
+ }
534
+ visual.append(token);
535
+ }
536
+ if (table) {
537
+ visual.style.background = loaded
538
+ ? background
539
+ : source && 'backgroundColor' in source && source.backgroundColor
540
+ ? source.backgroundColor
541
+ : 'var(--nl-strong)';
542
+ const borderColor =
543
+ source && 'borderColor' in source && source.borderColor
544
+ ? source.borderColor
545
+ : 'var(--nl-separator)';
546
+ visual.style.border = `1px solid ${borderColor}`;
547
+ visual.style.boxSizing = 'border-box';
548
+ } else if (sources.length === 1 && source?.kind === 'token') {
549
+ visual.style.border = source.borderColor
550
+ ? `1px solid ${source.borderColor}`
551
+ : '0';
552
+ visual.style.boxSizing = 'border-box';
553
+ const mainImage = visual.querySelector<HTMLImageElement>(
554
+ ':scope > .ok-native-list-visual-main'
555
+ );
556
+ if (mainImage) {
557
+ mainImage.style.width = '100%';
558
+ mainImage.style.height = '100%';
559
+ }
560
+ }
561
+ });
495
562
  Object.assign(v.text.style, {
496
563
  minWidth: '0',
497
564
  flex: '1 1 auto',