@onekeyfe/react-native-pager-view 6.7.0-alpha.475 → 6.8.0-3

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.
@@ -1,4 +1,5 @@
1
1
  #import <XCTest/XCTest.h>
2
+ #import <objc/runtime.h>
2
3
  #import "RNCCollapsiblePagerViewComponentView.h"
3
4
  #import "RNCNativeScrollerComponentView.h"
4
5
  #import <React/RCTScrollViewComponentView.h>
@@ -57,6 +58,30 @@ using namespace facebook::react;
57
58
 
58
59
  @implementation RNCCollapsiblePagerFirstFrameTests
59
60
 
61
+ - (void)testFreshZeroGeometryAlignsOffsetBeforePendingRestoreCompletes
62
+ {
63
+ RNCCollapsiblePagerViewComponentView *pager = [RNCCollapsiblePagerViewComponentView new];
64
+ auto props = std::make_shared<RNCCollapsiblePagerViewProps>();
65
+ props->nativeSmoothHeaderScrollEnabled = true;
66
+ props->headerHeight = 120;
67
+ props->stickyHeaderHeight = 44;
68
+ props->pageKeys = "[\"fresh\"]";
69
+ [pager updateProps:props oldProps:nullptr];
70
+ UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
71
+ [pager applyInsetsToScrollView:scroll pageIndex:0 restore:YES];
72
+ XCTAssertEqualWithAccuracy(scroll.contentInset.top, 164, 0.01);
73
+ XCTAssertEqualWithAccuracy(scroll.contentOffset.y, -164, 0.01);
74
+ XCTAssertEqualWithAccuracy(scroll.contentOffset.y + scroll.contentInset.top, 0, 0.01);
75
+ XCTAssertTrue([[pager valueForKey:@"pendingPageRestoreKeys"] containsObject:@"fresh"]);
76
+
77
+ scroll.frame = CGRectMake(0, 0, 320, 600);
78
+ scroll.contentSize = CGSizeMake(320, 900);
79
+ [pager applyInsetsToScrollView:scroll pageIndex:0 restore:YES];
80
+ XCTAssertEqualWithAccuracy(scroll.contentOffset.y, -164, 0.01);
81
+ XCTAssertFalse([[pager valueForKey:@"pendingPageRestoreKeys"] containsObject:@"fresh"]);
82
+ [pager prepareForRecycle];
83
+ }
84
+
60
85
  - (void)testInactivePagesPrepareTheirOwnStickyInsetsBeforeSelection
61
86
  {
62
87
  RNCCollapsiblePagerViewComponentView *pager = [RNCCollapsiblePagerViewComponentView new];
@@ -574,11 +599,19 @@ using namespace facebook::react;
574
599
  [pager mountingTransactionWillMount:removal withSurfaceTelemetry:telemetry];
575
600
  [source removeFromSuperview];
576
601
  [self finishMount:pager];
577
- NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:3];
578
- while (([[pager valueForKey:@"scrollResolveRetryAttempt"] integerValue] < 12 ||
579
- (!finalRetryPending && [[pager valueForKey:@"scrollResolveRetryScheduled"] boolValue])) &&
580
- deadline.timeIntervalSinceNow > 0) {
581
- [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
602
+ if (finalRetryPending) {
603
+ NSUInteger staleToken = [[pager valueForKey:@"scrollResolveRetryToken"] unsignedIntegerValue];
604
+ [pager setValue:@(staleToken + 1) forKey:@"scrollResolveRetryToken"];
605
+ [pager setValue:@NO forKey:@"scrollResolveRetryScheduled"];
606
+ [pager setValue:@11 forKey:@"scrollResolveRetryAttempt"];
607
+ [pager attachScrollObserverForCurrentPage];
608
+ } else {
609
+ NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:6];
610
+ while (([[pager valueForKey:@"scrollResolveRetryAttempt"] integerValue] < 12 ||
611
+ [[pager valueForKey:@"scrollResolveRetryScheduled"] boolValue]) &&
612
+ deadline.timeIntervalSinceNow > 0) {
613
+ [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
614
+ }
582
615
  }
583
616
  XCTAssertEqualObjects([pager valueForKey:@"scrollResolveRetryAttempt"], @12);
584
617
  XCTAssertEqualObjects([pager valueForKey:@"scrollResolveRetryScheduled"], @(finalRetryPending));
@@ -873,6 +906,87 @@ using namespace facebook::react;
873
906
  return component;
874
907
  }
875
908
 
909
+ - (void)testUnmeasuredNativeListAttachesAndAlignsSynchronouslyOnFirstLayoutReadiness
910
+ {
911
+ RNCCollapsiblePagerViewComponentView *pager = [self pagerWithPageCount:1];
912
+ [pager setValue:@YES forKey:@"hasAppliedInitialPage"];
913
+ [pager setValue:@293 forKey:@"headerHeight"];
914
+ [pager setValue:@52 forKey:@"stickyHeaderHeight"];
915
+ Class nativeListClass = NSClassFromString(@"HybridNativeListComponent");
916
+ XCTAssertNotNil(nativeListClass, @"The real NativeList test dependency must be linked");
917
+ UIViewController *page = [pager valueForKey:@"pageControllers"][0];
918
+
919
+ RCTViewComponentView *horizontalComponent = [[nativeListClass alloc] init];
920
+ horizontalComponent.tag = 92002;
921
+ horizontalComponent.frame = CGRectZero;
922
+ horizontalComponent.contentView.frame = CGRectZero;
923
+ [page.view addSubview:horizontalComponent];
924
+
925
+ RCTViewComponentView *component = [[nativeListClass alloc] init];
926
+ component.tag = 92003;
927
+ component.frame = CGRectZero;
928
+ component.contentView.frame = CGRectZero;
929
+ [page.view addSubview:component];
930
+ [self addTeardownBlock:^{
931
+ [horizontalComponent prepareForRecycle];
932
+ [horizontalComponent removeFromSuperview];
933
+ [component prepareForRecycle];
934
+ [component removeFromSuperview];
935
+ }];
936
+
937
+ UICollectionView *horizontalList = nil;
938
+ for (UIView *child in horizontalComponent.contentView.subviews) {
939
+ if ([child isKindOfClass:UICollectionView.class]) {
940
+ horizontalList = (UICollectionView *)child;
941
+ break;
942
+ }
943
+ }
944
+ XCTAssertNotNil(horizontalList);
945
+ UICollectionViewFlowLayout *horizontalLayout =
946
+ (UICollectionViewFlowLayout *)horizontalList.collectionViewLayout;
947
+ horizontalLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
948
+ horizontalList.alwaysBounceVertical = NO;
949
+ horizontalList.alwaysBounceHorizontal = YES;
950
+
951
+ [pager setNeedsLayout];
952
+ [pager layoutIfNeeded];
953
+ XCTAssertNil([pager valueForKey:@"observedScrollView"]);
954
+ XCTAssertFalse([[pager valueForKey:@"awaitingScrollOwnerForCurrentPage"] boolValue]);
955
+ XCTAssertTrue([[pager valueForKey:@"scrollReconcileScheduled"] boolValue]);
956
+
957
+ horizontalComponent.frame = CGRectMake(0, 0, 390, 120);
958
+ horizontalComponent.contentView.frame = horizontalComponent.bounds;
959
+ [horizontalComponent.contentView layoutIfNeeded];
960
+ [[NSNotificationCenter defaultCenter]
961
+ postNotificationName:@"OneKeyNativeScrollViewDidBecomeReady"
962
+ object:horizontalList];
963
+ XCTAssertNil([pager valueForKey:@"observedScrollView"]);
964
+ XCTAssertEqualWithAccuracy(horizontalList.contentInset.top, 0, 0.01);
965
+ XCTAssertEqualWithAccuracy(horizontalList.contentOffset.y, 0, 0.01);
966
+ XCTAssertFalse(horizontalList.alwaysBounceVertical);
967
+
968
+ UICollectionView *list = nil;
969
+ for (UIView *child in component.contentView.subviews) {
970
+ if ([child isKindOfClass:UICollectionView.class]) {
971
+ list = (UICollectionView *)child;
972
+ break;
973
+ }
974
+ }
975
+ XCTAssertNotNil(list);
976
+ XCTAssertEqualWithAccuracy(list.contentInset.top, 0, 0.01);
977
+ XCTAssertEqualWithAccuracy(list.contentOffset.y, 0, 0.01);
978
+
979
+ component.frame = CGRectMake(0, 0, 390, 697);
980
+ component.contentView.frame = component.bounds;
981
+ [component.contentView layoutIfNeeded];
982
+
983
+ UIView *header = [pager valueForKey:@"sharedHeaderHostView"];
984
+ XCTAssertEqual([pager valueForKey:@"observedScrollView"], list);
985
+ XCTAssertEqual(header.superview, list);
986
+ XCTAssertEqualWithAccuracy(list.contentInset.top, 345, 0.01);
987
+ XCTAssertEqualWithAccuracy(list.contentOffset.y, -345, 0.01);
988
+ }
989
+
876
990
  - (void)testNativeListFooterScrollViewCannotReplacePageOwner
877
991
  {
878
992
  RNCCollapsiblePagerViewComponentView *pager = [self pagerWithPageCount:1];
@@ -922,6 +1036,53 @@ using namespace facebook::react;
922
1036
  XCTAssertEqualWithAccuracy(footerList.scrollView.contentInset.top, 0, 0.01);
923
1037
  }
924
1038
 
1039
+ // Overlay content (popover, sheet) stays mounted inside its host view until
1040
+ // the overlay window presents it, and the host can sit beside the page's list.
1041
+ // As a Fabric scroll view its scroller outranks the native list, so the pager
1042
+ // used to adopt it and apply the collapsed-header offset to it: the sheet then
1043
+ // opened scrolled past its content (OK-67220).
1044
+ - (void)testStagedOverlayScrollViewCannotReplacePageOwner
1045
+ {
1046
+ RNCCollapsiblePagerViewComponentView *pager = [self pagerWithPageCount:1];
1047
+ RCTViewComponentView *component = [self addNativeListToPager:pager];
1048
+ UICollectionView *list = nil;
1049
+ for (UIView *child in component.contentView.subviews) {
1050
+ if ([child isKindOfClass:UICollectionView.class]) {
1051
+ list = (UICollectionView *)child;
1052
+ break;
1053
+ }
1054
+ }
1055
+ XCTAssertNotNil(list);
1056
+ XCTAssertEqual([pager verticalScrollViewForPageAtIndex:0], list);
1057
+
1058
+ // The overlay package is not linked into this target; stand in for its host.
1059
+ Class overlayHostClass = NSClassFromString(@"RCTNativeOverlayComponentView");
1060
+ if (overlayHostClass == Nil) {
1061
+ overlayHostClass = objc_allocateClassPair(UIView.class, "RCTNativeOverlayComponentView", 0);
1062
+ objc_registerClassPair(overlayHostClass);
1063
+ }
1064
+ UIView *overlayHost = [overlayHostClass new];
1065
+ RCTScrollViewComponentView *sheetScroller = [RCTScrollViewComponentView new];
1066
+ sheetScroller.frame = CGRectMake(0, 0, 320, 60);
1067
+ sheetScroller.scrollView.frame = sheetScroller.bounds;
1068
+ sheetScroller.scrollView.contentSize = CGSizeMake(320, 60);
1069
+ sheetScroller.scrollView.alwaysBounceHorizontal = NO;
1070
+ [overlayHost addSubview:sheetScroller];
1071
+ UIViewController *page = [pager valueForKey:@"pageControllers"][0];
1072
+ [page.view addSubview:overlayHost];
1073
+
1074
+ XCTAssertEqual([pager verticalScrollViewForPageAtIndex:0], list);
1075
+ XCTAssertNil([pager findVerticalScrollViewInView:overlayHost]);
1076
+ [pager attachScrollObserverForCurrentPage];
1077
+ XCTAssertEqual([pager valueForKey:@"observedScrollView"], list);
1078
+ XCTAssertEqualWithAccuracy(sheetScroller.scrollView.contentOffset.y, 0, 0.01);
1079
+
1080
+ // The same scroll view outside an overlay host is still a page scroller.
1081
+ [sheetScroller removeFromSuperview];
1082
+ [page.view addSubview:sheetScroller];
1083
+ XCTAssertEqual([pager verticalScrollViewForPageAtIndex:0], sheetScroller.scrollView);
1084
+ }
1085
+
925
1086
  - (void)testExplicitScrollerSiblingStillPrecedesNativeList
926
1087
  {
927
1088
  RNCCollapsiblePagerViewComponentView *pager = [self pagerWithPageCount:1];
@@ -305,7 +305,12 @@ export class CollapsiblePagerView extends React.PureComponent {
305
305
  return keys;
306
306
  })(),
307
307
  toolbar: nativeToolbar(nativeTabBar.toolbar),
308
- activeFontFamily: nativeTabBar.style?.activeFontFamily
308
+ activeFontFamily: nativeTabBar.style?.activeFontFamily,
309
+ itemPaddingHorizontal: nativeTabBar.style?.itemPaddingHorizontal,
310
+ itemHoverBackgroundColor: nativeTabBar.style?.itemHoverBackgroundColor === undefined ? undefined : processColor(nativeTabBar.style.itemHoverBackgroundColor),
311
+ itemPressedBackgroundColor: nativeTabBar.style?.itemPressedBackgroundColor === undefined ? undefined : processColor(nativeTabBar.style.itemPressedBackgroundColor),
312
+ contentMaxWidth: nativeTabBar.style?.contentMaxWidth,
313
+ indicatorAnimationEnabled: nativeTabBar.style?.indicatorAnimationEnabled
309
314
  }) : undefined,
310
315
  onNativeToolbarPress: this.onNativeToolbarPress,
311
316
  nativeTabBarItems: nativeTabBarEnabled ? JSON.stringify(nativeTabBar.items) : undefined,
@@ -53,6 +53,9 @@ export class CollapsiblePagerView extends React.PureComponent {
53
53
  tabProgressFrame = null;
54
54
  tabProgressGeneration = 0;
55
55
  tabButtons = new Map();
56
+ tabList = null;
57
+ tabButtonRefs = new Map();
58
+ tabPill = null;
56
59
  headerSlot = null;
57
60
  stickySlot = null;
58
61
  cssTimelineSupported = false;
@@ -231,6 +234,8 @@ export class CollapsiblePagerView extends React.PureComponent {
231
234
  if (this.root) this.chromeObserver.observe(this.root);
232
235
  if (this.headerContent) this.chromeObserver.observe(this.headerContent);
233
236
  if (this.stickyContent) this.chromeObserver.observe(this.stickyContent);
237
+ if (this.tabList) this.chromeObserver.observe(this.tabList);
238
+ for (const button of this.tabButtons.values()) this.chromeObserver.observe(button);
234
239
  this.scheduleChromeMeasurement();
235
240
  }
236
241
  scheduleChromeMeasurement = () => {
@@ -539,7 +544,10 @@ export class CollapsiblePagerView extends React.PureComponent {
539
544
  }
540
545
  tabColorWeights() {
541
546
  const config = this.props.nativeTabBar;
542
- if (!config?.controlled || config.style?.variant !== "text" || this.tabProgress === null) return null;
547
+ const variant = config?.style?.variant;
548
+ if (!config?.controlled || variant !== "text" && variant !== "pill" || this.tabProgress === null) return null;
549
+ // A pill that does not animate also snaps label colors to the selection.
550
+ if (variant === "pill" && config.style?.indicatorAnimationEnabled === false) return null;
543
551
  const keys = [];
544
552
  React.Children.forEach(this.props.children, child => {
545
553
  if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
@@ -590,6 +598,79 @@ export class CollapsiblePagerView extends React.PureComponent {
590
598
  if (label) label.style.fontFamily = fontFamily;
591
599
  } else button.style.fontFamily = fontFamily;
592
600
  }
601
+ this.syncTabPill(weights, selectedKey);
602
+ }
603
+
604
+ // Positions the pill from the live button boxes on every sync. Nothing is
605
+ // cached per index, so a tab that only moved (same size, new position) still
606
+ // gets its own width and offset.
607
+ syncTabPill(weights, selectedKey) {
608
+ const pill = this.tabPill;
609
+ if (!pill) return;
610
+ let fromKey = selectedKey;
611
+ let toKey = selectedKey;
612
+ let fraction = 0;
613
+ if (weights && this.tabProgress !== null) {
614
+ const keys = Array.from(weights.keys());
615
+ const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
616
+ const source = Math.floor(progress);
617
+ fromKey = keys[source];
618
+ toKey = keys[Math.min(source + 1, keys.length - 1)];
619
+ fraction = progress - source;
620
+ }
621
+ const from = fromKey === undefined ? undefined : this.tabButtons.get(fromKey);
622
+ const to = toKey === undefined ? undefined : this.tabButtons.get(toKey);
623
+ if (!from || !to || !from.isConnected || !to.isConnected || from.offsetWidth <= 0) {
624
+ pill.style.visibility = "hidden";
625
+ pill.removeAttribute("data-placed");
626
+ return;
627
+ }
628
+ // Leading edge leads, trailing edge lags, like the JS pill this replaces.
629
+ const leading = 1 - (1 - fraction) * (1 - fraction);
630
+ const trailing = fraction * fraction;
631
+ const forward = to.offsetLeft >= from.offsetLeft;
632
+ const leftFraction = forward ? trailing : leading;
633
+ const rightFraction = forward ? leading : trailing;
634
+ const fromRight = from.offsetLeft + from.offsetWidth;
635
+ const toRight = to.offsetLeft + to.offsetWidth;
636
+ const left = from.offsetLeft + (to.offsetLeft - from.offsetLeft) * leftFraction;
637
+ const right = fromRight + (toRight - fromRight) * rightFraction;
638
+ const animationEnabled = this.props.nativeTabBar?.style?.indicatorAnimationEnabled !== false;
639
+ const animate = animationEnabled && pill.hasAttribute("data-placed") && this.tabProgressFrame === null && fraction === 0;
640
+ pill.style.transition = animate ? "transform 220ms cubic-bezier(0.2, 0, 0, 1), width 220ms cubic-bezier(0.2, 0, 0, 1)" : "none";
641
+ pill.style.top = `${from.offsetTop}px`;
642
+ pill.style.height = `${from.offsetHeight}px`;
643
+ pill.style.width = `${Math.max(0, right - left)}px`;
644
+ pill.style.transform = `translateX(${left}px)`;
645
+ pill.style.visibility = "visible";
646
+ pill.setAttribute("data-placed", "");
647
+ }
648
+ setTabList = node => {
649
+ if (node === this.tabList) return;
650
+ if (this.tabList) this.chromeObserver?.unobserve(this.tabList);
651
+ this.tabList = node;
652
+ if (node) this.chromeObserver?.observe(node);
653
+ };
654
+ setTabPill = node => {
655
+ this.tabPill = node;
656
+ if (node) this.syncTabColors();
657
+ };
658
+ tabButtonRef(key) {
659
+ let ref = this.tabButtonRefs.get(key);
660
+ if (!ref) {
661
+ ref = button => this.setTabButton(key, button);
662
+ this.tabButtonRefs.set(key, ref);
663
+ }
664
+ return ref;
665
+ }
666
+ setTabButton(key, button) {
667
+ const previous = this.tabButtons.get(key);
668
+ if (previous === button) return;
669
+ if (previous) this.chromeObserver?.unobserve(previous);
670
+ if (button) {
671
+ this.tabButtons.set(key, button);
672
+ this.chromeObserver?.observe(button);
673
+ } else this.tabButtons.delete(key);
593
674
  }
594
675
  pageScrollElement(index) {
595
676
  const pageHost = this.pageHosts.get(index);
@@ -1269,30 +1350,71 @@ export class CollapsiblePagerView extends React.PureComponent {
1269
1350
  return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
1270
1351
  }));
1271
1352
  const segmented = variant === "segmented";
1353
+ const pill = variant === "pill";
1272
1354
  const reserveTextFaces = config.controlled && variant === "text";
1355
+ const itemPadding = style?.itemPaddingHorizontal ?? (variant === "text" ? 10 : pill ? 14 : 8);
1356
+ const cssColor = value => value === undefined ? "transparent" : String(value);
1357
+ for (const key of this.tabButtonRefs.keys()) {
1358
+ if (!config.items.some(item => item.key === key)) this.tabButtonRefs.delete(key);
1359
+ }
1273
1360
  const colorWeights = this.tabColorWeights();
1274
1361
  const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
1275
1362
  return /*#__PURE__*/React.createElement("div", {
1276
1363
  className: "ok-pager-tab-bar",
1277
1364
  dir: this.props.layoutDirection === "rtl" || (this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL ? "rtl" : "ltr",
1365
+ "data-variant": variant,
1278
1366
  style: {
1279
1367
  display: "flex",
1280
1368
  alignItems: "center",
1281
1369
  position: "relative",
1282
1370
  height: style?.height ?? 44,
1283
1371
  backgroundColor: String(style?.backgroundColor ?? "transparent"),
1284
- minWidth: 0
1372
+ minWidth: 0,
1373
+ ["--pager-tab-hover"]: cssColor(style?.itemHoverBackgroundColor),
1374
+ ["--pager-tab-pressed"]: cssColor(style?.itemPressedBackgroundColor)
1285
1375
  }
1286
- }, /*#__PURE__*/React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`), /*#__PURE__*/React.createElement("div", {
1376
+ }, /*#__PURE__*/React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab{position:relative;z-index:1;border-radius:999px}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:hover{background:var(--pager-tab-hover)}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:active{background:var(--pager-tab-pressed)}.ok-pager-tablist{scrollbar-width:none}.ok-pager-tablist::-webkit-scrollbar{display:none}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`), /*#__PURE__*/React.createElement("div", {
1377
+ className: "ok-pager-tab-row",
1378
+ style: {
1379
+ display: "flex",
1380
+ alignItems: "center",
1381
+ height: "100%",
1382
+ flex: 1,
1383
+ minWidth: 0,
1384
+ maxWidth: style?.contentMaxWidth,
1385
+ margin: style?.contentMaxWidth === undefined ? undefined : "0 auto"
1386
+ }
1387
+ }, /*#__PURE__*/React.createElement("div", {
1287
1388
  role: "tablist",
1389
+ className: "ok-pager-tablist",
1390
+ ref: this.setTabList,
1288
1391
  style: {
1289
1392
  display: "flex",
1290
1393
  overflowX: segmented ? "hidden" : "auto",
1291
1394
  flex: 1,
1395
+ position: "relative",
1396
+ alignItems: "center",
1292
1397
  padding: `${style?.contentPaddingVertical ?? 0}px ${style?.contentPaddingHorizontal ?? 20}px`,
1293
1398
  gap: style?.itemSpacing ?? 8
1294
1399
  }
1295
- }, ...config.items.map((item, position) => {
1400
+ }, pill ? /*#__PURE__*/React.createElement("div", {
1401
+ key: "ok-pager-tab-pill",
1402
+ ref: this.setTabPill,
1403
+ className: "ok-pager-tab-pill",
1404
+ "aria-hidden": true,
1405
+ style: {
1406
+ position: "absolute",
1407
+ left: 0,
1408
+ top: 0,
1409
+ width: 0,
1410
+ height: 0,
1411
+ borderRadius: 999,
1412
+ pointerEvents: "none",
1413
+ visibility: "hidden",
1414
+ backgroundColor: String(style?.indicatorColor ?? "#000000"),
1415
+ willChange: "transform, width"
1416
+ }
1417
+ }) : null, ...config.items.map((item, position) => {
1296
1418
  const selected = item.key === selectedKey;
1297
1419
  const fontSelected = item.key === fontOwnerKey;
1298
1420
  return /*#__PURE__*/React.createElement("button", {
@@ -1301,13 +1423,11 @@ export class CollapsiblePagerView extends React.PureComponent {
1301
1423
  type: "button",
1302
1424
  className: "ok-pager-tab",
1303
1425
  "aria-selected": selected,
1304
- ref: button => {
1305
- if (button) this.tabButtons.set(item.key, button);else this.tabButtons.delete(item.key);
1306
- },
1426
+ ref: this.tabButtonRef(item.key),
1307
1427
  "aria-label": item.accessibilityLabel ?? item.title,
1308
1428
  "data-testid": item.testID,
1309
1429
  style: {
1310
- padding: variant === "text" ? "6px 10px" : "6px 8px",
1430
+ padding: `6px ${itemPadding}px`,
1311
1431
  minWidth: 44,
1312
1432
  height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
1313
1433
  fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
@@ -1318,8 +1438,9 @@ export class CollapsiblePagerView extends React.PureComponent {
1318
1438
  alignItems: reserveTextFaces ? "center" : undefined,
1319
1439
  color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
1320
1440
  flex: segmented ? 1 : undefined,
1321
- borderRadius: segmented ? 999 : 0,
1322
- backgroundColor: segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
1441
+ borderRadius: segmented || pill ? 999 : 0,
1442
+ // Pill items leave the background to CSS so hover / pressed apply.
1443
+ backgroundColor: pill ? undefined : segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
1323
1444
  borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined
1324
1445
  },
1325
1446
  onClick: () => {
@@ -1362,7 +1483,7 @@ export class CollapsiblePagerView extends React.PureComponent {
1362
1483
  height: "100%",
1363
1484
  position: "relative"
1364
1485
  }
1365
- }) : null);
1486
+ }) : null));
1366
1487
  }
1367
1488
  render() {
1368
1489
  const {
@@ -16,7 +16,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
16
16
  testID?: string;
17
17
  }>;
18
18
  export type CollapsiblePagerNativeTabBarStyle = Readonly<{
19
- variant?: "underline" | "segmented" | "text";
19
+ /**
20
+ * `pill` draws a rounded background behind the selected item that follows
21
+ * pager progress, with active / inactive label colors.
22
+ */
23
+ variant?: "underline" | "segmented" | "text" | "pill";
20
24
  height?: number;
21
25
  trailingReservedWidth?: number;
22
26
  contentPaddingHorizontal?: number;
@@ -31,6 +35,22 @@ export type CollapsiblePagerNativeTabBarStyle = Readonly<{
31
35
  indicatorColor?: ReactNative.ColorValue;
32
36
  indicatorHeight?: number;
33
37
  indicatorBottom?: number;
38
+ /** Horizontal padding inside each item. Defaults: text 10, pill 14, others 8. */
39
+ itemPaddingHorizontal?: number;
40
+ /** Pill variant: background of an unselected item under the pointer. */
41
+ itemHoverBackgroundColor?: ReactNative.ColorValue;
42
+ /** Pill variant: background of an unselected item while pressed. */
43
+ itemPressedBackgroundColor?: ReactNative.ColorValue;
44
+ /**
45
+ * Caps the width of the tab row and toolbar and centers them; the bar
46
+ * background still spans the full width.
47
+ */
48
+ contentMaxWidth?: number;
49
+ /**
50
+ * Pill variant: when false, the pill and label colors jump to the selected
51
+ * item instead of following pager progress or animating. Defaults to true.
52
+ */
53
+ indicatorAnimationEnabled?: boolean;
34
54
  }>;
35
55
  export type CollapsiblePagerToolbarItem = Readonly<{
36
56
  iconName: string;
@@ -77,6 +77,9 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
77
77
  private tabProgressFrame;
78
78
  private tabProgressGeneration;
79
79
  private tabButtons;
80
+ private tabList;
81
+ private tabButtonRefs;
82
+ private tabPill;
80
83
  private headerSlot;
81
84
  private stickySlot;
82
85
  private cssTimelineSupported;
@@ -171,6 +174,11 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
171
174
  private tabFontOwnerKey;
172
175
  private tabColor;
173
176
  private syncTabColors;
177
+ private syncTabPill;
178
+ private setTabList;
179
+ private setTabPill;
180
+ private tabButtonRef;
181
+ private setTabButton;
174
182
  private pageScrollElement;
175
183
  private setRoot;
176
184
  private overlayTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-pager-view",
3
- "version": "6.7.0-alpha.475",
3
+ "version": "6.8.0-3",
4
4
  "description": "React Native wrapper for Android and iOS ViewPager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -32,7 +32,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
32
32
  }>;
33
33
 
34
34
  export type CollapsiblePagerNativeTabBarStyle = Readonly<{
35
- variant?: "underline" | "segmented" | "text";
35
+ /**
36
+ * `pill` draws a rounded background behind the selected item that follows
37
+ * pager progress, with active / inactive label colors.
38
+ */
39
+ variant?: "underline" | "segmented" | "text" | "pill";
36
40
  height?: number;
37
41
  trailingReservedWidth?: number;
38
42
  contentPaddingHorizontal?: number;
@@ -47,6 +51,22 @@ export type CollapsiblePagerNativeTabBarStyle = Readonly<{
47
51
  indicatorColor?: ReactNative.ColorValue;
48
52
  indicatorHeight?: number;
49
53
  indicatorBottom?: number;
54
+ /** Horizontal padding inside each item. Defaults: text 10, pill 14, others 8. */
55
+ itemPaddingHorizontal?: number;
56
+ /** Pill variant: background of an unselected item under the pointer. */
57
+ itemHoverBackgroundColor?: ReactNative.ColorValue;
58
+ /** Pill variant: background of an unselected item while pressed. */
59
+ itemPressedBackgroundColor?: ReactNative.ColorValue;
60
+ /**
61
+ * Caps the width of the tab row and toolbar and centers them; the bar
62
+ * background still spans the full width.
63
+ */
64
+ contentMaxWidth?: number;
65
+ /**
66
+ * Pill variant: when false, the pill and label colors jump to the selected
67
+ * item instead of following pager progress or animating. Defaults to true.
68
+ */
69
+ indicatorAnimationEnabled?: boolean;
50
70
  }>;
51
71
 
52
72
  export type CollapsiblePagerToolbarItem = Readonly<{
@@ -709,6 +729,15 @@ export class CollapsiblePagerView extends React.PureComponent<
709
729
  })(),
710
730
  toolbar: nativeToolbar(nativeTabBar.toolbar),
711
731
  activeFontFamily: nativeTabBar.style?.activeFontFamily,
732
+ itemPaddingHorizontal: nativeTabBar.style?.itemPaddingHorizontal,
733
+ itemHoverBackgroundColor: nativeTabBar.style?.itemHoverBackgroundColor === undefined
734
+ ? undefined
735
+ : processColor(nativeTabBar.style.itemHoverBackgroundColor),
736
+ itemPressedBackgroundColor: nativeTabBar.style?.itemPressedBackgroundColor === undefined
737
+ ? undefined
738
+ : processColor(nativeTabBar.style.itemPressedBackgroundColor),
739
+ contentMaxWidth: nativeTabBar.style?.contentMaxWidth,
740
+ indicatorAnimationEnabled: nativeTabBar.style?.indicatorAnimationEnabled,
712
741
  }) : undefined}
713
742
  onNativeToolbarPress={this.onNativeToolbarPress}
714
743
  nativeTabBarItems={