@onekeyfe/react-native-pager-view 6.7.0-6 → 6.7.0-60

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 (49) hide show
  1. package/README.md +159 -115
  2. package/android/build.gradle +1 -0
  3. package/android/src/androidTest/AndroidManifest.xml +7 -0
  4. package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
  5. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +233 -43
  6. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +596 -27
  7. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
  8. package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
  9. package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
  10. package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
  11. package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
  12. package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
  13. package/docs/SPEC.md +716 -10
  14. package/ios/RNCCollapsiblePagerViewComponentView.mm +2246 -97
  15. package/ios/RNCNativeScrollerComponentView.h +2 -0
  16. package/ios/RNCNativeScrollerComponentView.mm +42 -0
  17. package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +723 -1
  18. package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
  19. package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
  20. package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
  21. package/lib/module/CollapsiblePagerView.js +75 -11
  22. package/lib/module/CollapsiblePagerView.web.js +653 -8
  23. package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
  24. package/lib/module/NativeScroller.web.js +3 -0
  25. package/lib/module/NativeScrollerNativeComponent.ts +42 -46
  26. package/lib/module/PagerViewNativeComponent.ts +20 -25
  27. package/lib/module/WebCollapsiblePagerPage.js +7 -2
  28. package/lib/typescript/src/CollapsiblePagerView.d.ts +62 -4
  29. package/lib/typescript/src/CollapsiblePagerView.web.d.ts +56 -2
  30. package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
  31. package/lib/typescript/src/NativeScroller.d.ts +5 -3
  32. package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
  33. package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
  34. package/lib/typescript/src/PagerView.d.ts +1 -1
  35. package/lib/typescript/src/PagerView.web.d.ts +1 -1
  36. package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
  37. package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
  38. package/lib/typescript/src/usePagerView.d.ts +2 -2
  39. package/lib/typescript/src/utils.d.ts +2 -2
  40. package/package.json +20 -7
  41. package/react-native-pager-view.podspec +1 -0
  42. package/src/CollapsiblePagerView.tsx +208 -12
  43. package/src/CollapsiblePagerView.web.tsx +587 -7
  44. package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
  45. package/src/NativeScroller.tsx +14 -4
  46. package/src/NativeScroller.web.tsx +15 -1
  47. package/src/NativeScrollerNativeComponent.ts +42 -46
  48. package/src/PagerViewNativeComponent.ts +20 -25
  49. package/src/WebCollapsiblePagerPage.tsx +7 -2
@@ -14,10 +14,13 @@
14
14
  #import "React/RCTSurfaceTouchHandler.h"
15
15
  #import "React/RCTTouchHandler.h"
16
16
  #import <objc/runtime.h>
17
+ #import <React/RCTConvert.h>
18
+ #import <React/RCTFont.h>
17
19
  #import <UIKit/UIGestureRecognizerSubclass.h>
18
20
 
19
21
  // OneKey patch: deduplicate structural mutation parents before scanning the page.
20
22
  #include <unordered_set>
23
+ #include <cmath>
21
24
 
22
25
  using namespace facebook::react;
23
26
 
@@ -25,6 +28,7 @@ static void *RNCCollapsiblePagerContentOffsetContext = &RNCCollapsiblePagerConte
25
28
  static void *RNCRefreshControlLayerContext = &RNCRefreshControlLayerContext;
26
29
  static void *RNCScrollRefreshControlContext = &RNCScrollRefreshControlContext;
27
30
  static char RNCRefreshControlOffsetKey;
31
+ static void RNCCollapsiblePagerLog(NSString *message);
28
32
 
29
33
  @interface RNCRefreshControlOffsetState : NSObject
30
34
  + (void)setOffset:(CGFloat)offset forControl:(UIRefreshControl *)control owner:(id)owner;
@@ -39,6 +43,10 @@ static char RNCRefreshControlOffsetKey;
39
43
  BOOL _originalMasksToBounds;
40
44
  BOOL _applying;
41
45
  BOOL _observing;
46
+ CGFloat _lastLoggedOffset;
47
+ NSUInteger _lastLoggedOwnerCount;
48
+ CGFloat _lastLoggedTransformY;
49
+ BOOL _hasLoggedState;
42
50
  }
43
51
 
44
52
  - (instancetype)initWithControl:(UIRefreshControl *)control
@@ -79,6 +87,21 @@ static char RNCRefreshControlOffsetKey;
79
87
  }
80
88
  [CATransaction commit];
81
89
  _applying = NO;
90
+ #if DEBUG
91
+ if (!_hasLoggedState || fabs(_lastLoggedOffset - offset) > 0.01 ||
92
+ _lastLoggedOwnerCount != _offsets.count ||
93
+ fabs(_lastLoggedTransformY - transform.m42) > 0.01) {
94
+ _hasLoggedState = YES;
95
+ _lastLoggedOffset = offset;
96
+ _lastLoggedOwnerCount = _offsets.count;
97
+ _lastLoggedTransformY = transform.m42;
98
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
99
+ @"[IOS-HOME-VISUAL] epochMs=%.0f monoMs=%.0f phase=refresh-transform ownerCount=%lu offsetSum=%.1f baselineY=%.1f appliedY=%.1f masksToBounds=%d",
100
+ [NSDate.date timeIntervalSince1970] * 1000, CACurrentMediaTime() * 1000,
101
+ (unsigned long)_offsets.count, offset, _baselineTransform.m42,
102
+ transform.m42, control.layer.masksToBounds]);
103
+ }
104
+ #endif
82
105
  }
83
106
 
84
107
  + (void)setOffset:(CGFloat)offset forControl:(UIRefreshControl *)control owner:(id)owner
@@ -137,6 +160,20 @@ static NSString *const RNCCollapsiblePagerNativeScrollerIDPrefix =
137
160
 
138
161
  static const CFTimeInterval RNCCollapsiblePagerFallbackDebounceInterval = 0.5;
139
162
 
163
+ typedef NS_ENUM(NSInteger, RNCScrollCandidateTier) {
164
+ RNCScrollCandidateTierNone = 0,
165
+ RNCScrollCandidateTierGenericFallback = 1,
166
+ RNCScrollCandidateTierVerifiedNativeList = 2,
167
+ RNCScrollCandidateTierFabricScrollView = 3,
168
+ RNCScrollCandidateTierExplicitScroller = 4,
169
+ };
170
+
171
+ struct RNCScrollCandidateResolution {
172
+ UIScrollView *scrollView = nil;
173
+ RNCScrollCandidateTier tier = RNCScrollCandidateTierNone;
174
+ BOOL hasUnreadyScrollHost = NO;
175
+ };
176
+
140
177
  // OneKey patch: native scroll views can survive a move or be reused for a new
141
178
  // Fabric component. Keep weak identity until their page is attached again.
142
179
  @interface RNCCollapsiblePagerReleasedScrollState : NSObject
@@ -150,6 +187,41 @@ static const CFTimeInterval RNCCollapsiblePagerFallbackDebounceInterval = 0.5;
150
187
  @implementation RNCCollapsiblePagerReleasedScrollState
151
188
  @end
152
189
 
190
+ @interface RNCCollapsiblePagerTransitionEdgeOwner : NSObject
191
+ @property (nonatomic, weak) UIScrollView *scrollView;
192
+ @property (nonatomic, weak) UIView *page;
193
+ @property (nonatomic, strong) UIScrollEdgeEffectStyle *originalStyle;
194
+ @property (nonatomic, strong) UIScrollEdgeElementContainerInteraction *topInteraction;
195
+ @property (nonatomic, strong) UIScrollEdgeElementContainerInteraction *stickyInteraction;
196
+ @property (nonatomic, weak) UIView *topHost;
197
+ @property (nonatomic, weak) UIView *stickyHost;
198
+ @property (nonatomic, strong) UILabel *topMarker;
199
+ @property (nonatomic, strong) UILabel *stickyMarker;
200
+ @property (nonatomic, assign) BOOL borrowsPinnedStickyHost;
201
+ @property (nonatomic, assign) BOOL ownsTransitionHosts;
202
+ @property (nonatomic, strong) UIView *ownedTopHost;
203
+ @property (nonatomic, strong) UIView *ownedStickyHost;
204
+ @property (nonatomic, strong) UIScrollView *standInScrollView;
205
+ @end
206
+
207
+ @implementation RNCCollapsiblePagerTransitionEdgeOwner
208
+ @end
209
+
210
+ // OneKey patch: overlay content (popover, sheet, dialog) stays mounted inside
211
+ // its host view until the overlay window presents it, so a host can sit in a
212
+ // page's subtree. That content is never the page's scroller: adopting its
213
+ // scroll view applies the collapsed-header offset to it, and the sheet then
214
+ // opens scrolled past its content.
215
+ static BOOL RNCIsNativeOverlayHost(UIView *view)
216
+ {
217
+ // Looked up by name: the overlay package is optional here. Main thread only.
218
+ static Class overlayHostClass = Nil;
219
+ if (overlayHostClass == Nil) {
220
+ overlayHostClass = NSClassFromString(@"RCTNativeOverlayComponentView");
221
+ }
222
+ return overlayHostClass != Nil && [view isKindOfClass:overlayHostClass];
223
+ }
224
+
153
225
  static UIView *RNCScrollComponentView(UIScrollView *scrollView)
154
226
  {
155
227
  for (UIView *view = scrollView; view != nil; view = view.superview) {
@@ -344,11 +416,70 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
344
416
  (long)pagerState]);
345
417
  }
346
418
 
419
+ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFloat fallback, CGFloat minimum, CGFloat maximum)
420
+ {
421
+ id value = entry[key];
422
+ if (![value isKindOfClass:NSNumber.class]) return fallback;
423
+ double dimension = [value doubleValue];
424
+ return std::isfinite(dimension) ? MIN(maximum, MAX(minimum, dimension)) : fallback;
425
+ }
426
+
427
+ @protocol RNCPagerNamedSVGBridge <NSObject>
428
+ + (void)cancelWithOwner:(id)owner;
429
+ + (void)requestWithOwner:(id)owner name:(NSString *)name color:(NSString *)color
430
+ width:(NSInteger)width height:(NSInteger)height scale:(double)scale
431
+ complete:(void (^)(UIImage *))complete;
432
+ @end
433
+
434
+ @interface RNCPagerToolbarButton : UIButton
435
+ @property (nonatomic, strong) UIColor *baseColor;
436
+ @property (nonatomic, strong) UIColor *hoverColor;
437
+ @property (nonatomic, strong) UIColor *pressedColor;
438
+ @property (nonatomic) BOOL hovering;
439
+ @property (nonatomic) CGFloat iconSize;
440
+ - (void)refreshBackground;
441
+ @end
442
+ @implementation RNCPagerToolbarButton
443
+ - (instancetype)initWithFrame:(CGRect)frame {
444
+ if ((self = [super initWithFrame:frame])) {
445
+ self.adjustsImageWhenHighlighted = NO;
446
+ [self addGestureRecognizer:[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hover:)]];
447
+ }
448
+ return self;
449
+ }
450
+ - (CGRect)imageRectForContentRect:(CGRect)contentRect {
451
+ CGFloat side = MIN(self.iconSize, MIN(CGRectGetWidth(contentRect), CGRectGetHeight(contentRect)));
452
+ return CGRectMake(CGRectGetMidX(contentRect) - side / 2, CGRectGetMidY(contentRect) - side / 2, side, side);
453
+ }
454
+ - (void)hover:(UIHoverGestureRecognizer *)gesture {
455
+ self.hovering = gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged;
456
+ [self refreshBackground];
457
+ }
458
+ - (void)setEnabled:(BOOL)enabled {
459
+ [super setEnabled:enabled];
460
+ if (!enabled) self.hovering = NO;
461
+ [self refreshBackground];
462
+ }
463
+ - (void)setHighlighted:(BOOL)highlighted {
464
+ [super setHighlighted:highlighted];
465
+ [self refreshBackground];
466
+ }
467
+ - (void)refreshBackground {
468
+ self.backgroundColor = self.enabled && self.highlighted ? self.pressedColor : (self.enabled && self.hovering ? self.hoverColor : self.baseColor);
469
+ }
470
+ @end
471
+
347
472
  @interface RNCCollapsiblePagerNativeTabBarView : UIView <UIScrollViewDelegate>
348
473
  @property (nonatomic, copy) RNCCollapsiblePagerNativeTabPressHandler onTabPress;
474
+ @property (nonatomic, copy) void (^onToolbarPress)(NSString *, CGRect);
475
+ @property (nonatomic, copy) void (^onToolbarNeedsSettlement)(void);
476
+ - (void)updateToolbarPagerIndex:(NSInteger)index busy:(BOOL)busy;
477
+ - (void)updateConfigJSON:(NSString *)json;
349
478
  - (void)updateItemsJSON:(NSString *)itemsJSON;
350
479
  - (void)updateStyleWithHeight:(CGFloat)height
480
+ variant:(NSString *)variant
351
481
  contentPaddingHorizontal:(CGFloat)contentPaddingHorizontal
482
+ contentPaddingVertical:(CGFloat)contentPaddingVertical
352
483
  itemSpacing:(CGFloat)itemSpacing
353
484
  fontSize:(CGFloat)fontSize
354
485
  fontFamily:(NSString *)fontFamily
@@ -359,18 +490,58 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
359
490
  indicatorHeight:(CGFloat)indicatorHeight
360
491
  indicatorBottom:(CGFloat)indicatorBottom;
361
492
  - (void)setProgress:(CGFloat)progress;
493
+ - (BOOL)usesControlledTextProgress;
494
+ - (BOOL)ownsSettledToolbar;
362
495
  - (void)setLeftToRight:(BOOL)leftToRight;
363
496
  - (void)updateAncestorGesturePrecedence;
364
497
  @end
365
498
 
366
499
  @implementation RNCCollapsiblePagerNativeTabBarView {
367
500
  RNCCollapsiblePagerHorizontalScrollView *_scrollView;
501
+ UIView *_trackView;
368
502
  UIView *_indicatorView;
369
503
  NSArray<NSDictionary *> *_items;
370
504
  NSMutableArray<UIButton *> *_buttons;
371
505
  NSMutableArray<NSValue *> *_indicatorFrames;
372
506
  CGFloat _barHeight;
373
507
  CGFloat _contentPaddingHorizontal;
508
+ CGFloat _contentPaddingVertical;
509
+ BOOL _segmented;
510
+ BOOL _textVariant;
511
+ BOOL _pillVariant;
512
+ NSDictionary *_config;
513
+ RNCPagerToolbarButton *_toolbarButton;
514
+ NSString *_toolbarKey;
515
+ BOOL _toolbarPagerBusy;
516
+ NSInteger _toolbarPageIndex;
517
+ NSDictionary *_committedToolbarEntry;
518
+ NSString *_desiredToolbarKey;
519
+ NSDictionary *_desiredToolbarEntry;
520
+ UIImage *_loadedToolbarImage;
521
+ BOOL _toolbarPresenceAnimating;
522
+ BOOL _toolbarPresenceInterrupted;
523
+ NSString *_toolbarTouchKey;
524
+ BOOL _toolbarTouchStarted;
525
+ NSString *_iconIdentity;
526
+ NSObject *_iconOwner;
527
+ NSInteger _progressSource;
528
+ NSInteger _progressDestination;
529
+ CGFloat _progressFraction;
530
+ CGFloat _nativeProgress;
531
+ BOOL _hasNativeProgress;
532
+ BOOL _hasMappedPageProgress;
533
+ CGFloat _toolbarReservedWidth;
534
+ BOOL _toolbarVisible;
535
+ NSUInteger _toolbarAnimationGeneration;
536
+ NSString *_loadedIconIdentity;
537
+ BOOL _iconRequestPending;
538
+ UIImage *_readyToolbarImage;
539
+ NSString *_readyToolbarIdentity;
540
+ NSString *_failedIconIdentity;
541
+ CGFloat _toolbarSize;
542
+ CGFloat _toolbarIconSize;
543
+ CGFloat _toolbarContentWidth;
544
+ CGFloat _toolbarTrailingInset;
374
545
  CGFloat _itemSpacing;
375
546
  CGFloat _fontSize;
376
547
  NSString *_fontFamily;
@@ -389,10 +560,27 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
389
560
  {
390
561
  if (self = [super initWithFrame:frame]) {
391
562
  _items = @[];
563
+ _config = @{};
564
+ _toolbarPagerBusy = YES;
565
+ _toolbarPageIndex = -1;
566
+ _toolbarButton = [RNCPagerToolbarButton new];
567
+ _toolbarButton.layer.cornerRadius = 19;
568
+ _toolbarButton.hidden = YES;
569
+ _toolbarButton.alpha = 0;
570
+ _toolbarButton.userInteractionEnabled = NO;
571
+ _toolbarButton.accessibilityElementsHidden = YES;
572
+ _toolbarButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
573
+ _toolbarButton.iconSize = 24;
574
+ [_toolbarButton addTarget:self action:@selector(toolbarTouchDown) forControlEvents:UIControlEventTouchDown];
575
+ [_toolbarButton addTarget:self action:@selector(toolbarPress:forEvent:) forControlEvents:UIControlEventTouchUpInside];
576
+ [_toolbarButton addTarget:self action:@selector(toolbarCancel) forControlEvents:UIControlEventTouchCancel | UIControlEventTouchUpOutside];
577
+ [self addSubview:_toolbarButton];
392
578
  _buttons = [NSMutableArray new];
393
579
  _indicatorFrames = [NSMutableArray new];
394
580
  _barHeight = 44;
395
581
  _contentPaddingHorizontal = 20;
582
+ _contentPaddingVertical = 0;
583
+ _segmented = NO;
396
584
  _itemSpacing = 8;
397
585
  _fontSize = 16;
398
586
  _activeTextColor = UIColor.labelColor;
@@ -414,6 +602,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
414
602
  _scrollView.delegate = self;
415
603
  [self addSubview:_scrollView];
416
604
 
605
+ _trackView = [UIView new];
606
+ _trackView.userInteractionEnabled = NO;
607
+ [_scrollView addSubview:_trackView];
608
+
417
609
  _indicatorView = [UIView new];
418
610
  _indicatorView.userInteractionEnabled = NO;
419
611
  [_scrollView addSubview:_indicatorView];
@@ -430,6 +622,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
430
622
  return [UIFont systemFontOfSize:_fontSize weight:UIFontWeightMedium];
431
623
  }
432
624
 
625
+ - (UIFont *)activeTabFont
626
+ {
627
+ NSString *activeFamily = _config[@"activeFontFamily"];
628
+ if (activeFamily.length > 0) {
629
+ return [UIFont fontWithName:activeFamily size:_fontSize]
630
+ ?: [UIFont systemFontOfSize:_fontSize weight:UIFontWeightSemibold];
631
+ }
632
+ UIFont *normalFont = _fontFamily.length > 0 ? [UIFont fontWithName:_fontFamily size:_fontSize] : nil;
633
+ return normalFont != nil ? [RCTFont updateFont:normalFont withWeight:@"600"]
634
+ : [UIFont systemFontOfSize:_fontSize weight:UIFontWeightSemibold];
635
+ }
636
+
433
637
  - (void)updateItemsJSON:(NSString *)itemsJSON
434
638
  {
435
639
  NSData *data = [itemsJSON dataUsingEncoding:NSUTF8StringEncoding];
@@ -464,11 +668,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
464
668
  for (UIButton *button in _buttons) [_scrollView bringSubviewToFront:button];
465
669
  _shouldCenterSelectedItem = YES;
466
670
  self.hidden = _items.count == 0;
671
+ if (_hasNativeProgress) [self setProgress:_nativeProgress];
672
+ else if ([_config[@"controlled"] boolValue]) {
673
+ NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
674
+ if (selected != NSNotFound) { _progress = selected; _progressSource = selected; _progressDestination = selected; _progressFraction = 0; }
675
+ }
467
676
  [self setNeedsLayout];
468
677
  }
469
678
 
470
679
  - (void)updateStyleWithHeight:(CGFloat)height
680
+ variant:(NSString *)variant
471
681
  contentPaddingHorizontal:(CGFloat)contentPaddingHorizontal
682
+ contentPaddingVertical:(CGFloat)contentPaddingVertical
472
683
  itemSpacing:(CGFloat)itemSpacing
473
684
  fontSize:(CGFloat)fontSize
474
685
  fontFamily:(NSString *)fontFamily
@@ -480,19 +691,28 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
480
691
  indicatorBottom:(CGFloat)indicatorBottom
481
692
  {
482
693
  _barHeight = MAX(1, height);
694
+ BOOL wasSegmented = _segmented;
695
+ _segmented = [variant isEqualToString:@"segmented"];
696
+ _textVariant = [variant isEqualToString:@"text"];
697
+ _pillVariant = [variant isEqualToString:@"pill"];
483
698
  _contentPaddingHorizontal = MAX(0, contentPaddingHorizontal);
699
+ _contentPaddingVertical = MAX(0, contentPaddingVertical);
484
700
  _itemSpacing = MAX(0, itemSpacing);
485
701
  _fontSize = MAX(1, fontSize);
486
702
  _fontFamily = [fontFamily copy];
487
- self.backgroundColor = backgroundColor ?: UIColor.clearColor;
488
- _scrollView.backgroundColor = self.backgroundColor;
703
+ self.backgroundColor = _segmented ? UIColor.clearColor : (backgroundColor ?: UIColor.clearColor);
704
+ _scrollView.backgroundColor = _textVariant ? UIColor.clearColor : self.backgroundColor;
705
+ _scrollView.scrollEnabled = !_segmented;
706
+ if (_segmented && !wasSegmented) [_scrollView setContentOffset:CGPointZero animated:NO];
707
+ _trackView.hidden = !_segmented;
708
+ _trackView.backgroundColor = backgroundColor ?: UIColor.clearColor;
489
709
  _activeTextColor = activeTextColor ?: UIColor.labelColor;
490
710
  _inactiveTextColor = inactiveTextColor ?: UIColor.secondaryLabelColor;
491
711
  _indicatorColor = indicatorColor ?: _activeTextColor;
492
712
  _indicatorHeight = MAX(0, indicatorHeight);
493
713
  _indicatorBottom = MAX(0, indicatorBottom);
494
714
  _indicatorView.backgroundColor = _indicatorColor;
495
- _indicatorView.layer.cornerRadius = _indicatorHeight / 2;
715
+ _indicatorView.layer.cornerRadius = _segmented ? 0 : _indicatorHeight / 2;
496
716
  for (UIButton *button in _buttons) button.titleLabel.font = self.tabFont;
497
717
  [self setNeedsLayout];
498
718
  }
@@ -547,22 +767,83 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
547
767
  RNCLogNativeTabScrollBoundary(@"primary", @"end", scrollView, _scrollStartOffsetX);
548
768
  }
549
769
 
770
+ - (CGFloat)itemPaddingHorizontal
771
+ {
772
+ id value = _config[@"itemPaddingHorizontal"];
773
+ if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] >= 0) {
774
+ return [value doubleValue];
775
+ }
776
+ return _textVariant ? 10 : (_pillVariant ? 14 : 8);
777
+ }
778
+
779
+ // The tab row and toolbar share a centered band no wider than contentMaxWidth;
780
+ // the bar background still covers the full width.
781
+ - (CGRect)contentRowFrame
782
+ {
783
+ CGFloat width = CGRectGetWidth(self.bounds);
784
+ id value = _config[@"contentMaxWidth"];
785
+ if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] > 0 &&
786
+ [value doubleValue] < width) {
787
+ CGFloat rowWidth = [value doubleValue];
788
+ return CGRectMake(floor((width - rowWidth) / 2), 0, rowWidth, CGRectGetHeight(self.bounds));
789
+ }
790
+ return self.bounds;
791
+ }
792
+
550
793
  - (void)layoutSubviews
551
794
  {
552
795
  [super layoutSubviews];
553
- _scrollView.frame = self.bounds;
796
+ CGFloat reserved = _toolbarReservedWidth;
797
+ CGRect row = [self contentRowFrame];
798
+ [self bringSubviewToFront:_toolbarButton];
799
+ _scrollView.frame = CGRectMake(CGRectGetMinX(row) + (_leftToRight ? 0 : reserved), 0,
800
+ MAX(0, CGRectGetWidth(row) - reserved), CGRectGetHeight(self.bounds));
801
+ CGFloat inset = _toolbarTrailingInset - (_toolbarSize - _toolbarContentWidth) / 2;
802
+ _toolbarButton.frame = CGRectMake(_leftToRight ? CGRectGetMaxX(row) - inset - _toolbarSize : CGRectGetMinX(row) + inset,
803
+ (CGRectGetHeight(self.bounds) - _toolbarSize) / 2, _toolbarSize, _toolbarSize);
804
+ if (_segmented) {
805
+ CGFloat width = CGRectGetWidth(_scrollView.bounds);
806
+ CGFloat height = CGRectGetHeight(self.bounds);
807
+ CGFloat insetX = MIN(_contentPaddingHorizontal, width / 2);
808
+ CGFloat insetY = MIN(_contentPaddingVertical, height / 2);
809
+ CGRect trackFrame = CGRectMake(insetX, insetY,
810
+ MAX(0, width - 2 * insetX), MAX(0, height - 2 * insetY));
811
+ _trackView.frame = trackFrame;
812
+ _trackView.layer.cornerRadius = CGRectGetHeight(trackFrame) / 2;
813
+ _scrollView.contentSize = _scrollView.bounds.size;
814
+ [_indicatorFrames removeAllObjects];
815
+ NSUInteger count = _buttons.count;
816
+ [_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
817
+ CGFloat first = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) * index / count;
818
+ CGFloat last = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) * (index + 1) / count;
819
+ CGFloat x = self->_leftToRight ? first : CGRectGetMaxX(trackFrame) - (last - CGRectGetMinX(trackFrame));
820
+ CGFloat end = self->_leftToRight ? last : CGRectGetMaxX(trackFrame) - (first - CGRectGetMinX(trackFrame));
821
+ button.frame = CGRectMake(x, CGRectGetMinY(trackFrame), MAX(0, end - x), CGRectGetHeight(trackFrame));
822
+ CGRect thumbFrame = CGRectMake(x + 2, CGRectGetMinY(trackFrame) + 2,
823
+ MAX(0, CGRectGetWidth(button.frame) - 4), MAX(0, CGRectGetHeight(trackFrame) - 4));
824
+ [self->_indicatorFrames addObject:[NSValue valueWithCGRect:thumbFrame]];
825
+ }];
826
+ _indicatorView.layer.cornerRadius = MAX(0, CGRectGetHeight(trackFrame) - 4) / 2;
827
+ [self updatePresentation];
828
+ return;
829
+ }
830
+ _trackView.frame = CGRectZero;
554
831
  UIFont *font = self.tabFont;
555
832
  NSMutableArray<NSNumber *> *widths = [NSMutableArray arrayWithCapacity:_buttons.count];
556
833
  CGFloat itemsWidth = 0;
557
834
  for (UIButton *button in _buttons) {
558
835
  NSString *title = [button titleForState:UIControlStateNormal] ?: @"";
559
836
  CGFloat textWidth = ceil([title sizeWithAttributes:@{NSFontAttributeName: font}].width);
560
- CGFloat buttonWidth = MAX(44, textWidth + 16);
837
+ if (_textVariant) {
838
+ UIFont *activeFont = self.activeTabFont;
839
+ textWidth = MAX(textWidth, ceil([title sizeWithAttributes:@{NSFontAttributeName: activeFont}].width));
840
+ }
841
+ CGFloat buttonWidth = MAX(44, textWidth + 2 * self.itemPaddingHorizontal);
561
842
  [widths addObject:@(buttonWidth)];
562
843
  itemsWidth += buttonWidth;
563
844
  }
564
845
  if (_buttons.count > 1) itemsWidth += (_buttons.count - 1) * _itemSpacing;
565
- CGFloat contentWidth = MAX(CGRectGetWidth(self.bounds),
846
+ CGFloat contentWidth = MAX(CGRectGetWidth(_scrollView.bounds),
566
847
  itemsWidth + _contentPaddingHorizontal * 2);
567
848
  _scrollView.contentSize = CGSizeMake(contentWidth, MAX(_barHeight, CGRectGetHeight(self.bounds)));
568
849
  [_indicatorFrames removeAllObjects];
@@ -573,6 +854,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
573
854
  [_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
574
855
  CGFloat buttonWidth = widths[index].doubleValue;
575
856
  if (!self->_leftToRight) x -= buttonWidth;
857
+ if (self->_pillVariant) {
858
+ CGFloat insetY = MIN(self->_contentPaddingVertical, self->_barHeight / 2);
859
+ button.frame = CGRectMake(x, insetY, buttonWidth, MAX(0, self->_barHeight - 2 * insetY));
860
+ [self->_indicatorFrames addObject:[NSValue valueWithCGRect:button.frame]];
861
+ if (self->_leftToRight) x += buttonWidth + self->_itemSpacing;
862
+ else x -= self->_itemSpacing;
863
+ return;
864
+ }
576
865
  button.frame = CGRectMake(x, 0, buttonWidth, self->_barHeight);
577
866
  NSString *title = [button titleForState:UIControlStateNormal] ?: @"";
578
867
  CGFloat textWidth = ceil([title sizeWithAttributes:@{NSFontAttributeName: font}].width);
@@ -592,19 +881,515 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
592
881
  [self updatePresentation];
593
882
  }
594
883
 
884
+ - (Class<RNCPagerNamedSVGBridge>)iconBridge {
885
+ Class cls = NSClassFromString(@"OneKeyNamedSVGBridge");
886
+ if (![cls respondsToSelector:@selector(cancelWithOwner:)] ||
887
+ ![cls respondsToSelector:@selector(requestWithOwner:name:color:width:height:scale:complete:)]) return Nil;
888
+ return (Class<RNCPagerNamedSVGBridge>)cls;
889
+ }
890
+ - (void)updateConfigJSON:(NSString *)json {
891
+ BOOL wasOwned = [self ownsSettledToolbar];
892
+ NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
893
+ id parsed = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
894
+ _config = [parsed isKindOfClass:NSDictionary.class] ? parsed : @{};
895
+ BOOL owned = [self ownsSettledToolbar];
896
+ if (owned != wasOwned) {
897
+ if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
898
+ _iconOwner = [NSObject new];
899
+ _iconRequestPending = NO;
900
+ _readyToolbarImage = nil;
901
+ _readyToolbarIdentity = nil;
902
+ _desiredToolbarKey = nil;
903
+ _desiredToolbarEntry = nil;
904
+ [self suspendToolbar];
905
+ if (!owned) {
906
+ ++_toolbarAnimationGeneration;
907
+ [_toolbarButton.layer removeAllAnimations];
908
+ _toolbarPresenceAnimating = NO;
909
+ _toolbarPresenceInterrupted = NO;
910
+ _toolbarButton.alpha = _toolbarVisible ? 1 : 0;
911
+ _toolbarButton.hidden = !_toolbarVisible;
912
+ [self setToolbarInteractive:_toolbarVisible];
913
+ }
914
+ }
915
+ if (!owned) {
916
+ _toolbarTouchKey = nil;
917
+ _toolbarButton.highlighted = NO;
918
+ _toolbarButton.hovering = NO;
919
+ }
920
+ _toolbarButton.adjustsImageWhenDisabled = !owned;
921
+ NSString *key = _config[@"selectedKey"];
922
+ if (![_config[@"controlled"] boolValue]) {
923
+ _progress = RNCClamp(_nativeProgress, 0, MAX(0, (NSInteger)_items.count - 1));
924
+ key = _items.count ? _items[(NSInteger)round(_progress)][@"key"] : nil;
925
+ }
926
+ if (_hasNativeProgress) {
927
+ [self setProgress:_nativeProgress];
928
+ } else {
929
+ NSUInteger index = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:key]; }];
930
+ if (index != NSNotFound) {
931
+ _progress = index;
932
+ _progressSource = index;
933
+ _progressDestination = index;
934
+ _progressFraction = 0;
935
+ }
936
+ }
937
+ [self updateToolbarForKey:key];
938
+ [self setNeedsLayout];
939
+ }
940
+ - (BOOL)pillAnimationDisabled
941
+ {
942
+ id value = _config[@"indicatorAnimationEnabled"];
943
+ return _pillVariant && [value isKindOfClass:NSNumber.class] && ![value boolValue];
944
+ }
945
+ - (BOOL)usesControlledTextProgress {
946
+ return (_textVariant || (_pillVariant && !self.pillAnimationDisabled)) && [_config[@"controlled"] boolValue];
947
+ }
948
+ - (void)setLegacyToolbarVisible:(BOOL)visible {
949
+ _toolbarButton.enabled = visible;
950
+ _toolbarButton.userInteractionEnabled = visible;
951
+ _toolbarButton.accessibilityElementsHidden = !visible;
952
+ _toolbarButton.isAccessibilityElement = visible;
953
+ if (_toolbarVisible == visible) return;
954
+ _toolbarVisible = visible;
955
+ NSUInteger generation = ++_toolbarAnimationGeneration;
956
+ CALayer *presentation = _toolbarButton.layer.presentationLayer;
957
+ CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
958
+ [_toolbarButton.layer removeAllAnimations];
959
+ _toolbarButton.alpha = alpha;
960
+ _toolbarButton.enabled = visible;
961
+ _toolbarButton.userInteractionEnabled = visible;
962
+ _toolbarButton.accessibilityElementsHidden = !visible;
963
+ if (visible) _toolbarButton.hidden = NO;
964
+ if (self.window == nil) {
965
+ _toolbarButton.alpha = visible ? 1 : 0;
966
+ _toolbarButton.hidden = !visible;
967
+ return;
968
+ }
969
+ [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
970
+ self->_toolbarButton.alpha = visible ? 1 : 0;
971
+ } completion:^(BOOL finished) {
972
+ if (self->_toolbarAnimationGeneration == generation && !visible) {
973
+ self->_toolbarButton.hidden = YES;
974
+ [self applyReadyLegacyToolbarImage];
975
+ }
976
+ }];
977
+ }
978
+ - (void)applyReadyLegacyToolbarImage {
979
+ if (_readyToolbarImage == nil || ![_readyToolbarIdentity isEqualToString:_iconIdentity]) return;
980
+ CALayer *presentation = _toolbarButton.layer.presentationLayer;
981
+ if (_toolbarButton.alpha > 0.001 || (presentation && presentation.opacity > 0.001)) return;
982
+ [_toolbarButton setImage:_readyToolbarImage forState:UIControlStateNormal];
983
+ _loadedIconIdentity = _readyToolbarIdentity;
984
+ _loadedToolbarImage = _readyToolbarImage;
985
+ _readyToolbarImage = nil;
986
+ _readyToolbarIdentity = nil;
987
+ _iconRequestPending = NO;
988
+ [self setLegacyToolbarVisible:YES];
989
+ }
990
+ - (void)updateLegacyToolbarForKey:(NSString *)key {
991
+ NSDictionary *toolbar = [_config[@"toolbar"] isKindOfClass:NSDictionary.class] ? _config[@"toolbar"] : nil;
992
+ _toolbarReservedWidth = toolbar == nil ? 0 : 44;
993
+ if (toolbar.count > 0) {
994
+ _toolbarReservedWidth = 0;
995
+ for (id value in toolbar.allValues) {
996
+ NSDictionary *entry = [value isKindOfClass:NSDictionary.class] ? value : @{};
997
+ CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
998
+ CGFloat content = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, size), 0, size);
999
+ CGFloat trailing = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
1000
+ _toolbarReservedWidth = MAX(_toolbarReservedWidth, content + trailing);
1001
+ }
1002
+ }
1003
+ NSDictionary *entry = [toolbar[key ?: @""] isKindOfClass:NSDictionary.class] ? toolbar[key] : nil;
1004
+ NSString *name = [entry[@"iconName"] isKindOfClass:NSString.class] ? entry[@"iconName"] : nil;
1005
+ if (![_toolbarKey isEqualToString:key]) {
1006
+ _toolbarTouchKey = nil;
1007
+ _toolbarButton.highlighted = NO;
1008
+ _toolbarButton.hovering = NO;
1009
+ }
1010
+ _toolbarKey = [key copy];
1011
+ if (name.length == 0) {
1012
+ _toolbarTouchKey = nil;
1013
+ _toolbarButton.accessibilityLabel = nil;
1014
+ _toolbarButton.accessibilityIdentifier = nil;
1015
+ if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
1016
+ _iconOwner = [NSObject new];
1017
+ _iconRequestPending = NO;
1018
+ _readyToolbarImage = nil;
1019
+ _readyToolbarIdentity = nil;
1020
+ [self setLegacyToolbarVisible:NO];
1021
+ return;
1022
+ }
1023
+ _toolbarSize = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
1024
+ _toolbarIconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, _toolbarSize), 1, _toolbarSize);
1025
+ _toolbarContentWidth = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, _toolbarSize), 0, _toolbarSize);
1026
+ _toolbarTrailingInset = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
1027
+ _toolbarButton.layer.cornerRadius = _toolbarSize / 2;
1028
+ _toolbarButton.iconSize = _toolbarIconSize;
1029
+ [_toolbarButton setNeedsLayout];
1030
+ _toolbarButton.baseColor = [entry[@"selected"] boolValue] ? ([RCTConvert UIColor:entry[@"selectedBackgroundColor"]] ?: UIColor.clearColor) : UIColor.clearColor;
1031
+ _toolbarButton.hoverColor = [RCTConvert UIColor:entry[@"hoverBackgroundColor"]] ?: _toolbarButton.baseColor;
1032
+ _toolbarButton.pressedColor = [RCTConvert UIColor:entry[@"pressedBackgroundColor"]] ?: _toolbarButton.baseColor;
1033
+ [_toolbarButton refreshBackground];
1034
+ _toolbarButton.accessibilityLabel = entry[@"accessibilityLabel"];
1035
+ _toolbarButton.accessibilityIdentifier = entry[@"testID"];
1036
+ NSString *color = [entry[@"iconColor"] isKindOfClass:NSString.class] ? entry[@"iconColor"] : @"#000000";
1037
+ CGFloat scale = self.window.screen.scale ?: UIScreen.mainScreen.scale;
1038
+ NSString *identity = [NSString stringWithFormat:@"%@|%@|%g|%g", name, color, scale, _toolbarIconSize];
1039
+ if ([_loadedIconIdentity isEqualToString:identity] && [_toolbarButton imageForState:UIControlStateNormal] != nil) {
1040
+ if (_iconRequestPending) {
1041
+ [[self iconBridge] cancelWithOwner:_iconOwner];
1042
+ _iconOwner = [NSObject new];
1043
+ }
1044
+ _iconIdentity = identity;
1045
+ _iconRequestPending = NO;
1046
+ _readyToolbarImage = nil;
1047
+ _readyToolbarIdentity = nil;
1048
+ [self setLegacyToolbarVisible:YES];
1049
+ return;
1050
+ }
1051
+ if ((_iconRequestPending || [_failedIconIdentity isEqualToString:identity]) && [_iconIdentity isEqualToString:identity]) return;
1052
+ if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
1053
+ NSObject *owner = [NSObject new];
1054
+ _iconOwner = owner;
1055
+ _iconIdentity = identity;
1056
+ _iconRequestPending = NO;
1057
+ _readyToolbarImage = nil;
1058
+ _readyToolbarIdentity = nil;
1059
+ [self setLegacyToolbarVisible:NO];
1060
+ if ([_failedIconIdentity isEqualToString:identity] || self.window == nil) return;
1061
+ _iconRequestPending = YES;
1062
+ __weak __typeof__(self) weakSelf = self;
1063
+ [[self iconBridge] requestWithOwner:owner name:name color:color width:(NSInteger)ceil(_toolbarIconSize * scale) height:(NSInteger)ceil(_toolbarIconSize * scale) scale:scale complete:^(UIImage *image) {
1064
+ __strong __typeof__(weakSelf) self = weakSelf;
1065
+ if (!self || self->_iconOwner != owner || ![self->_iconIdentity isEqualToString:identity] || !self.window) return;
1066
+ if (image == nil) {
1067
+ self->_iconRequestPending = NO;
1068
+ self->_failedIconIdentity = identity;
1069
+ return;
1070
+ }
1071
+ UIImage *scaled = image.CGImage ? [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] : image;
1072
+ self->_readyToolbarImage = [scaled imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
1073
+ self->_readyToolbarIdentity = identity;
1074
+ [self applyReadyLegacyToolbarImage];
1075
+ }];
1076
+ }
1077
+
1078
+ - (BOOL)ownsSettledToolbar {
1079
+ return [_config[@"controlled"] boolValue] && [_config[@"toolbar"] isKindOfClass:NSDictionary.class];
1080
+ }
1081
+ - (BOOL)toolbarCanCommit {
1082
+ if (!self.window) return NO;
1083
+ if (![self ownsSettledToolbar]) return YES;
1084
+ if (_toolbarPagerBusy || _toolbarPageIndex < 0) return NO;
1085
+ NSArray *pages = [_config[@"pageKeys"] isKindOfClass:NSArray.class] ? _config[@"pageKeys"] : @[];
1086
+ NSArray *items = [_items valueForKey:@"key"];
1087
+ BOOL valid = pages.count > 0 && [pages containsObject:_config[@"selectedKey"] ?: @""] &&
1088
+ [NSSet setWithArray:pages].count == pages.count && [NSSet setWithArray:items].count == items.count;
1089
+ for (id key in pages) if (![items containsObject:key]) { valid = NO; break; }
1090
+ return !valid || (_toolbarPageIndex < pages.count && [pages[_toolbarPageIndex] isEqual:_config[@"selectedKey"]]);
1091
+ }
1092
+ - (void)setToolbarInteractive:(BOOL)interactive {
1093
+ _toolbarButton.enabled = interactive;
1094
+ _toolbarButton.userInteractionEnabled = interactive;
1095
+ _toolbarButton.accessibilityElementsHidden = !interactive;
1096
+ _toolbarButton.isAccessibilityElement = interactive;
1097
+ if (!interactive) {
1098
+ _toolbarTouchKey = nil;
1099
+ _toolbarButton.highlighted = NO;
1100
+ _toolbarButton.hovering = NO;
1101
+ [_toolbarButton refreshBackground];
1102
+ }
1103
+ }
1104
+ - (void)cancelToolbarRequest {
1105
+ if (_iconRequestPending || _readyToolbarImage) {
1106
+ if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
1107
+ _iconOwner = [NSObject new];
1108
+ _iconRequestPending = NO;
1109
+ _readyToolbarImage = nil;
1110
+ _readyToolbarIdentity = nil;
1111
+ }
1112
+ }
1113
+ - (void)suspendToolbar {
1114
+ [self setToolbarInteractive:NO];
1115
+ [self cancelToolbarRequest];
1116
+ _desiredToolbarKey = nil;
1117
+ _desiredToolbarEntry = nil;
1118
+ if (_toolbarPresenceAnimating) {
1119
+ CALayer *presentation = _toolbarButton.layer.presentationLayer;
1120
+ CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
1121
+ ++_toolbarAnimationGeneration;
1122
+ [_toolbarButton.layer removeAllAnimations];
1123
+ _toolbarButton.alpha = alpha;
1124
+ _toolbarPresenceAnimating = NO;
1125
+ _toolbarPresenceInterrupted = YES;
1126
+ }
1127
+ }
1128
+ - (void)updateToolbarPagerIndex:(NSInteger)index busy:(BOOL)busy {
1129
+ if (_toolbarPagerBusy == busy && (busy || _toolbarPageIndex == index)) return;
1130
+ _toolbarPagerBusy = busy;
1131
+ if (!busy) _toolbarPageIndex = index;
1132
+ NSString *key = [_config[@"controlled"] boolValue] ? _config[@"selectedKey"] : _toolbarKey;
1133
+ [self updateToolbarForKey:key];
1134
+ }
1135
+ - (void)setToolbarVisible:(BOOL)visible {
1136
+ if (_toolbarVisible == visible && !_toolbarPresenceInterrupted) return;
1137
+ _toolbarVisible = visible;
1138
+ _toolbarPresenceInterrupted = NO;
1139
+ NSUInteger generation = ++_toolbarAnimationGeneration;
1140
+ CALayer *presentation = _toolbarButton.layer.presentationLayer;
1141
+ CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
1142
+ [_toolbarButton.layer removeAllAnimations];
1143
+ _toolbarButton.alpha = alpha;
1144
+ if (visible) _toolbarButton.hidden = NO;
1145
+ if (!self.window) {
1146
+ _toolbarPresenceAnimating = NO;
1147
+ _toolbarButton.alpha = visible ? 1 : 0;
1148
+ _toolbarButton.hidden = !visible;
1149
+ return;
1150
+ }
1151
+ _toolbarPresenceAnimating = YES;
1152
+ [UIView animateWithDuration:0.10 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
1153
+ self->_toolbarButton.alpha = visible ? 1 : 0;
1154
+ } completion:^(BOOL finished) {
1155
+ if (self->_toolbarAnimationGeneration != generation) return;
1156
+ self->_toolbarPresenceAnimating = NO;
1157
+ if (!visible) self->_toolbarButton.hidden = YES;
1158
+ }];
1159
+ }
1160
+ - (void)commitToolbarImage:(UIImage *)image identity:(NSString *)identity {
1161
+ if (![self toolbarCanCommit] || !_desiredToolbarKey || !_desiredToolbarEntry) return;
1162
+ NSDictionary *entry = _desiredToolbarEntry;
1163
+ BOOL changed = ![_toolbarKey isEqualToString:_desiredToolbarKey] || ![_committedToolbarEntry isEqual:entry] || _loadedToolbarImage != image;
1164
+ if (![_toolbarKey isEqualToString:_desiredToolbarKey]) [self setToolbarInteractive:NO];
1165
+ _toolbarKey = [_desiredToolbarKey copy];
1166
+ _committedToolbarEntry = entry;
1167
+ _toolbarSize = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
1168
+ _toolbarIconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, _toolbarSize), 1, _toolbarSize);
1169
+ _toolbarContentWidth = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, _toolbarSize), 0, _toolbarSize);
1170
+ _toolbarTrailingInset = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
1171
+ _toolbarButton.layer.cornerRadius = _toolbarSize / 2;
1172
+ _toolbarButton.iconSize = _toolbarIconSize;
1173
+ [_toolbarButton setNeedsLayout];
1174
+ _toolbarButton.baseColor = [entry[@"selected"] boolValue] ? ([RCTConvert UIColor:entry[@"selectedBackgroundColor"]] ?: UIColor.clearColor) : UIColor.clearColor;
1175
+ _toolbarButton.hoverColor = [RCTConvert UIColor:entry[@"hoverBackgroundColor"]] ?: _toolbarButton.baseColor;
1176
+ _toolbarButton.pressedColor = [RCTConvert UIColor:entry[@"pressedBackgroundColor"]] ?: _toolbarButton.baseColor;
1177
+ [_toolbarButton refreshBackground];
1178
+ _toolbarButton.accessibilityLabel = entry[@"accessibilityLabel"];
1179
+ _toolbarButton.accessibilityIdentifier = entry[@"testID"];
1180
+ [_toolbarButton setImage:image forState:UIControlStateNormal];
1181
+ _loadedIconIdentity = identity;
1182
+ _loadedToolbarImage = image;
1183
+ _readyToolbarImage = nil;
1184
+ _readyToolbarIdentity = nil;
1185
+ _iconRequestPending = NO;
1186
+ [self setToolbarVisible:YES];
1187
+ [self setToolbarInteractive:YES];
1188
+ if (changed) [self setNeedsLayout];
1189
+ }
1190
+ - (void)applyReadyToolbarImage {
1191
+ if (!_readyToolbarImage || ![_readyToolbarIdentity isEqualToString:_iconIdentity] || ![self toolbarCanCommit]) return;
1192
+ [self commitToolbarImage:_readyToolbarImage identity:_readyToolbarIdentity];
1193
+ }
1194
+ - (void)hideFailedToolbar {
1195
+ [self setToolbarInteractive:NO];
1196
+ _toolbarKey = nil;
1197
+ _committedToolbarEntry = nil;
1198
+ [_toolbarButton setImage:nil forState:UIControlStateNormal];
1199
+ _toolbarButton.accessibilityLabel = nil;
1200
+ _toolbarButton.accessibilityIdentifier = nil;
1201
+ [self setToolbarVisible:NO];
1202
+ }
1203
+ - (void)updateToolbarForKey:(NSString *)key {
1204
+ if (![self ownsSettledToolbar]) { [self updateLegacyToolbarForKey:key]; return; }
1205
+ NSDictionary *toolbar = [_config[@"toolbar"] isKindOfClass:NSDictionary.class] ? _config[@"toolbar"] : nil;
1206
+ _toolbarReservedWidth = toolbar == nil ? 0 : 44;
1207
+ if (toolbar.count > 0) {
1208
+ _toolbarReservedWidth = 0;
1209
+ for (id value in toolbar.allValues) {
1210
+ NSDictionary *entry = [value isKindOfClass:NSDictionary.class] ? value : @{};
1211
+ CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
1212
+ CGFloat content = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, size), 0, size);
1213
+ CGFloat trailing = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
1214
+ _toolbarReservedWidth = MAX(_toolbarReservedWidth, content + trailing);
1215
+ }
1216
+ }
1217
+ if (![self toolbarCanCommit]) { [self suspendToolbar]; return; }
1218
+ NSDictionary *entry = [toolbar[key ?: @""] isKindOfClass:NSDictionary.class] ? toolbar[key] : nil;
1219
+ NSString *name = [entry[@"iconName"] isKindOfClass:NSString.class] ? entry[@"iconName"] : nil;
1220
+ if (!name.length) {
1221
+ [self cancelToolbarRequest];
1222
+ _desiredToolbarKey = nil;
1223
+ _desiredToolbarEntry = nil;
1224
+ _toolbarKey = nil;
1225
+ _committedToolbarEntry = nil;
1226
+ [self setToolbarInteractive:NO];
1227
+ _toolbarButton.accessibilityLabel = nil;
1228
+ _toolbarButton.accessibilityIdentifier = nil;
1229
+ [self setToolbarVisible:NO];
1230
+ return;
1231
+ }
1232
+ _desiredToolbarKey = [key copy];
1233
+ _desiredToolbarEntry = [entry copy];
1234
+ CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
1235
+ CGFloat iconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, size), 1, size);
1236
+ NSString *color = [entry[@"iconColor"] isKindOfClass:NSString.class] ? entry[@"iconColor"] : @"#000000";
1237
+ CGFloat scale = self.window.screen.scale ?: UIScreen.mainScreen.scale;
1238
+ NSString *identity = [NSString stringWithFormat:@"%@|%@|%g|%g", name, color, scale, iconSize];
1239
+ if ([_loadedIconIdentity isEqualToString:identity] && _loadedToolbarImage) {
1240
+ [self cancelToolbarRequest];
1241
+ _iconIdentity = identity;
1242
+ [self commitToolbarImage:_loadedToolbarImage identity:identity];
1243
+ return;
1244
+ }
1245
+ if ([_iconIdentity isEqualToString:identity] && (_iconRequestPending || _readyToolbarImage)) {
1246
+ [self setToolbarInteractive:NO];
1247
+ [self applyReadyToolbarImage];
1248
+ return;
1249
+ }
1250
+ [self cancelToolbarRequest];
1251
+ _iconIdentity = identity;
1252
+ [self setToolbarInteractive:NO];
1253
+ if ([_failedIconIdentity isEqualToString:identity]) { [self hideFailedToolbar]; return; }
1254
+ NSObject *owner = [NSObject new];
1255
+ _iconOwner = owner;
1256
+ _iconRequestPending = YES;
1257
+ __weak __typeof__(self) weakSelf = self;
1258
+ [[self iconBridge] requestWithOwner:owner name:name color:color width:(NSInteger)ceil(iconSize * scale) height:(NSInteger)ceil(iconSize * scale) scale:scale complete:^(UIImage *image) {
1259
+ __strong __typeof__(weakSelf) self = weakSelf;
1260
+ if (!self || self->_iconOwner != owner || ![self->_iconIdentity isEqualToString:identity] || !self.window) return;
1261
+ self->_iconRequestPending = NO;
1262
+ if (!image) {
1263
+ self->_failedIconIdentity = identity;
1264
+ if ([self toolbarCanCommit]) [self hideFailedToolbar];
1265
+ return;
1266
+ }
1267
+ UIImage *scaled = image.CGImage ? [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] : image;
1268
+ self->_readyToolbarImage = [scaled imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
1269
+ self->_readyToolbarIdentity = identity;
1270
+ [self applyReadyToolbarImage];
1271
+ }];
1272
+ }
1273
+ - (void)didMoveToWindow {
1274
+ [super didMoveToWindow];
1275
+ if (![self ownsSettledToolbar]) {
1276
+ if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
1277
+ _iconIdentity = nil;
1278
+ _loadedIconIdentity = nil;
1279
+ _iconRequestPending = NO;
1280
+ _readyToolbarImage = nil;
1281
+ _readyToolbarIdentity = nil;
1282
+ _failedIconIdentity = nil;
1283
+ _iconOwner = [NSObject new];
1284
+ _toolbarAnimationGeneration++;
1285
+ [_toolbarButton.layer removeAllAnimations];
1286
+ _toolbarVisible = NO;
1287
+ _toolbarButton.alpha = 0;
1288
+ _toolbarButton.hidden = YES;
1289
+ _toolbarButton.enabled = NO;
1290
+ _toolbarButton.userInteractionEnabled = NO;
1291
+ _toolbarButton.accessibilityElementsHidden = YES;
1292
+ _toolbarTouchKey = nil;
1293
+ _toolbarTouchStarted = NO;
1294
+ _toolbarButton.highlighted = NO;
1295
+ _toolbarButton.hovering = NO;
1296
+ [self updateToolbarForKey:_toolbarKey];
1297
+ return;
1298
+ }
1299
+ [self suspendToolbar];
1300
+ _toolbarPagerBusy = YES;
1301
+ _toolbarPageIndex = -1;
1302
+ _toolbarTouchStarted = NO;
1303
+ if (self.window && self.onToolbarNeedsSettlement) self.onToolbarNeedsSettlement();
1304
+ }
1305
+ - (void)dealloc { if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner]; }
1306
+ - (void)toolbarTouchDown {
1307
+ _toolbarTouchStarted = YES;
1308
+ _toolbarTouchKey = _toolbarButton.enabled && [self toolbarCanCommit] ? [_toolbarKey copy] : nil;
1309
+ }
1310
+ - (void)toolbarCancel {
1311
+ _toolbarTouchKey = nil;
1312
+ if (![self ownsSettledToolbar]) _toolbarTouchStarted = NO;
1313
+ }
1314
+ - (void)toolbarPress:(UIControl *)sender forEvent:(UIEvent *)event {
1315
+ if (![self ownsSettledToolbar]) {
1316
+ NSString *key = _toolbarTouchStarted ? _toolbarTouchKey : _toolbarKey;
1317
+ _toolbarTouchStarted = NO; _toolbarTouchKey = nil;
1318
+ if (key && [key isEqualToString:_toolbarKey] && !_toolbarButton.hidden && _toolbarButton.enabled && self.window && self.onToolbarPress)
1319
+ self.onToolbarPress(key, [_toolbarButton convertRect:_toolbarButton.bounds toView:self.window]);
1320
+ return;
1321
+ }
1322
+ BOOL pointer = event && event.type == UIEventTypeTouches;
1323
+ NSString *key = pointer ? (_toolbarTouchStarted ? _toolbarTouchKey : nil) : _toolbarKey;
1324
+ if (pointer) { _toolbarTouchStarted = NO; _toolbarTouchKey = nil; }
1325
+ BOOL selectedMatches = ![_config[@"controlled"] boolValue] || [key isEqual:_config[@"selectedKey"]];
1326
+ if (key && selectedMatches && [key isEqualToString:_toolbarKey] && [self toolbarCanCommit] &&
1327
+ !_toolbarButton.hidden && _toolbarButton.enabled && self.onToolbarPress) {
1328
+ self.onToolbarPress(key, [_toolbarButton convertRect:_toolbarButton.bounds toView:self.window]);
1329
+ }
1330
+ }
1331
+
595
1332
  - (void)setProgress:(CGFloat)progress
596
1333
  {
1334
+ _hasMappedPageProgress = NO;
1335
+ _nativeProgress = progress;
1336
+ _hasNativeProgress = YES;
597
1337
  if (_items.count == 0) return;
598
1338
  if (fabs(_progress - progress) >= 0.001) _shouldCenterSelectedItem = YES;
1339
+ if ([_config[@"controlled"] boolValue]) {
1340
+ NSArray *pageKeys = [_config[@"pageKeys"] isKindOfClass:NSArray.class] ? _config[@"pageKeys"] : @[];
1341
+ NSMutableArray<NSNumber *> *indices = [NSMutableArray new];
1342
+ NSSet *unique = [NSSet setWithArray:pageKeys];
1343
+ NSArray *itemKeys = [_items valueForKey:@"key"];
1344
+ BOOL valid = pageKeys.count > 0 && [pageKeys containsObject:_config[@"selectedKey"] ?: @""] && unique.count == pageKeys.count && [NSSet setWithArray:itemKeys].count == itemKeys.count;
1345
+ for (NSString *key in pageKeys) {
1346
+ NSUInteger index = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:key]; }];
1347
+ if (index == NSNotFound) { valid = NO; break; }
1348
+ [indices addObject:@(index)];
1349
+ }
1350
+ if (!valid) {
1351
+ NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
1352
+ if (selected == NSNotFound) return;
1353
+ _progressSource = selected; _progressDestination = selected; _progressFraction = 0;
1354
+ _progress = selected;
1355
+ if (_indicatorFrames.count == _items.count) [self updatePresentation];
1356
+ return;
1357
+ }
1358
+ _hasMappedPageProgress = YES;
1359
+ CGFloat bounded = RNCClamp(progress, 0, pageKeys.count - 1);
1360
+ NSInteger lower = (NSInteger)floor(bounded);
1361
+ NSInteger upper = MIN(lower + 1, pageKeys.count - 1);
1362
+ _progressSource = indices[lower].integerValue;
1363
+ _progressDestination = indices[upper].integerValue;
1364
+ _progressFraction = bounded - lower;
1365
+ progress = _progressSource + (_progressDestination - _progressSource) * _progressFraction;
1366
+ }
599
1367
  _progress = RNCClamp(progress, 0, _items.count - 1);
600
1368
  if (_indicatorFrames.count == _items.count) [self updatePresentation];
601
1369
  }
602
1370
 
1371
+ - (NSInteger)visualFontOwnerIndex:(NSInteger)semanticIndex {
1372
+ if (_textVariant && [_config[@"controlled"] boolValue] && _hasMappedPageProgress) {
1373
+ return _progressFraction < 0.5 ? _progressSource : _progressDestination;
1374
+ }
1375
+ return semanticIndex;
1376
+ }
1377
+
603
1378
  - (void)updatePresentation
604
1379
  {
605
1380
  NSInteger count = _buttons.count;
606
1381
  if (count == 0 || _indicatorFrames.count != count) return;
607
1382
  CGFloat progress = RNCClamp(_progress, 0, count - 1);
1383
+ BOOL snapToSelection = self.pillAnimationDisabled;
1384
+ if (snapToSelection) {
1385
+ // The pill and label colors jump to the selection instead of following progress.
1386
+ NSInteger snapped = (NSInteger)round(progress);
1387
+ if ([_config[@"controlled"] boolValue]) {
1388
+ NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
1389
+ if (selected != NSNotFound) snapped = (NSInteger)selected;
1390
+ }
1391
+ progress = RNCClamp(snapped, 0, count - 1);
1392
+ }
608
1393
  NSInteger lower = (NSInteger)floor(progress);
609
1394
  NSInteger upper = MIN(lower + 1, count - 1);
610
1395
  CGFloat fraction = progress - lower;
@@ -614,14 +1399,35 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
614
1399
  CGRectGetMinX(fromFrame) + (CGRectGetMinX(toFrame) - CGRectGetMinX(fromFrame)) * fraction,
615
1400
  CGRectGetMinY(fromFrame),
616
1401
  CGRectGetWidth(fromFrame) + (CGRectGetWidth(toFrame) - CGRectGetWidth(fromFrame)) * fraction,
617
- _indicatorHeight
1402
+ _segmented ? CGRectGetHeight(fromFrame) : _indicatorHeight
618
1403
  );
1404
+ if (_pillVariant) {
1405
+ // Leading edge leads and trailing edge lags while moving between tabs.
1406
+ CGFloat leading = 1 - (1 - fraction) * (1 - fraction);
1407
+ CGFloat trailing = fraction * fraction;
1408
+ BOOL forward = CGRectGetMinX(toFrame) >= CGRectGetMinX(fromFrame);
1409
+ CGFloat left = CGRectGetMinX(fromFrame) + (CGRectGetMinX(toFrame) - CGRectGetMinX(fromFrame)) * (forward ? trailing : leading);
1410
+ CGFloat right = CGRectGetMaxX(fromFrame) + (CGRectGetMaxX(toFrame) - CGRectGetMaxX(fromFrame)) * (forward ? leading : trailing);
1411
+ indicatorFrame = CGRectMake(left, CGRectGetMinY(fromFrame), MAX(0, right - left), CGRectGetHeight(fromFrame));
1412
+ _indicatorView.layer.cornerRadius = CGRectGetHeight(indicatorFrame) / 2;
1413
+ }
619
1414
  _indicatorView.frame = indicatorFrame;
620
- _indicatorView.hidden = _indicatorHeight <= 0;
1415
+ _indicatorView.hidden = _textVariant || CGRectGetHeight(indicatorFrame) <= 0;
621
1416
 
622
1417
  NSInteger selectedIndex = (NSInteger)round(progress);
1418
+ if ([_config[@"controlled"] boolValue]) {
1419
+ NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
1420
+ selectedIndex = selected == NSNotFound ? -1 : (NSInteger)selected;
1421
+ }
1422
+ NSInteger fontOwnerIndex = [self visualFontOwnerIndex:selectedIndex];
1423
+ NSString *key = selectedIndex >= 0 && selectedIndex < count ? _items[selectedIndex][@"key"] : nil;
1424
+ [self updateToolbarForKey:key];
623
1425
  [_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
624
1426
  CGFloat emphasis = 1 - MIN(1, fabs(progress - index));
1427
+ if ([self->_config[@"controlled"] boolValue] && !snapToSelection) {
1428
+ emphasis = index == self->_progressSource ? 1 - self->_progressFraction : 0;
1429
+ if (index == self->_progressDestination) emphasis += self->_progressFraction;
1430
+ }
625
1431
  UIColor *color = RNCInterpolateColor(
626
1432
  self->_inactiveTextColor,
627
1433
  self->_activeTextColor,
@@ -629,12 +1435,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
629
1435
  self.traitCollection
630
1436
  );
631
1437
  [button setTitleColor:color forState:UIControlStateNormal];
1438
+ if (self->_textVariant) {
1439
+ button.titleLabel.font = index == fontOwnerIndex
1440
+ ? self.activeTabFont
1441
+ : self.tabFont;
1442
+ }
632
1443
  button.accessibilityTraits = index == selectedIndex
633
1444
  ? UIAccessibilityTraitButton | UIAccessibilityTraitSelected
634
1445
  : UIAccessibilityTraitButton;
635
1446
  }];
636
1447
 
637
- if (_shouldCenterSelectedItem && !_scrollView.tracking && !_scrollView.dragging &&
1448
+ if (_shouldCenterSelectedItem && !_segmented && !_scrollView.tracking && !_scrollView.dragging &&
638
1449
  !_scrollView.decelerating && CGRectGetWidth(_scrollView.bounds) > 0) {
639
1450
  CGFloat maximumOffset = MAX(0, _scrollView.contentSize.width - CGRectGetWidth(_scrollView.bounds));
640
1451
  CGFloat desiredOffset = RNCClamp(
@@ -1433,6 +2244,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1433
2244
  - (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)other { return YES; }
1434
2245
  @end
1435
2246
 
2247
+ @protocol RNCPagerPresentationProgressTarget <NSObject>
2248
+ - (void)sampleProgrammaticTabProgress:(CADisplayLink *)link;
2249
+ - (void)sampleToolbarSettlement:(CADisplayLink *)link;
2250
+ @end
2251
+
2252
+ @interface RNCPagerPresentationProgressProxy : NSObject
2253
+ @property (nonatomic, weak) id<RNCPagerPresentationProgressTarget> target;
2254
+ @property (nonatomic, assign) BOOL toolbarSettlement;
2255
+ @end
2256
+ @implementation RNCPagerPresentationProgressProxy
2257
+ - (void)tick:(CADisplayLink *)link {
2258
+ id<RNCPagerPresentationProgressTarget> target = self.target;
2259
+ if (target && self.toolbarSettlement) [target sampleToolbarSettlement:link];
2260
+ else if (target) [target sampleProgrammaticTabProgress:link];
2261
+ else [link invalidate];
2262
+ }
2263
+ @end
2264
+
1436
2265
  @interface RNCCollapsiblePagerViewComponentView () <
1437
2266
  RCTRNCCollapsiblePagerViewViewProtocol,
1438
2267
  UIPageViewControllerDataSource,
@@ -1441,33 +2270,57 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1441
2270
  UIGestureRecognizerDelegate,
1442
2271
  RCTMountingTransactionObserving,
1443
2272
  RNCNativeScrollerInsetCoordinator,
1444
- RNCPagerViewNestedOverlayObserver
2273
+ RNCPagerViewNestedOverlayObserver,
2274
+ RNCPagerPresentationProgressTarget
1445
2275
  >
2276
+ - (void)syncNativeToolbarState;
2277
+ - (void)cancelNativeToolbarSettlement;
2278
+ - (void)scheduleNativeToolbarSettlement;
1446
2279
  - (void)finishPagerScrollEmittingSelection:(BOOL)emitSelection;
2280
+ - (void)cancelPendingNativePagerScroll;
1447
2281
  - (void)completeTransitionOnNextRunLoopForGeneration:(NSUInteger)generation
1448
2282
  transition:(NSUInteger)transition;
1449
2283
  - (void)setDirectNativePagerEnabled:(BOOL)enabled;
1450
2284
  - (void)attachSharedHeadersToScrollView:(UIScrollView *)scrollView;
1451
2285
  - (void)liftSharedHeadersForPagerTransition:(NSString *)reason;
1452
2286
  - (void)restoreSharedHeadersToContainer;
2287
+ - (NSInteger)currentStickyHeaderHeight;
1453
2288
  - (void)layoutSharedHeaders;
2289
+ - (void)bringReservedStickyControlToFront;
1454
2290
  - (void)restorePinnedStickyHeader;
1455
2291
  - (void)updatePinnedStickyHeader;
1456
2292
  - (UIScrollView *)currentVerticalScrollViewForParentPager;
1457
2293
  - (UIScrollView *)verticalScrollViewForPageAtIndex:(NSInteger)pageIndex;
2294
+ - (RNCScrollCandidateResolution)resolveScrollCandidateForPageAtIndex:(NSInteger)pageIndex;
2295
+ - (RNCScrollCandidateResolution)resolveScrollCandidateInView:(UIView *)view;
1458
2296
  - (UIScrollView *)findExplicitNativeScrollerInView:(UIView *)view;
1459
2297
  - (UIScrollView *)findFabricScrollViewInView:(UIView *)view;
1460
2298
  - (UIScrollView *)findVerticalScrollViewInView:(UIView *)view;
2299
+ - (void)scheduleCoalescedScrollReconcile;
1461
2300
  - (void)scheduleScrollObserverRetryForCurrentPage;
1462
2301
  - (void)preparePageForHorizontalTransitionAtIndex:(NSInteger)pageIndex;
1463
2302
  - (void)updateSharedHeaderPressCancellationGesture;
1464
2303
  - (void)detachSharedHeaderPressCancellationGesture;
1465
2304
  - (void)updateRefreshControlForScrollView:(UIScrollView *)scrollView;
1466
2305
  - (void)releaseRefreshControlForScrollView:(UIScrollView *)scrollView;
2306
+ - (void)logHomeVisualGeometry:(NSString *)phase scrollView:(UIScrollView *)scrollView;
1467
2307
  - (void)cancelTopInsetReboundCheck;
1468
2308
  - (void)scheduleTopInsetReboundCheck;
1469
2309
  - (void)syncScrollEdgeAppearance;
1470
2310
  - (void)updateHardEdgeSeparatorCovers;
2311
+ - (void)updateTopOverlayThemeBackground;
2312
+ - (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay;
2313
+ - (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay;
2314
+ - (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay;
2315
+ - (RNCCollapsiblePagerTransitionEdgeOwner *)borrowedPinnedStickyOwner;
2316
+ - (void)releaseProgrammaticScrollEdge:(UIScrollView *)scrollView;
2317
+ - (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex;
2318
+ - (BOOL)layoutStandInScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner;
2319
+ - (void)layoutStandInScrollEdges;
2320
+ - (void)releaseProgrammaticScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner;
2321
+ - (void)clearProgrammaticScrollEdges;
2322
+ - (void)finishProgrammaticScrollEdges;
2323
+ - (BOOL)hasProgrammaticScrollEdgeForPage:(UIView *)page;
1471
2324
  - (void)updateScrollEdgeContentMasks;
1472
2325
  - (void)restoreScrollEdgeContentMasks;
1473
2326
  - (void)sharedHeaderPressCancellationGestureChanged:(UIPanGestureRecognizer *)recognizer;
@@ -1506,6 +2359,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1506
2359
  UILabel *_stickyEdgeMarker;
1507
2360
  CALayer *_topEdgeSeparatorCover;
1508
2361
  CALayer *_stickyEdgeSeparatorCover;
2362
+ CALayer *_topOverlayThemeBackgroundLayer;
1509
2363
  __weak UIView *_topEdgeInteractionHost;
1510
2364
  __weak UIView *_stickyEdgeInteractionHost;
1511
2365
  __weak UIScrollView *_topEdgeScrollView;
@@ -1517,6 +2371,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1517
2371
  NSInteger _pendingInitialPage;
1518
2372
  NSInteger _headerHeight;
1519
2373
  NSInteger _stickyHeaderHeight;
2374
+ NSArray *_stickyHeaderHeights;
1520
2375
  CGFloat _topOverlayHeight;
1521
2376
  NSInteger _externalTopOverlayTag;
1522
2377
  __weak UIView *_externalTopOverlayView;
@@ -1535,6 +2390,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1535
2390
  NSUInteger _pendingTopInsetReboundGeneration;
1536
2391
  NSTimer *_topInsetReboundTimer;
1537
2392
  CGFloat _nativeTabBarHeight;
2393
+ CGFloat _nativeTabBarTrailingReservedWidth;
1538
2394
  CGFloat _nativeSubHeaderHeight;
1539
2395
  CGFloat _headerOffset;
1540
2396
  BOOL _scrollEnabled;
@@ -1543,12 +2399,31 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1543
2399
  BOOL _nativeSmoothHeaderScrollEnabled;
1544
2400
  UIPanGestureRecognizer *_blockerGesture;
1545
2401
  BOOL _transitioning;
2402
+ BOOL _toolbarTransitionPending;
2403
+ CADisplayLink *_toolbarSettleDisplayLink;
2404
+ NSUInteger _toolbarSettleGeneration;
2405
+ NSUInteger _toolbarSettleTransition;
2406
+ NSInteger _toolbarSettlePage;
2407
+ CGFloat _toolbarSettleWidth;
2408
+ NSUInteger _toolbarSettleTicks;
2409
+ BOOL _toolbarSettleAttempted;
1546
2410
  BOOL _isPagerDragging;
1547
2411
  BOOL _directNativePagerEnabled;
1548
2412
  BOOL _pendingDirectNativePagerEnabled;
1549
2413
  BOOL _hasPendingDirectNativePagerChange;
1550
2414
  BOOL _hasReceivedPageCommand;
1551
2415
  NSUInteger _transitionId;
2416
+ void (^_pendingNativePagerScrollCompletion)(BOOL);
2417
+ NSUInteger _pendingNativePagerScrollGeneration;
2418
+ NSUInteger _pendingNativePagerScrollTransition;
2419
+ CGFloat _pendingNativePagerScrollTarget;
2420
+ CADisplayLink *_tabProgressDisplayLink;
2421
+ NSUInteger _tabProgressGeneration;
2422
+ NSUInteger _tabProgressTransition;
2423
+ CGFloat _tabProgressWidth;
2424
+ NSIndexSet *_programmaticPageMaskIndexes;
2425
+ NSMapTable<UIScrollView *, RNCCollapsiblePagerTransitionEdgeOwner *> *_programmaticScrollEdges;
2426
+ NSMutableArray<RNCCollapsiblePagerTransitionEdgeOwner *> *_programmaticScrollEdgeOwners;
1552
2427
  // OneKey patch: Retain the latest tab tap while an animation is in flight.
1553
2428
  NSInteger _pendingGoToIndex;
1554
2429
  BOOL _pendingGoToAnimated;
@@ -1576,6 +2451,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1576
2451
  NSMapTable<UIScrollView *, NSValue *> *_originalInsets;
1577
2452
  NSMapTable<UIScrollView *, UIRefreshControl *> *_managedRefreshControls;
1578
2453
  NSHashTable<UIScrollView *> *_refreshControlObservedScrollViews;
2454
+ CFTimeInterval _homeVisualLastScrollLog;
2455
+ CFTimeInterval _homeVisualLastLayoutLog;
2456
+ CFTimeInterval _homeVisualStartMono;
2457
+ NSString *_homeVisualLastGeometrySignature;
2458
+ CGFloat _homeVisualLastThemeOpacity;
2459
+ CFTimeInterval _homeVisualLastThemeLog;
2460
+ BOOL _homeVisualThemeHolding;
1579
2461
  NSMapTable<UIScrollView *, NSNumber *> *_appliedTopInsets;
1580
2462
  NSMapTable<UIScrollView *, NSValue *> *_originalIndicatorInsets;
1581
2463
  NSMapTable<UIScrollView *, NSNumber *> *_originalAlwaysBounceVertical;
@@ -1614,6 +2496,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1614
2496
  RNCCollapsiblePagerOuterPagerPanGestureRecognizer *_sharedHeaderOuterPagerGesture;
1615
2497
  RNCCollapsiblePagerVerticalPagerGuardGestureRecognizer *_verticalPagerGesture;
1616
2498
  BOOL _observingContentOffset;
2499
+ BOOL _awaitingScrollOwnerForCurrentPage;
2500
+ BOOL _scrollReconcileScheduled;
1617
2501
  BOOL _scrollResolveRetryScheduled;
1618
2502
  CFTimeInterval _pendingFallbackScrollViewDetectedAt;
1619
2503
  NSInteger _scrollResolveRetryPageIndex;
@@ -1645,6 +2529,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1645
2529
  _displayBodyOverrides = [NSMutableDictionary new];
1646
2530
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nativeListScrollCommandAccepted:)
1647
2531
  name:@"OneKeyNativeListScrollCommandAccepted" object:nil];
2532
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nativeScrollViewDidBecomeReadyNotification:)
2533
+ name:@"OneKeyNativeScrollViewDidBecomeReady" object:nil];
1648
2534
  _pendingPageRestoreKeys = [NSMutableSet new];
1649
2535
  _releasedPageScrollStates = [NSMutableDictionary new];
1650
2536
  _mountingRemovedScrollViews = [NSHashTable weakObjectsHashTable];
@@ -1714,6 +2600,23 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1714
2600
  });
1715
2601
  }
1716
2602
  };
2603
+ _nativeTabBarView.onToolbarNeedsSettlement = ^{
2604
+ __strong __typeof__(weakSelf) self = weakSelf;
2605
+ if (!self) return;
2606
+ NSUInteger generation = self->_generation;
2607
+ dispatch_async(dispatch_get_main_queue(), ^{
2608
+ if (self->_generation == generation) [self syncNativeToolbarState];
2609
+ });
2610
+ };
2611
+ _nativeTabBarView.onToolbarPress = ^(NSString *key, CGRect rect) {
2612
+ __strong __typeof__(weakSelf) self = weakSelf;
2613
+ if (!self || self->_isBeingRecycled) return;
2614
+ const auto emitter = [self eventEmitter];
2615
+ if (emitter) emitter->onNativeToolbarPress({
2616
+ .key = std::string(key.UTF8String ?: ""),
2617
+ .anchorRect = {.x = rect.origin.x, .y = rect.origin.y, .width = rect.size.width, .height = rect.size.height}
2618
+ });
2619
+ };
1717
2620
  [_sharedHeaderHostView addSubview:_nativeTabBarView];
1718
2621
 
1719
2622
  _nativeSubHeaderView = [RNCCollapsiblePagerNativeSubHeaderView new];
@@ -1774,11 +2677,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1774
2677
  if (hitView != nil && !sharedHeaderPointIsVisible &&
1775
2678
  (hitView == _sharedHeaderHostView ||
1776
2679
  [hitView isDescendantOfView:_sharedHeaderHostView])) return nil;
1777
- if (hitView != nil && _ownedPageMasks.count > 0 &&
2680
+ if (hitView != nil && (_ownedPageMasks.count > 0 || _programmaticScrollEdges.count > 0) &&
1778
2681
  [_containerView convertPoint:point fromView:self].y < _pageMaskBoundary) {
1779
2682
  for (UIView *page in _ownedPageMasks.keyEnumerator.allObjects) {
1780
2683
  if ([hitView isDescendantOfView:page]) return nil;
1781
2684
  }
2685
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdges.objectEnumerator) {
2686
+ if (owner.page != nil && [hitView isDescendantOfView:owner.page]) return nil;
2687
+ }
1782
2688
  }
1783
2689
  return hitView;
1784
2690
  }
@@ -1795,6 +2701,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1795
2701
  - (void)didMoveToWindow
1796
2702
  {
1797
2703
  [super didMoveToWindow];
2704
+ [self cancelNativeToolbarSettlement];
2705
+ if (self.window == nil) [self stopProgrammaticTabProgress];
2706
+ if (self.window == nil && _pendingNativePagerScrollCompletion != nil) {
2707
+ [self cancelPendingNativePagerScroll];
2708
+ _pagerScrollView.scrollEnabled = _scrollEnabled;
2709
+ [self finishPagerScrollEmittingSelection:NO];
2710
+ }
2711
+ [self syncNativeToolbarState];
1798
2712
  [self registerExternalOuterPager];
1799
2713
  BOOL externalHeightChanged = [self resolveExternalTopOverlay];
1800
2714
  if (self.window == nil) [self restoreScrollEdgeContentMasks];
@@ -1803,8 +2717,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1803
2717
  [self updateTopScrollEdgeForScrollView:_observedScrollView];
1804
2718
  [self updateSharedHeaderPressCancellationGesture];
1805
2719
  [self updateHeaderSettledStateForceBusy:NO];
2720
+ [self logHomeVisualGeometry:@"window" scrollView:_observedScrollView];
1806
2721
  for (UIScrollView *scrollView in _originalInsets.keyEnumerator) {
1807
- [self updateNativeScrollerViewport:scrollView stickyHeight:self.window == nil ? 0 : _stickyHeaderHeight + self.effectiveTopOverlayHeight];
2722
+ [self updateNativeScrollerViewport:scrollView stickyHeight:self.window == nil ? 0 : self.currentStickyHeaderHeight + self.effectiveTopOverlayHeight];
1808
2723
  }
1809
2724
  if (externalHeightChanged) [self reapplyInsetsToObservedScrollView];
1810
2725
  // OneKey patch: removing a decelerating page from its window can suppress
@@ -1830,7 +2745,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1830
2745
 
1831
2746
  - (CGFloat)effectiveTopOverlayHeight
1832
2747
  {
1833
- return _topOverlayView != nil ? _topOverlayHeight : _externalTopOverlayHeight;
2748
+ BOOL localOverlayPending = _topScrollEdgeEnabled && _topOverlayHeight > 0 &&
2749
+ _externalTopOverlayTag <= 0;
2750
+ return _topOverlayView != nil || localOverlayPending
2751
+ ? _topOverlayHeight : _externalTopOverlayHeight;
1834
2752
  }
1835
2753
 
1836
2754
  - (BOOL)hasFixedTopOverlay
@@ -1851,6 +2769,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1851
2769
  }
1852
2770
  }
1853
2771
  if (_externalOuterPager == outer) return;
2772
+ if (_topOverlayView == nil && _externalTopOverlayTag > 0) {
2773
+ [self clearProgrammaticScrollEdges];
2774
+ }
1854
2775
  [_externalOuterPager removeNestedOverlayObserver:self];
1855
2776
  _externalOuterPager = outer;
1856
2777
  _externalOuterPageActive = NO;
@@ -1882,6 +2803,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1882
2803
  }
1883
2804
  BOOL changed = _externalTopOverlayView != nextView ||
1884
2805
  fabs(_externalTopOverlayHeight - nextHeight) > 0.5;
2806
+ if (changed && _topOverlayView == nil && _externalTopOverlayTag > 0) {
2807
+ [self clearProgrammaticScrollEdges];
2808
+ }
1885
2809
  _externalTopOverlayView = nextView;
1886
2810
  _externalTopOverlayHeight = nextHeight;
1887
2811
  _topOverlayHostView.hidden = !self.hasFixedTopOverlay;
@@ -1893,9 +2817,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1893
2817
  {
1894
2818
  if (_isBeingRecycled || _externalOuterPager == nil || _externalTopOverlayTag <= 0) return;
1895
2819
  if (_externalOuterPageActive == active && _externalOuterTransitioning == transitioning) return;
2820
+ if ((transitioning || !active) && _topOverlayView == nil) {
2821
+ [self clearProgrammaticScrollEdges];
2822
+ }
1896
2823
  BOOL wasTransitioning = _externalOuterTransitioning;
1897
2824
  _externalOuterPageActive = active;
1898
2825
  _externalOuterTransitioning = transitioning;
2826
+ [self syncNativeToolbarState];
1899
2827
  if (transitioning && !wasTransitioning) {
1900
2828
  [self updateTopScrollEdgeForScrollView:nil];
1901
2829
  [self liftSharedHeadersForPagerTransition:@"outer"];
@@ -1913,6 +2841,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1913
2841
  [super traitCollectionDidChange:previousTraitCollection];
1914
2842
  if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) {
1915
2843
  [self syncScrollEdgeAppearance];
2844
+ [self updateTopOverlayThemeBackground];
2845
+ [self logHomeVisualGeometry:@"trait" scrollView:_observedScrollView];
1916
2846
  }
1917
2847
  }
1918
2848
 
@@ -1938,6 +2868,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1938
2868
 
1939
2869
  - (void)restoreScrollEdgeContentMasks
1940
2870
  {
2871
+ [self clearProgrammaticScrollEdges];
2872
+ _programmaticPageMaskIndexes = nil;
1941
2873
  if (_sharedHeaderHostView.maskView == _sharedHeaderMaskView) {
1942
2874
  _sharedHeaderHostView.maskView = _originalSharedHeaderMaskView;
1943
2875
  }
@@ -1956,12 +2888,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
1956
2888
 
1957
2889
  - (void)updateScrollEdgeContentMasks
1958
2890
  {
2891
+ [self layoutStandInScrollEdges];
1959
2892
  [self updateHardEdgeSeparatorCovers];
1960
2893
  BOOL enabled = _topScrollEdgeEnabled &&
1961
2894
  (self.hasFixedTopOverlay || _stickyHeaderView != nil) &&
1962
2895
  self.window != nil && !_isBeingRecycled;
1963
2896
  if (!enabled) {
1964
2897
  [self restoreScrollEdgeContentMasks];
2898
+ [self updateTopOverlayThemeBackground];
1965
2899
  return;
1966
2900
  }
1967
2901
  if (self.hasFixedTopOverlay && _sharedHeaderHostView.window == self.window &&
@@ -2001,11 +2935,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2001
2935
  _pageMaskBoundary = boundary;
2002
2936
  NSMutableSet<UIView *> *visiblePages = [NSMutableSet new];
2003
2937
  if (transitioning) {
2004
- for (UIViewController *controller in _pageControllers) {
2005
- UIView *page = controller.view;
2938
+ for (NSUInteger index = 0; index < _pageControllers.count; index++) {
2939
+ UIView *page = _pageControllers[index].view;
2940
+ BOOL programmaticParticipant = [_programmaticPageMaskIndexes containsIndex:index];
2941
+ if ([self hasProgrammaticScrollEdgeForPage:page]) continue;
2006
2942
  if (page.window != self.window ||
2007
- !CGRectIntersectsRect([page convertRect:page.bounds toView:_containerView],
2008
- _containerView.bounds)) continue;
2943
+ (!programmaticParticipant &&
2944
+ !CGRectIntersectsRect([page convertRect:page.bounds toView:_containerView],
2945
+ _containerView.bounds))) continue;
2009
2946
  [visiblePages addObject:page];
2010
2947
  UIView *mask = [_ownedPageMasks objectForKey:page];
2011
2948
  if (mask == nil) {
@@ -2017,8 +2954,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2017
2954
  }
2018
2955
  CGFloat localTop = [_containerView convertPoint:CGPointMake(0, boundary)
2019
2956
  toView:page].y;
2020
- mask.frame = CGRectMake(0, localTop, CGRectGetWidth(page.bounds),
2957
+ CGRect maskFrame = CGRectMake(0, localTop, CGRectGetWidth(page.bounds),
2021
2958
  MAX(0, CGRectGetHeight(page.bounds) - localTop));
2959
+ if (programmaticParticipant) {
2960
+ [UIView performWithoutAnimation:^{ mask.frame = maskFrame; }];
2961
+ } else {
2962
+ mask.frame = maskFrame;
2963
+ }
2022
2964
  }
2023
2965
  }
2024
2966
  for (UIView *page in _ownedPageMasks.keyEnumerator.allObjects) {
@@ -2031,6 +2973,102 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2031
2973
  [_ownedPageMasks removeObjectForKey:page];
2032
2974
  [_originalPageMasks removeObjectForKey:page];
2033
2975
  }
2976
+ [self updateTopOverlayThemeBackground];
2977
+ }
2978
+
2979
+ - (void)updateTopOverlayThemeBackground
2980
+ {
2981
+ if (@available(iOS 27.0, *)) {
2982
+ BOOL localHardOverlay = !_isBeingRecycled && _topScrollEdgeEnabled &&
2983
+ _topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
2984
+ _nativeSmoothHeaderScrollEnabled && _topOverlayView != nil &&
2985
+ _externalTopOverlayTag <= 0 && _topOverlayHeight > 0 && _headerHeight > 0 &&
2986
+ _topOverlayHostView.window == self.window && self.window != nil &&
2987
+ !CGRectIsEmpty(_topOverlayHostView.bounds);
2988
+ if (!localHardOverlay) {
2989
+ [_topOverlayThemeBackgroundLayer removeFromSuperlayer];
2990
+ _topOverlayThemeBackgroundLayer = nil;
2991
+ _homeVisualThemeHolding = NO;
2992
+ return;
2993
+ }
2994
+
2995
+ UIColor *color = nil;
2996
+ for (UIView *view = self; view != nil; view = view.superview) {
2997
+ UIColor *candidate = [view.backgroundColor resolvedColorWithTraitCollection:
2998
+ _topOverlayHostView.traitCollection];
2999
+ if (candidate != nil && CGColorGetAlpha(candidate.CGColor) >= 1) {
3000
+ color = candidate;
3001
+ break;
3002
+ }
3003
+ }
3004
+ if (color == nil) {
3005
+ [_topOverlayThemeBackgroundLayer removeFromSuperlayer];
3006
+ _topOverlayThemeBackgroundLayer = nil;
3007
+ return;
3008
+ }
3009
+
3010
+ UIScrollView *scrollView = _observedScrollView;
3011
+ BOOL geometryReady = scrollView != nil &&
3012
+ _sharedHeaderScrollView == scrollView && _topEdgeScrollView == scrollView &&
3013
+ _topEdgeInteraction.scrollView == scrollView &&
3014
+ scrollView.topEdgeEffect.style == UIScrollEdgeEffectStyle.hardStyle &&
3015
+ _sharedHeaderMaskView != nil &&
3016
+ _sharedHeaderHostView.maskView == _sharedHeaderMaskView &&
3017
+ _headerView.window == self.window;
3018
+ if (_topOverlayThemeBackgroundLayer == nil && !geometryReady) return;
3019
+ BOOL created = _topOverlayThemeBackgroundLayer == nil;
3020
+ if (created) {
3021
+ _topOverlayThemeBackgroundLayer = [CALayer layer];
3022
+ _topOverlayThemeBackgroundLayer.name = @"onekey-top-overlay-theme-background";
3023
+ _topOverlayThemeBackgroundLayer.actions = @{
3024
+ @"position": NSNull.null, @"bounds": NSNull.null,
3025
+ @"opacity": NSNull.null, @"backgroundColor": NSNull.null
3026
+ };
3027
+ [_topOverlayHostView.layer insertSublayer:_topOverlayThemeBackgroundLayer atIndex:0];
3028
+ }
3029
+ _topOverlayThemeBackgroundLayer.frame = _topOverlayHostView.bounds;
3030
+ _topOverlayThemeBackgroundLayer.backgroundColor = color.CGColor;
3031
+ if (!geometryReady) {
3032
+ if (!_homeVisualThemeHolding) {
3033
+ _homeVisualThemeHolding = YES;
3034
+ #if DEBUG
3035
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
3036
+ @"[IOS-HOME-VISUAL] phase=theme-background-hold pagerTag=%ld generation=%lu pageIndex=%ld opacity=%.3f",
3037
+ (long)self.tag, (unsigned long)_generation, (long)_currentIndex,
3038
+ _topOverlayThemeBackgroundLayer.opacity]);
3039
+ #endif
3040
+ }
3041
+ return;
3042
+ }
3043
+ _homeVisualThemeHolding = NO;
3044
+ CGRect overlayWindow = [_topOverlayHostView convertRect:_topOverlayHostView.bounds
3045
+ toView:self.window];
3046
+ CGRect headerWindow = [_headerView convertRect:_headerView.bounds
3047
+ toView:self.window];
3048
+ CGFloat overlayBottom = CGRectGetMaxY(overlayWindow);
3049
+ CGFloat collapse = MIN(MAX(overlayBottom - CGRectGetMinY(headerWindow), 0),
3050
+ _headerHeight);
3051
+ CGFloat opacity = 1 - collapse / _headerHeight;
3052
+ _topOverlayThemeBackgroundLayer.opacity = opacity;
3053
+ #if DEBUG
3054
+ CFTimeInterval now = CACurrentMediaTime();
3055
+ if (created || fabs(opacity - _homeVisualLastThemeOpacity) >= 0.1 ||
3056
+ now - _homeVisualLastThemeLog >= 2.0) {
3057
+ _homeVisualLastThemeOpacity = opacity;
3058
+ _homeVisualLastThemeLog = now;
3059
+ CGFloat red = 0, green = 0, blue = 0, alpha = 0;
3060
+ [color getRed:&red green:&green blue:&blue alpha:&alpha];
3061
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
3062
+ @"[IOS-HOME-VISUAL] phase=theme-background epochMs=%.0f monoMs=%.0f pagerTag=%ld generation=%lu pageIndex=%ld opacity=%.3f collapse=%.1f header=%.1f overlayBottom=%.1f headerY=%.1f bodyYEstimate=%.1f hardOwner=%d rgba=%.3f,%.3f,%.3f,%.3f",
3063
+ NSDate.date.timeIntervalSince1970 * 1000, now * 1000,
3064
+ (long)self.tag, (unsigned long)_generation, (long)_currentIndex,
3065
+ opacity, collapse, (CGFloat)_headerHeight, overlayBottom,
3066
+ CGRectGetMinY(headerWindow), overlayBottom + _headerHeight +
3067
+ self.currentStickyHeaderHeight - collapse, _topEdgeInteraction.scrollView == scrollView,
3068
+ red, green, blue, alpha]);
3069
+ }
3070
+ #endif
3071
+ }
2034
3072
  }
2035
3073
 
2036
3074
  - (void)updateEventEmitter:(const EventEmitter::Shared &)eventEmitter
@@ -2049,10 +3087,444 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2049
3087
  emitter->onScrollEdgeCapability({.available = (bool)available});
2050
3088
  }
2051
3089
 
3090
+ - (RNCCollapsiblePagerTransitionEdgeOwner *)borrowedPinnedStickyOwner
3091
+ {
3092
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
3093
+ if (owner.borrowsPinnedStickyHost) return owner;
3094
+ }
3095
+ return nil;
3096
+ }
3097
+
3098
+ - (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay
3099
+ {
3100
+ if (@available(iOS 27.0, *)) {
3101
+ if (!_directNativePagerEnabled || !_topScrollEdgeEnabled ||
3102
+ !_nativeSmoothHeaderScrollEnabled ||
3103
+ _topScrollEdgeEffect != RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard ||
3104
+ self.window == nil || _isBeingRecycled) return NO;
3105
+ if (_topOverlayView != nil && _externalTopOverlayTag <= 0) return YES;
3106
+ return allowExternalOverlay && _topOverlayView == nil && _externalTopOverlayTag > 0 &&
3107
+ _externalTopOverlayView.window == self.window && _externalTopOverlayHeight > 0 &&
3108
+ _topOverlayHostView.window == self.window && !_topOverlayHostView.hidden &&
3109
+ (_externalOuterPager == nil || (_externalOuterPageActive && !_externalOuterTransitioning));
3110
+ }
3111
+ return NO;
3112
+ }
3113
+
3114
+ - (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay
3115
+ {
3116
+ if (@available(iOS 27.0, *)) {
3117
+ UIScrollView *source = _observedScrollView;
3118
+ if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay] ||
3119
+ source == nil || source != _topEdgeScrollView ||
3120
+ _topEdgeInteraction == nil || _topEdgeInteraction.scrollView != source ||
3121
+ _currentIndex < 0 || _currentIndex >= _pageControllers.count) return;
3122
+
3123
+ RNCCollapsiblePagerTransitionEdgeOwner *existing =
3124
+ [_programmaticScrollEdges objectForKey:source];
3125
+ if (existing != nil && existing.topInteraction.scrollView == source) return;
3126
+ if (existing != nil) [self releaseProgrammaticScrollEdgeOwner:existing];
3127
+ if (_programmaticScrollEdges == nil) {
3128
+ _programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
3129
+ _programmaticScrollEdgeOwners = [NSMutableArray new];
3130
+ }
3131
+ RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
3132
+ owner.scrollView = source;
3133
+ owner.page = _pageControllers[_currentIndex].view;
3134
+ owner.originalStyle = _originalTopEdgeStyle;
3135
+ owner.topInteraction = _topEdgeInteraction;
3136
+ owner.topHost = _topEdgeInteractionHost;
3137
+ owner.topMarker = _topEdgeMarker;
3138
+ owner.stickyInteraction = _stickyEdgeInteraction;
3139
+ owner.stickyHost = _stickyEdgeInteractionHost;
3140
+ owner.stickyMarker = _stickyEdgeMarker;
3141
+ owner.borrowsPinnedStickyHost = _stickyHeaderIsPinned &&
3142
+ owner.stickyHost == _pinnedStickyHostView &&
3143
+ owner.stickyInteraction.scrollView == source;
3144
+ [_programmaticScrollEdges setObject:owner forKey:source];
3145
+ [_programmaticScrollEdgeOwners addObject:owner];
3146
+
3147
+ // Transfer ownership without detaching UIKit's existing edge resources.
3148
+ _topEdgeInteraction = nil;
3149
+ _stickyEdgeInteraction = nil;
3150
+ _topEdgeMarker = nil;
3151
+ _stickyEdgeMarker = nil;
3152
+ _topEdgeInteractionHost = nil;
3153
+ _stickyEdgeInteractionHost = nil;
3154
+ _topEdgeScrollView = nil;
3155
+ _originalTopEdgeStyle = nil;
3156
+ }
3157
+ }
3158
+
3159
+ - (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay
3160
+ {
3161
+ if (@available(iOS 27.0, *)) {
3162
+ if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay]) return;
3163
+ if (_programmaticScrollEdges == nil) {
3164
+ _programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
3165
+ _programmaticScrollEdgeOwners = [NSMutableArray new];
3166
+ }
3167
+ NSInteger first = MIN(_currentIndex, index);
3168
+ NSInteger last = MAX(_currentIndex, index);
3169
+ for (NSInteger pageIndex = first; pageIndex <= last; pageIndex++) {
3170
+ [self preparePageForHorizontalTransitionAtIndex:pageIndex];
3171
+ UIScrollView *scrollView = [self verticalScrollViewForPageAtIndex:pageIndex];
3172
+ // A list that is not mounted yet, not laid out under the bars, or not
3173
+ // scrolled past its top cannot render the edge effect behind the bars.
3174
+ BOOL coversBars = scrollView != nil && scrollView.window == self.window &&
3175
+ [scrollView convertPoint:CGPointZero toView:_containerView].y <=
3176
+ [_pageControllers[pageIndex].view convertPoint:CGPointZero toView:_containerView].y + 0.5 &&
3177
+ scrollView.contentOffset.y + scrollView.adjustedContentInset.top > 0.5;
3178
+ // The stand-in applies only while the sticky header is pinned; otherwise
3179
+ // keep the temporary interaction on the page's own list.
3180
+ if (!coversBars && pageIndex != _currentIndex &&
3181
+ [self beginStandInScrollEdgeForPageAtIndex:pageIndex]) {
3182
+ continue;
3183
+ }
3184
+ if (scrollView == nil || scrollView.window != self.window) continue;
3185
+ if ([_programmaticScrollEdges objectForKey:scrollView] != nil) continue;
3186
+ RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
3187
+ owner.scrollView = scrollView;
3188
+ owner.page = _pageControllers[pageIndex].view;
3189
+ owner.originalStyle = scrollView.topEdgeEffect.style;
3190
+ scrollView.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle;
3191
+ UILabel *(^markerForHost)(UIView *) = ^UILabel *(UIView *host) {
3192
+ UILabel *marker = [UILabel new];
3193
+ marker.frame = host.bounds;
3194
+ marker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
3195
+ marker.text = @" ";
3196
+ marker.textColor = UIColor.clearColor;
3197
+ marker.backgroundColor = UIColor.clearColor;
3198
+ marker.userInteractionEnabled = NO;
3199
+ marker.isAccessibilityElement = NO;
3200
+ marker.accessibilityElementsHidden = YES;
3201
+ [host addSubview:marker];
3202
+ return marker;
3203
+ };
3204
+ owner.ownsTransitionHosts = pageIndex != _currentIndex;
3205
+ UIView *(^transitionHost)(UIView *) = ^UIView *(UIView *referenceHost) {
3206
+ CGRect frame = [referenceHost convertRect:referenceHost.bounds toView:owner.page];
3207
+ CGRect viewport = [scrollView convertRect:scrollView.bounds toView:owner.page];
3208
+ frame.origin.x = CGRectGetMinX(viewport);
3209
+ UIView *host = [[UIView alloc] initWithFrame:frame];
3210
+ host.autoresizingMask = UIViewAutoresizingFlexibleWidth;
3211
+ host.userInteractionEnabled = NO;
3212
+ host.accessibilityElementsHidden = YES;
3213
+ [owner.page addSubview:host];
3214
+ return host;
3215
+ };
3216
+ if (owner.ownsTransitionHosts) {
3217
+ owner.ownedTopHost = transitionHost(_topOverlayHostView);
3218
+ owner.topHost = owner.ownedTopHost;
3219
+ } else {
3220
+ owner.topHost = _topOverlayHostView;
3221
+ }
3222
+ owner.topMarker = markerForHost(owner.topHost);
3223
+ owner.topInteraction = [UIScrollEdgeElementContainerInteraction new];
3224
+ owner.topInteraction.edge = UIRectEdgeTop;
3225
+ owner.topInteraction.scrollView = scrollView;
3226
+ [owner.topHost addInteraction:owner.topInteraction];
3227
+ if (_stickyHeaderView != nil && _headerOffset >= _headerHeight - 0.5) {
3228
+ if (owner.ownsTransitionHosts) {
3229
+ owner.ownedStickyHost = transitionHost(_stickyHeaderView);
3230
+ owner.stickyHost = owner.ownedStickyHost;
3231
+ } else {
3232
+ owner.stickyHost = _stickyHeaderView;
3233
+ }
3234
+ owner.stickyMarker = markerForHost(owner.stickyHost);
3235
+ owner.stickyInteraction = [UIScrollEdgeElementContainerInteraction new];
3236
+ owner.stickyInteraction.edge = UIRectEdgeTop;
3237
+ owner.stickyInteraction.scrollView = scrollView;
3238
+ [owner.stickyHost addInteraction:owner.stickyInteraction];
3239
+ }
3240
+ [_programmaticScrollEdges setObject:owner forKey:scrollView];
3241
+ [_programmaticScrollEdgeOwners addObject:owner];
3242
+ }
3243
+ [self updateScrollEdgeContentMasks];
3244
+ }
3245
+ }
3246
+
3247
+ - (void)releaseProgrammaticScrollEdge:(UIScrollView *)scrollView
3248
+ {
3249
+ if (scrollView == nil) return;
3250
+ [self releaseProgrammaticScrollEdgeOwner:[_programmaticScrollEdges objectForKey:scrollView]];
3251
+ }
3252
+
3253
+ - (void)releaseProgrammaticScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner
3254
+ {
3255
+ if (@available(iOS 26.0, *)) {
3256
+ if (owner == nil) return;
3257
+ UIScrollView *scrollView = owner.scrollView;
3258
+ [owner.topHost removeInteraction:owner.topInteraction];
3259
+ owner.topInteraction.scrollView = nil;
3260
+ [owner.stickyHost removeInteraction:owner.stickyInteraction];
3261
+ owner.stickyInteraction.scrollView = nil;
3262
+ [owner.topMarker removeFromSuperview];
3263
+ [owner.stickyMarker removeFromSuperview];
3264
+ [owner.standInScrollView removeFromSuperview];
3265
+ owner.standInScrollView = nil;
3266
+ if (owner.ownsTransitionHosts) {
3267
+ [owner.ownedTopHost removeFromSuperview];
3268
+ [owner.ownedStickyHost removeFromSuperview];
3269
+ owner.ownedTopHost = nil;
3270
+ owner.ownedStickyHost = nil;
3271
+ }
3272
+ scrollView.topEdgeEffect.style = owner.originalStyle;
3273
+ if (owner.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
3274
+ (_pinnedStickyHostView.superview == scrollView ||
3275
+ _pinnedStickyHostView.superview == nil)) {
3276
+ _pinnedStickyHostView.hidden = YES;
3277
+ _pinnedStickyHostView.layer.zPosition = 0;
3278
+ [_containerView addSubview:_pinnedStickyHostView];
3279
+ }
3280
+ if (scrollView != nil) [_programmaticScrollEdges removeObjectForKey:scrollView];
3281
+ [_programmaticScrollEdgeOwners removeObjectIdenticalTo:owner];
3282
+ }
3283
+ }
3284
+
3285
+ - (void)clearProgrammaticScrollEdges
3286
+ {
3287
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners.copy) {
3288
+ [self releaseProgrammaticScrollEdgeOwner:owner];
3289
+ }
3290
+ _programmaticScrollEdges = nil;
3291
+ _programmaticScrollEdgeOwners = nil;
3292
+ }
3293
+
3294
+ - (void)finishProgrammaticScrollEdges
3295
+ {
3296
+ if (_programmaticScrollEdgeOwners.count == 0) return;
3297
+ // OneKey patch: keep the destination's transitional edge alive until the
3298
+ // settled interaction exists, so UIKit does not fade the edge effect back in.
3299
+ UIScrollView *settled = _observedScrollView;
3300
+ RNCCollapsiblePagerTransitionEdgeOwner *handoff =
3301
+ settled != nil ? [_programmaticScrollEdges objectForKey:settled] : nil;
3302
+ if (handoff != nil) {
3303
+ [_programmaticScrollEdges removeObjectForKey:settled];
3304
+ [_programmaticScrollEdgeOwners removeObjectIdenticalTo:handoff];
3305
+ }
3306
+ [self clearProgrammaticScrollEdges];
3307
+ if (@available(iOS 26.0, *)) {
3308
+ // A cancelled drag settles on the page whose settled edge was adopted.
3309
+ // Return that interaction as-is: a second container interaction for the
3310
+ // same scroll view and host would be torn down together with the old one.
3311
+ if (handoff != nil && !handoff.ownsTransitionHosts && _topEdgeInteraction == nil &&
3312
+ handoff.topHost == _topOverlayHostView &&
3313
+ handoff.topInteraction.scrollView == settled) {
3314
+ _topEdgeInteraction = handoff.topInteraction;
3315
+ _topEdgeInteractionHost = handoff.topHost;
3316
+ _topEdgeMarker = handoff.topMarker;
3317
+ _topEdgeScrollView = settled;
3318
+ _originalTopEdgeStyle = handoff.originalStyle;
3319
+ if (handoff.stickyInteraction != nil && handoff.stickyHost != nil &&
3320
+ handoff.stickyInteraction.scrollView == settled) {
3321
+ _stickyEdgeInteraction = handoff.stickyInteraction;
3322
+ _stickyEdgeInteractionHost = handoff.stickyHost;
3323
+ _stickyEdgeMarker = handoff.stickyMarker;
3324
+ } else {
3325
+ [handoff.stickyHost removeInteraction:handoff.stickyInteraction];
3326
+ handoff.stickyInteraction.scrollView = nil;
3327
+ [handoff.stickyMarker removeFromSuperview];
3328
+ }
3329
+ if (handoff.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
3330
+ (_pinnedStickyHostView.superview == settled ||
3331
+ _pinnedStickyHostView.superview == nil)) {
3332
+ _pinnedStickyHostView.hidden = YES;
3333
+ _pinnedStickyHostView.layer.zPosition = 0;
3334
+ [_containerView addSubview:_pinnedStickyHostView];
3335
+ }
3336
+ [self updateTopScrollEdgeForScrollView:settled];
3337
+ return;
3338
+ }
3339
+ }
3340
+ [self updateTopScrollEdgeForScrollView:settled];
3341
+ if (handoff == nil) return;
3342
+ if (@available(iOS 26.0, *)) {
3343
+ if (_topEdgeScrollView == settled && settled != nil) {
3344
+ _originalTopEdgeStyle = handoff.originalStyle;
3345
+ handoff.originalStyle = settled.topEdgeEffect.style;
3346
+ }
3347
+ }
3348
+ if (handoff.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
3349
+ (_pinnedStickyHostView.superview == settled ||
3350
+ _pinnedStickyHostView.superview == nil)) {
3351
+ _pinnedStickyHostView.hidden = YES;
3352
+ _pinnedStickyHostView.layer.zPosition = 0;
3353
+ [_containerView addSubview:_pinnedStickyHostView];
3354
+ }
3355
+ handoff.borrowsPinnedStickyHost = NO;
3356
+ // The caller reattaches the shared header in this run loop turn; drop the
3357
+ // transitional resources on the next one, after the header is rendered.
3358
+ dispatch_async(dispatch_get_main_queue(), ^{
3359
+ if (@available(iOS 26.0, *)) {
3360
+ [handoff.topHost removeInteraction:handoff.topInteraction];
3361
+ [handoff.stickyHost removeInteraction:handoff.stickyInteraction];
3362
+ if (handoff.topInteraction.scrollView == handoff.scrollView) {
3363
+ handoff.topInteraction.scrollView = nil;
3364
+ }
3365
+ if (handoff.stickyInteraction.scrollView == handoff.scrollView) {
3366
+ handoff.stickyInteraction.scrollView = nil;
3367
+ }
3368
+ }
3369
+ [handoff.topMarker removeFromSuperview];
3370
+ [handoff.stickyMarker removeFromSuperview];
3371
+ if (handoff.ownsTransitionHosts) {
3372
+ [handoff.ownedTopHost removeFromSuperview];
3373
+ [handoff.ownedStickyHost removeFromSuperview];
3374
+ }
3375
+ });
3376
+ }
3377
+
3378
+ - (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex
3379
+ {
3380
+ // OneKey patch: a page whose list is not mounted yet has no scroll view to
3381
+ // own an edge effect, so its masked top shows the bare background. An empty
3382
+ // stand-in scroll view resting past its top edge renders the same Hard
3383
+ // material (the settled header is masked out under the overlay as well).
3384
+ if (@available(iOS 27.0, *)) {
3385
+ if (pageIndex == _currentIndex || pageIndex < 0 ||
3386
+ pageIndex >= (NSInteger)_pageControllers.count) return NO;
3387
+ UIView *page = _pageControllers[pageIndex].view;
3388
+ UIView *container = page.superview;
3389
+ if (page.window != self.window || container == nil ||
3390
+ _stickyHeaderView == nil || _headerHeight <= 0 ||
3391
+ _headerOffset < _headerHeight - 0.5) return NO;
3392
+ for (RNCCollapsiblePagerTransitionEdgeOwner *existing in _programmaticScrollEdgeOwners) {
3393
+ if (existing.page == page) return YES;
3394
+ }
3395
+ CGFloat boundary = self.effectiveTopOverlayHeight + self.currentStickyHeaderHeight;
3396
+ CGFloat pageTop = [page convertPoint:CGPointZero toView:_containerView].y;
3397
+ if (boundary - pageTop <= 0 || CGRectGetWidth(page.bounds) <= 0) return NO;
3398
+ UIScrollView *standIn = [UIScrollView new];
3399
+ standIn.userInteractionEnabled = NO;
3400
+ standIn.scrollsToTop = NO;
3401
+ standIn.showsVerticalScrollIndicator = NO;
3402
+ standIn.showsHorizontalScrollIndicator = NO;
3403
+ standIn.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
3404
+ standIn.backgroundColor = UIColor.clearColor;
3405
+ standIn.accessibilityElementsHidden = YES;
3406
+ standIn.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle;
3407
+ [container insertSubview:standIn aboveSubview:page];
3408
+
3409
+ RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
3410
+ owner.scrollView = standIn;
3411
+ owner.page = page;
3412
+ owner.standInScrollView = standIn;
3413
+ owner.originalStyle = UIScrollEdgeEffectStyle.hardStyle;
3414
+ owner.ownsTransitionHosts = YES;
3415
+ UIView *(^host)(void) = ^UIView *(void) {
3416
+ UIView *view = [UIView new];
3417
+ view.userInteractionEnabled = NO;
3418
+ view.accessibilityElementsHidden = YES;
3419
+ [container insertSubview:view aboveSubview:standIn];
3420
+ UILabel *marker = [UILabel new];
3421
+ marker.frame = view.bounds;
3422
+ marker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
3423
+ marker.text = @" ";
3424
+ marker.textColor = UIColor.clearColor;
3425
+ marker.backgroundColor = UIColor.clearColor;
3426
+ marker.isAccessibilityElement = NO;
3427
+ [view addSubview:marker];
3428
+ return view;
3429
+ };
3430
+ owner.ownedTopHost = host();
3431
+ owner.topHost = owner.ownedTopHost;
3432
+ owner.topInteraction = [UIScrollEdgeElementContainerInteraction new];
3433
+ owner.topInteraction.edge = UIRectEdgeTop;
3434
+ owner.topInteraction.scrollView = standIn;
3435
+ [owner.topHost addInteraction:owner.topInteraction];
3436
+ owner.ownedStickyHost = host();
3437
+ owner.stickyHost = owner.ownedStickyHost;
3438
+ owner.stickyInteraction = [UIScrollEdgeElementContainerInteraction new];
3439
+ owner.stickyInteraction.edge = UIRectEdgeTop;
3440
+ owner.stickyInteraction.scrollView = standIn;
3441
+ [owner.stickyHost addInteraction:owner.stickyInteraction];
3442
+ if (_programmaticScrollEdges == nil) {
3443
+ _programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
3444
+ _programmaticScrollEdgeOwners = [NSMutableArray new];
3445
+ }
3446
+ [self layoutStandInScrollEdgeOwner:owner];
3447
+ [_programmaticScrollEdges setObject:owner forKey:standIn];
3448
+ [_programmaticScrollEdgeOwners addObject:owner];
3449
+ return YES;
3450
+ }
3451
+ return NO;
3452
+ }
3453
+
3454
+ // Stand-ins live in the pager container rather than inside their page, so they
3455
+ // do not follow page or header geometry on their own. Recompute them from the
3456
+ // current page origin and overlay + sticky boundary on every layout pass.
3457
+ - (BOOL)layoutStandInScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner
3458
+ {
3459
+ UIScrollView *standIn = owner.standInScrollView;
3460
+ UIView *page = owner.page;
3461
+ UIView *container = standIn.superview;
3462
+ BOOL valid = standIn != nil && page != nil && container != nil &&
3463
+ page.superview == container && _containerView != nil;
3464
+ CGFloat width = valid ? CGRectGetWidth(page.bounds) : 0;
3465
+ CGFloat height = 0;
3466
+ CGPoint origin = CGPointZero;
3467
+ if (valid) {
3468
+ CGFloat boundary = self.effectiveTopOverlayHeight + self.currentStickyHeaderHeight;
3469
+ height = boundary - [page convertPoint:CGPointZero toView:_containerView].y;
3470
+ origin = [page convertPoint:CGPointZero toView:container];
3471
+ valid = width > 0 && height > 0;
3472
+ }
3473
+ standIn.hidden = !valid;
3474
+ owner.ownedTopHost.hidden = !valid;
3475
+ owner.ownedStickyHost.hidden = !valid;
3476
+ if (!valid) return NO;
3477
+ CGRect frame = CGRectMake(origin.x, origin.y, width, height);
3478
+ if (!CGRectEqualToRect(standIn.frame, frame)) standIn.frame = frame;
3479
+ // Rest past the top edge so UIKit draws the edge material.
3480
+ CGFloat scrolled = MAX(_headerHeight, 1);
3481
+ CGSize contentSize = CGSizeMake(width, scrolled + height + 1);
3482
+ if (!CGSizeEqualToSize(standIn.contentSize, contentSize)) standIn.contentSize = contentSize;
3483
+ if (standIn.contentOffset.y != scrolled) standIn.contentOffset = CGPointMake(0, scrolled);
3484
+ void (^place)(UIView *, UIView *) = ^(UIView *host, UIView *reference) {
3485
+ if (host == nil) return;
3486
+ CGRect hostFrame = reference != nil
3487
+ ? [reference convertRect:reference.bounds toView:container] : CGRectZero;
3488
+ hostFrame.origin.x = origin.x;
3489
+ hostFrame.size.width = width;
3490
+ if (!CGRectEqualToRect(host.frame, hostFrame)) host.frame = hostFrame;
3491
+ };
3492
+ place(owner.ownedTopHost, _topOverlayHostView);
3493
+ place(owner.ownedStickyHost, _stickyHeaderView);
3494
+ return YES;
3495
+ }
3496
+
3497
+ - (void)layoutStandInScrollEdges
3498
+ {
3499
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
3500
+ if (owner.standInScrollView != nil) [self layoutStandInScrollEdgeOwner:owner];
3501
+ }
3502
+ }
3503
+
3504
+ - (BOOL)hasProgrammaticScrollEdgeForPage:(UIView *)page
3505
+ {
3506
+ if (@available(iOS 26.0, *)) {
3507
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdges.objectEnumerator) {
3508
+ if (owner.page == page && owner.standInScrollView == nil &&
3509
+ owner.scrollView.window == self.window &&
3510
+ owner.topInteraction.scrollView == owner.scrollView) return YES;
3511
+ }
3512
+ }
3513
+ return NO;
3514
+ }
3515
+
2052
3516
  - (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView
2053
3517
  {
2054
3518
  [self syncScrollEdgeAppearance];
2055
3519
  if (@available(iOS 26.0, *)) {
3520
+ if (_programmaticScrollEdgeOwners.count > 0 &&
3521
+ ![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:YES]) {
3522
+ [self clearProgrammaticScrollEdges];
3523
+ }
3524
+ if (scrollView != nil && [_programmaticScrollEdges objectForKey:scrollView] != nil) {
3525
+ [self updateScrollEdgeContentMasks];
3526
+ return;
3527
+ }
2056
3528
  if (_pendingTopOverlayAppearanceCommit) scrollView = nil;
2057
3529
  BOOL externalOwnerReady = _externalTopOverlayTag <= 0 ||
2058
3530
  _externalOuterPager == nil ||
@@ -2147,10 +3619,22 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2147
3619
 
2148
3620
  - (void)updateHardEdgeSeparatorCovers
2149
3621
  {
3622
+ // OneKey patch: transitional edge owners draw the same Hard hairline while
3623
+ // the settled interaction is detached, so keep the covers during transitions.
3624
+ BOOL transitional = _programmaticScrollEdgeOwners.count > 0;
2150
3625
  BOOL enabled = _topScrollEdgeEnabled &&
2151
3626
  _topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
2152
- _topEdgeScrollView != nil && self.window != nil && !_isBeingRecycled;
3627
+ (_topEdgeScrollView != nil || transitional) && self.window != nil && !_isBeingRecycled;
2153
3628
  if (!enabled && _topEdgeSeparatorCover == nil && _stickyEdgeSeparatorCover == nil) return;
3629
+ BOOL transitionalSticky = NO;
3630
+ if (transitional && _topEdgeScrollView == nil) {
3631
+ for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
3632
+ if (owner.stickyInteraction != nil) {
3633
+ transitionalSticky = YES;
3634
+ break;
3635
+ }
3636
+ }
3637
+ }
2154
3638
  UIColor *color = nil;
2155
3639
  for (UIView *view = self; view != nil; view = view.superview) {
2156
3640
  UIColor *candidate = [view.backgroundColor resolvedColorWithTraitCollection:
@@ -2164,7 +3648,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2164
3648
  _topOverlayHostView.traitCollection];
2165
3649
  CGFloat scale = self.window.screen.scale ?: self.traitCollection.displayScale;
2166
3650
  CGFloat pixel = 1.0 / MAX(1, scale);
2167
- UIView *hosts[] = {_topEdgeInteractionHost, _stickyEdgeInteractionHost};
3651
+ UIView *topHost = _topEdgeInteractionHost;
3652
+ UIView *stickyHost = _stickyEdgeInteractionHost;
3653
+ if (_topEdgeScrollView == nil && transitional) {
3654
+ topHost = _topOverlayHostView;
3655
+ stickyHost = transitionalSticky ? _stickyHeaderView : nil;
3656
+ }
3657
+ UIView *hosts[] = {topHost, stickyHost};
2168
3658
  CALayer *covers[] = {_topEdgeSeparatorCover, _stickyEdgeSeparatorCover};
2169
3659
  for (NSInteger index = 0; index < 2; index++) {
2170
3660
  UIView *host = hosts[index];
@@ -2187,6 +3677,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2187
3677
  CGRectGetWidth(_containerView.bounds), pixel);
2188
3678
  cover.contentsScale = scale;
2189
3679
  cover.backgroundColor = color.CGColor;
3680
+ cover.hidden = index == 0 && (_stickyHeaderIsPinned || transitionalSticky);
2190
3681
  }
2191
3682
  if (index == 0) _topEdgeSeparatorCover = cover;
2192
3683
  else _stickyEdgeSeparatorCover = cover;
@@ -2195,9 +3686,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2195
3686
 
2196
3687
  - (void)dealloc
2197
3688
  {
3689
+ [self cancelNativeToolbarSettlement];
3690
+ [self stopProgrammaticTabProgress];
3691
+ [self clearProgrammaticScrollEdges];
2198
3692
  [self updateTopScrollEdgeForScrollView:nil];
2199
3693
  [self cancelHeaderSettledCheck];
2200
3694
  [[NSNotificationCenter defaultCenter] removeObserver:self name:@"OneKeyNativeListScrollCommandAccepted" object:nil];
3695
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"OneKeyNativeScrollViewDidBecomeReady" object:nil];
2201
3696
  for (UIScrollView *scrollView in _originalInsets.keyEnumerator) {
2202
3697
  [self updateNativeScrollerViewport:scrollView stickyHeight:0];
2203
3698
  }
@@ -2247,6 +3742,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2247
3742
  }
2248
3743
  _hasPendingDirectNativePagerChange = NO;
2249
3744
  if (_directNativePagerEnabled == enabled) return;
3745
+ [self cancelNativeToolbarSettlement];
3746
+ [self cancelPendingNativePagerScroll];
2250
3747
 
2251
3748
  [self restoreScrollEdgeContentMasks];
2252
3749
  [self detachScrollObserver];
@@ -2308,12 +3805,12 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2308
3805
  return width * MAX(0, physicalIndex);
2309
3806
  }
2310
3807
 
2311
- - (CGFloat)directPagerProgress
3808
+ - (CGFloat)directPagerProgressForOffset:(CGFloat)offset
2312
3809
  {
2313
3810
  CGFloat width = CGRectGetWidth(_pagerScrollView.bounds);
2314
3811
  if (width <= 0 || _pageControllers.count == 0) return _currentIndex;
2315
3812
  CGFloat physicalProgress = RNCClamp(
2316
- _pagerScrollView.contentOffset.x / width,
3813
+ offset / width,
2317
3814
  0,
2318
3815
  _pageControllers.count - 1
2319
3816
  );
@@ -2322,11 +3819,56 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2322
3819
  : _pageControllers.count - 1 - physicalProgress;
2323
3820
  }
2324
3821
 
3822
+ - (CGFloat)directPagerProgress {
3823
+ return [self directPagerProgressForOffset:_pagerScrollView.contentOffset.x];
3824
+ }
3825
+
3826
+ - (void)stopProgrammaticTabProgress {
3827
+ if (_tabProgressDisplayLink != nil && _tabProgressWidth > 0 && fabs(CGRectGetWidth(_pagerScrollView.bounds) - _tabProgressWidth) < 0.5) {
3828
+ CALayer *presentation = _pagerScrollView.layer.presentationLayer;
3829
+ if (presentation && std::isfinite(presentation.bounds.origin.x)) {
3830
+ [_nativeTabBarView setProgress:[self directPagerProgressForOffset:presentation.bounds.origin.x]];
3831
+ }
3832
+ }
3833
+ [_tabProgressDisplayLink invalidate];
3834
+ _tabProgressDisplayLink = nil;
3835
+ }
3836
+
3837
+ - (void)updateNativeTabProgress:(CGFloat)progress {
3838
+ if (_tabProgressDisplayLink == nil) [_nativeTabBarView setProgress:progress];
3839
+ }
3840
+
3841
+ - (void)sampleProgrammaticTabProgress:(CADisplayLink *)link {
3842
+ if (link != _tabProgressDisplayLink) { [link invalidate]; return; }
3843
+ if (self.window == nil || !_transitioning || ![_nativeTabBarView usesControlledTextProgress] ||
3844
+ _tabProgressGeneration != _generation || _tabProgressTransition != _transitionId ||
3845
+ !std::isfinite(CGRectGetWidth(_pagerScrollView.bounds)) || _tabProgressWidth <= 0 ||
3846
+ fabs(CGRectGetWidth(_pagerScrollView.bounds) - _tabProgressWidth) >= 0.5) {
3847
+ [self stopProgrammaticTabProgress];
3848
+ return;
3849
+ }
3850
+ CALayer *presentation = _pagerScrollView.layer.presentationLayer;
3851
+ if (presentation == nil || !std::isfinite(presentation.bounds.origin.x)) return;
3852
+ [_nativeTabBarView setProgress:[self directPagerProgressForOffset:presentation.bounds.origin.x]];
3853
+ }
3854
+
3855
+ - (void)startProgrammaticTabProgress {
3856
+ [self stopProgrammaticTabProgress];
3857
+ RNCPagerPresentationProgressProxy *proxy = [RNCPagerPresentationProgressProxy new];
3858
+ proxy.target = self;
3859
+ _tabProgressWidth = CGRectGetWidth(_pagerScrollView.bounds);
3860
+ _tabProgressGeneration = _generation;
3861
+ _tabProgressTransition = _transitionId;
3862
+ _tabProgressDisplayLink = [CADisplayLink displayLinkWithTarget:proxy selector:@selector(tick:)];
3863
+ [_tabProgressDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
3864
+ }
3865
+
2325
3866
  #pragma mark - Smooth shared header ownership
2326
3867
 
2327
3868
  - (void)restorePinnedStickyHeader
2328
3869
  {
2329
3870
  if (!_stickyHeaderIsPinned) return;
3871
+ BOOL borrowedHost = [self borrowedPinnedStickyOwner] != nil;
2330
3872
  _stickyHeaderIsPinned = NO;
2331
3873
  _stickyHeaderView.transform = CGAffineTransformIdentity;
2332
3874
  _nativeTabBarView.transform = CGAffineTransformIdentity;
@@ -2337,14 +3879,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2337
3879
  if (_stickyHeaderView != nil) [_sharedHeaderHostView addSubview:_stickyHeaderView];
2338
3880
  [_sharedHeaderHostView addSubview:_nativeTabBarView];
2339
3881
  [_sharedHeaderHostView addSubview:_nativeSubHeaderView];
2340
- _pinnedStickyHostView.hidden = YES;
2341
- _pinnedStickyHostView.layer.zPosition = 0;
2342
- [_containerView addSubview:_pinnedStickyHostView];
3882
+ if (!borrowedHost) {
3883
+ _pinnedStickyHostView.hidden = YES;
3884
+ _pinnedStickyHostView.layer.zPosition = 0;
3885
+ [_containerView addSubview:_pinnedStickyHostView];
3886
+ }
2343
3887
  if ([_pagerScrollView isKindOfClass:RNCCollapsiblePagerDirectScrollView.class]) {
2344
3888
  ((RNCCollapsiblePagerDirectScrollView *)_pagerScrollView).excludedHeaderView = _sharedHeaderHostView;
2345
3889
  }
2346
3890
  [_nativeTabBarView updateAncestorGesturePrecedence];
2347
3891
  [_nativeSubHeaderView updateAncestorGesturePrecedence];
3892
+ [self bringReservedStickyControlToFront];
2348
3893
  }
2349
3894
 
2350
3895
  - (void)restoreSharedHeadersToContainer
@@ -2419,10 +3964,22 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2419
3964
  reason ?: @"unknown"]);
2420
3965
  }
2421
3966
 
3967
+ - (NSInteger)stickyHeaderHeightForPageIndex:(NSInteger)index
3968
+ {
3969
+ if (index < 0 || index >= (NSInteger)_stickyHeaderHeights.count) return _stickyHeaderHeight;
3970
+ id value = _stickyHeaderHeights[index];
3971
+ return [value isKindOfClass:NSNumber.class] ? MAX(0, [value integerValue]) : _stickyHeaderHeight;
3972
+ }
3973
+
3974
+ - (NSInteger)currentStickyHeaderHeight
3975
+ {
3976
+ return [self stickyHeaderHeightForPageIndex:_currentIndex];
3977
+ }
3978
+
2422
3979
  - (void)layoutSharedHeaders
2423
3980
  {
2424
3981
  CGFloat width = CGRectGetWidth(self.bounds);
2425
- CGFloat totalHeight = _headerHeight + _stickyHeaderHeight;
3982
+ CGFloat totalHeight = _headerHeight + self.currentStickyHeaderHeight;
2426
3983
  BOOL attachedToList = _nativeSmoothHeaderScrollEnabled &&
2427
3984
  _sharedHeaderScrollView != nil && !_sharedHeadersLiftedForPagerTransition;
2428
3985
 
@@ -2440,20 +3997,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2440
3997
  );
2441
3998
  CGFloat stickyY = _headerHeight;
2442
3999
  _headerView.frame = CGRectMake(0, 0, width, _headerHeight);
2443
- CGPoint pinnedOrigin = _stickyHeaderIsPinned
2444
- ? [_sharedHeaderScrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight) fromView:_containerView]
4000
+ RNCCollapsiblePagerTransitionEdgeOwner *borrowedOwner = [self borrowedPinnedStickyOwner];
4001
+ UIScrollView *pinnedScrollView = borrowedOwner.scrollView ?: _sharedHeaderScrollView;
4002
+ CGPoint pinnedOrigin = (borrowedOwner != nil || _stickyHeaderIsPinned) && pinnedScrollView != nil
4003
+ ? [pinnedScrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
4004
+ fromView:_containerView]
2445
4005
  : CGPointMake(0, self.effectiveTopOverlayHeight);
2446
4006
  _pinnedStickyHostView.frame = CGRectMake(
2447
- pinnedOrigin.x, pinnedOrigin.y, width, _stickyHeaderHeight);
4007
+ pinnedOrigin.x, pinnedOrigin.y, width, self.currentStickyHeaderHeight);
2448
4008
  CGFloat stickyChildY = _stickyHeaderIsPinned ? 0 : stickyY;
2449
- _stickyHeaderView.frame = CGRectMake(0, stickyChildY, width, _stickyHeaderHeight);
4009
+ _stickyHeaderView.frame = CGRectMake(0, stickyChildY, width, self.currentStickyHeaderHeight);
2450
4010
  CGFloat nativeTabBarVisibleHeight = _nativeTabBarView.hidden
2451
4011
  ? 0
2452
- : MIN(_stickyHeaderHeight, _nativeTabBarHeight);
4012
+ : MIN(self.currentStickyHeaderHeight, _nativeTabBarHeight);
4013
+ CGFloat tabReservedWidth = MIN(width, MAX(0, _nativeTabBarTrailingReservedWidth));
2453
4014
  _nativeTabBarView.frame = CGRectMake(
2454
- 0,
4015
+ self.isLtrLayout ? 0 : tabReservedWidth,
2455
4016
  stickyChildY,
2456
- width,
4017
+ width - tabReservedWidth,
2457
4018
  nativeTabBarVisibleHeight
2458
4019
  );
2459
4020
  _nativeSubHeaderView.frame = CGRectMake(
@@ -2461,15 +4022,32 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2461
4022
  stickyChildY + nativeTabBarVisibleHeight,
2462
4023
  width,
2463
4024
  MIN(
2464
- MAX(0, _stickyHeaderHeight - nativeTabBarVisibleHeight),
4025
+ MAX(0, self.currentStickyHeaderHeight - nativeTabBarVisibleHeight),
2465
4026
  _nativeSubHeaderHeight
2466
4027
  )
2467
4028
  );
2468
4029
  _topOverlayHostView.frame = CGRectMake(0, 0, width, self.effectiveTopOverlayHeight);
2469
4030
  _topOverlayView.frame = _topOverlayHostView.bounds;
4031
+ [self bringReservedStickyControlToFront];
2470
4032
  [self applyHeaderOffset];
2471
4033
  }
2472
4034
 
4035
+ - (void)bringReservedStickyControlToFront
4036
+ {
4037
+ if (_stickyHeaderView != nil &&
4038
+ _stickyHeaderView.superview == _nativeTabBarView.superview) {
4039
+ if (_nativeTabBarTrailingReservedWidth > 0) {
4040
+ [_stickyHeaderView.superview bringSubviewToFront:_stickyHeaderView];
4041
+ } else {
4042
+ [_nativeTabBarView.superview bringSubviewToFront:_nativeTabBarView];
4043
+ if (!_nativeSubHeaderView.hidden &&
4044
+ _nativeSubHeaderView.superview == _nativeTabBarView.superview) {
4045
+ [_nativeSubHeaderView.superview bringSubviewToFront:_nativeSubHeaderView];
4046
+ }
4047
+ }
4048
+ }
4049
+ }
4050
+
2473
4051
  - (void)updatePinnedStickyHeader
2474
4052
  {
2475
4053
  BOOL attachedToList = _nativeSmoothHeaderScrollEnabled &&
@@ -2497,7 +4075,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2497
4075
  CGPoint origin = [scrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
2498
4076
  fromView:_containerView];
2499
4077
  _pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y,
2500
- CGRectGetWidth(self.bounds), _stickyHeaderHeight);
4078
+ CGRectGetWidth(self.bounds), self.currentStickyHeaderHeight);
2501
4079
  }
2502
4080
  return;
2503
4081
  }
@@ -2515,11 +4093,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2515
4093
  [host addSubview:_nativeSubHeaderView];
2516
4094
  CGFloat childY = shouldPin ? 0 : _headerHeight;
2517
4095
  CGFloat width = CGRectGetWidth(self.bounds);
2518
- CGFloat tabHeight = _nativeTabBarView.hidden ? 0 : MIN(_stickyHeaderHeight, _nativeTabBarHeight);
2519
- _stickyHeaderView.frame = CGRectMake(0, childY, width, _stickyHeaderHeight);
2520
- _nativeTabBarView.frame = CGRectMake(0, childY, width, tabHeight);
4096
+ CGFloat tabHeight = _nativeTabBarView.hidden ? 0 : MIN(self.currentStickyHeaderHeight, _nativeTabBarHeight);
4097
+ CGFloat tabReservedWidth = MIN(width, MAX(0, _nativeTabBarTrailingReservedWidth));
4098
+ _stickyHeaderView.frame = CGRectMake(0, childY, width, self.currentStickyHeaderHeight);
4099
+ _nativeTabBarView.frame = CGRectMake(self.isLtrLayout ? 0 : tabReservedWidth,
4100
+ childY, width - tabReservedWidth, tabHeight);
2521
4101
  _nativeSubHeaderView.frame = CGRectMake(0, childY + tabHeight, width,
2522
- MIN(MAX(0, _stickyHeaderHeight - tabHeight), _nativeSubHeaderHeight));
4102
+ MIN(MAX(0, self.currentStickyHeaderHeight - tabHeight), _nativeSubHeaderHeight));
2523
4103
  _pinnedStickyHostView.hidden = !shouldPin;
2524
4104
  if ([_pagerScrollView isKindOfClass:RNCCollapsiblePagerDirectScrollView.class]) {
2525
4105
  ((RNCCollapsiblePagerDirectScrollView *)_pagerScrollView).excludedHeaderView =
@@ -2530,14 +4110,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2530
4110
  _pinnedStickyHostView.layer.zPosition = 1000;
2531
4111
  CGPoint origin = [scrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
2532
4112
  fromView:_containerView];
2533
- _pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y, width, _stickyHeaderHeight);
4113
+ _pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y, width, self.currentStickyHeaderHeight);
2534
4114
  } else {
2535
4115
  _pinnedStickyHostView.layer.zPosition = 0;
2536
4116
  [_containerView addSubview:_pinnedStickyHostView];
2537
4117
  }
2538
4118
  [_nativeTabBarView updateAncestorGesturePrecedence];
2539
4119
  [_nativeSubHeaderView updateAncestorGesturePrecedence];
4120
+ [self bringReservedStickyControlToFront];
2540
4121
  [self updateTopScrollEdgeForScrollView:_observedScrollView];
4122
+ [self logHomeVisualGeometry:shouldPin ? @"pin" : @"unpin"
4123
+ scrollView:_observedScrollView];
2541
4124
  }
2542
4125
 
2543
4126
  - (void)preparePageForHorizontalTransitionAtIndex:(NSInteger)pageIndex
@@ -2550,8 +4133,81 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2550
4133
  }
2551
4134
  }
2552
4135
 
4136
+ - (void)cancelNativeToolbarSettlement {
4137
+ [_toolbarSettleDisplayLink invalidate];
4138
+ _toolbarSettleDisplayLink = nil;
4139
+ _toolbarSettleAttempted = NO;
4140
+ _toolbarSettleTicks = 0;
4141
+ }
4142
+
4143
+ - (void)scheduleNativeToolbarSettlement {
4144
+ CGFloat width = CGRectGetWidth(_pagerScrollView.bounds);
4145
+ BOOL sameAttempt = _toolbarSettleAttempted && _toolbarSettleGeneration == _generation &&
4146
+ _toolbarSettleTransition == _transitionId && _toolbarSettlePage == _currentIndex &&
4147
+ _toolbarSettleWidth == width;
4148
+ if (sameAttempt) return;
4149
+ [self cancelNativeToolbarSettlement];
4150
+ _toolbarSettleAttempted = YES;
4151
+ _toolbarSettleGeneration = _generation;
4152
+ _toolbarSettleTransition = _transitionId;
4153
+ _toolbarSettlePage = _currentIndex;
4154
+ _toolbarSettleWidth = width;
4155
+ RNCPagerPresentationProgressProxy *proxy = [RNCPagerPresentationProgressProxy new];
4156
+ proxy.target = self;
4157
+ proxy.toolbarSettlement = YES;
4158
+ _toolbarSettleDisplayLink = [CADisplayLink displayLinkWithTarget:proxy selector:@selector(tick:)];
4159
+ [_toolbarSettleDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
4160
+ }
4161
+
4162
+ - (void)sampleToolbarSettlement:(CADisplayLink *)link {
4163
+ if (link != _toolbarSettleDisplayLink) { [link invalidate]; return; }
4164
+ if (_toolbarSettleGeneration != _generation || _toolbarSettleTransition != _transitionId ||
4165
+ _toolbarSettlePage != _currentIndex ||
4166
+ _toolbarSettleWidth != CGRectGetWidth(_pagerScrollView.bounds) ||
4167
+ !self.window || _nativeTabBarView.window != self.window || ![_nativeTabBarView ownsSettledToolbar]) {
4168
+ [self cancelNativeToolbarSettlement];
4169
+ return;
4170
+ }
4171
+ ++_toolbarSettleTicks;
4172
+ [self syncNativeToolbarState];
4173
+ if (link == _toolbarSettleDisplayLink && _toolbarSettleTicks >= 2) {
4174
+ [link invalidate];
4175
+ _toolbarSettleDisplayLink = nil;
4176
+ }
4177
+ }
4178
+
4179
+ - (void)syncNativeToolbarState {
4180
+ BOOL logicalBusy = !self.window || _isBeingRecycled || !_hasAppliedInitialPage || _toolbarTransitionPending ||
4181
+ _transitioning || _isPagerDragging || _externalOuterTransitioning ||
4182
+ (_externalOuterPager != nil && !_externalOuterPageActive) || _needsSlotRebuild ||
4183
+ _pendingGoToIndex >= 0 || _transitionPageOffsets != nil || _pendingNativePagerScrollCompletion != nil ||
4184
+ _tabProgressDisplayLink != nil || _currentIndex < 0 || _currentIndex >= _pageControllers.count ||
4185
+ CGRectGetWidth(self.bounds) <= 0 || CGRectGetHeight(self.bounds) <= 0 ||
4186
+ _pagerScrollView.dragging || _pagerScrollView.decelerating;
4187
+ BOOL busy = logicalBusy || _pagerScrollView.tracking;
4188
+ if (!busy && _directNativePagerEnabled) {
4189
+ CALayer *presentation = _pagerScrollView.layer.presentationLayer;
4190
+ CGFloat offset = presentation ? presentation.bounds.origin.x : _pagerScrollView.contentOffset.x;
4191
+ busy = CGRectGetWidth(_pagerScrollView.bounds) <= 0 || !std::isfinite(offset) ||
4192
+ fabs(offset - [self directPagerOffsetForIndex:_currentIndex]) >= 0.5;
4193
+ } else if (!busy) {
4194
+ busy = _pageViewController.viewControllers.firstObject != _pageControllers[_currentIndex];
4195
+ }
4196
+ [_nativeTabBarView updateToolbarPagerIndex:_currentIndex busy:busy];
4197
+ if (busy && !logicalBusy && [_nativeTabBarView ownsSettledToolbar] &&
4198
+ _nativeTabBarView.window == self.window && !_nativeTabBarView.hidden &&
4199
+ CGRectGetWidth(_pagerScrollView.bounds) > 0) {
4200
+ [self scheduleNativeToolbarSettlement];
4201
+ } else {
4202
+ [self cancelNativeToolbarSettlement];
4203
+ }
4204
+ }
4205
+
2553
4206
  - (void)beginPageStateTransition
2554
4207
  {
4208
+ [self cancelNativeToolbarSettlement];
4209
+ _toolbarTransitionPending = YES;
4210
+ [_nativeTabBarView updateToolbarPagerIndex:-1 busy:YES];
2555
4211
  [self cancelPagerTop];
2556
4212
  if (!_nativeSmoothHeaderScrollEnabled || _headerHeight <= 0 || _transitionPageOffsets != nil) return;
2557
4213
  _transitionSourceDisplayBody = MAX(_observedScrollView.contentOffset.y + _observedScrollView.contentInset.top - _headerHeight, 0);
@@ -2689,6 +4345,15 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2689
4345
  - (void)mountingTransactionDidMount:(const MountingTransaction &)transaction
2690
4346
  withSurfaceTelemetry:(const SurfaceTelemetry &)surfaceTelemetry
2691
4347
  {
4348
+ if (_needsSlotRebuild && _deferTopEdgeSlotRebuild &&
4349
+ _topScrollEdgeEnabled && _nativeSmoothHeaderScrollEnabled &&
4350
+ _topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
4351
+ _topOverlayHeight > 0 && _pageKeys.count > 0 &&
4352
+ _externalTopOverlayTag <= 0 &&
4353
+ _logicalChildren.count == _pageKeys.count + 3 &&
4354
+ !_transitioning && !_isPagerDragging && !_isBeingRecycled) {
4355
+ _deferTopEdgeSlotRebuild = NO;
4356
+ }
2692
4357
  if (_needsSlotRebuild && !_deferTopEdgeSlotRebuild &&
2693
4358
  !_transitioning && !_isPagerDragging) {
2694
4359
  [self rebuildSlots];
@@ -2711,6 +4376,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2711
4376
  }
2712
4377
  [self updateScrollEdgeContentMasks];
2713
4378
  [_mountingRemovedScrollViews removeAllObjects];
4379
+ [self logHomeVisualGeometry:@"did-mount" scrollView:_observedScrollView];
2714
4380
  if (!_nativeSmoothHeaderScrollEnabled || _isBeingRecycled || self.window == nil ||
2715
4381
  _currentIndex < 0 || _currentIndex >= _pageControllers.count) return;
2716
4382
  // Prepare newly mounted owned scrollers before their first frame, even while
@@ -2728,6 +4394,23 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2728
4394
  [self applyInsetsToScrollView:scrollView pageIndex:index restore:YES];
2729
4395
  }
2730
4396
  }
4397
+ UIView *page = _pageControllers[_currentIndex].view;
4398
+ if (_scrollResolveRetryAttempt >= 12 &&
4399
+ _releasedPageScrollStates[self.currentPageKey] != nil) {
4400
+ for (const auto &mutation : transaction.getMutations()) {
4401
+ if (mutation.type == ShadowViewMutation::Insert && mutation.parentTag > 0 &&
4402
+ [page viewWithTag:mutation.parentTag] != nil) {
4403
+ // A new current-page insertion starts a bounded recovery round after
4404
+ // the previous replacement search has scheduled its final retry.
4405
+ _scrollResolveRetryToken += 1;
4406
+ _scrollResolveRetryScheduled = NO;
4407
+ _scrollResolveRetryAttempt = 0;
4408
+ break;
4409
+ }
4410
+ }
4411
+ }
4412
+
4413
+ // Record recovery during transitions; ownership still waits for settlement.
2731
4414
  if (_transitioning || _isPagerDragging) return;
2732
4415
 
2733
4416
  // OneKey patch: a release must recover even when the changed parent is above
@@ -2736,7 +4419,6 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2736
4419
  [self attachScrollObserverForCurrentPage];
2737
4420
  return;
2738
4421
  }
2739
- UIView *page = _pageControllers[_currentIndex].view;
2740
4422
  BOOL headerIsAttached = [_sharedHeaderHostView isDescendantOfView:self];
2741
4423
  BOOL currentListIsAttached = _observedScrollView != nil &&
2742
4424
  [_observedScrollView isDescendantOfView:page] && headerIsAttached;
@@ -2827,6 +4509,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2827
4509
  }
2828
4510
  _needsSlotRebuild = NO;
2829
4511
  _deferTopEdgeSlotRebuild = NO;
4512
+ [self cancelPendingNativePagerScroll];
2830
4513
  [self restoreScrollEdgeContentMasks];
2831
4514
  [self detachScrollObserver];
2832
4515
  [self restoreSharedHeadersToContainer];
@@ -2899,28 +4582,40 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2899
4582
  animated:NO
2900
4583
  completion:nil];
2901
4584
  }
2902
- [_nativeTabBarView setProgress:_currentIndex];
4585
+ [self updateNativeTabProgress:_currentIndex];
2903
4586
  }
2904
4587
  if (_stickyHeaderView != nil) [_sharedHeaderHostView bringSubviewToFront:_stickyHeaderView];
2905
4588
  if (!_nativeTabBarView.hidden) [_sharedHeaderHostView bringSubviewToFront:_nativeTabBarView];
2906
4589
  if (!_nativeSubHeaderView.hidden) [_sharedHeaderHostView bringSubviewToFront:_nativeSubHeaderView];
4590
+ [self bringReservedStickyControlToFront];
2907
4591
  [_containerView bringSubviewToFront:_sharedHeaderHostView];
2908
4592
  if (_stickyHeaderIsPinned) {
2909
4593
  [_pinnedStickyHostView.superview bringSubviewToFront:_pinnedStickyHostView];
2910
4594
  }
2911
4595
  if (self.hasFixedTopOverlay) [_containerView bringSubviewToFront:_topOverlayHostView];
2912
4596
  [self setNeedsLayout];
2913
- dispatch_async(dispatch_get_main_queue(), ^{
2914
- if (!self->_isBeingRecycled) {
2915
- [self prepareAdjacentPageInsets];
2916
- [self attachScrollObserverForCurrentPage];
2917
- }
2918
- });
4597
+ [self scheduleCoalescedScrollReconcile];
2919
4598
  }
2920
4599
 
2921
4600
  - (void)layoutSubviews
2922
4601
  {
2923
4602
  [super layoutSubviews];
4603
+ if (_tabProgressDisplayLink != nil && fabs(CGRectGetWidth(self.bounds) - _tabProgressWidth) >= 0.5) {
4604
+ [self stopProgrammaticTabProgress];
4605
+ }
4606
+ void (^resizedPagerCompletion)(BOOL) = nil;
4607
+ NSInteger resizedPagerDestination = -1;
4608
+ NSUInteger resizedPagerGeneration = 0;
4609
+ NSUInteger resizedPagerTransition = 0;
4610
+ if (_directNativePagerEnabled && _pendingNativePagerScrollCompletion != nil &&
4611
+ CGRectGetWidth(_pagerScrollView.bounds) != CGRectGetWidth(self.bounds)) {
4612
+ resizedPagerCompletion = [_pendingNativePagerScrollCompletion copy];
4613
+ resizedPagerDestination = _destinationIndex;
4614
+ resizedPagerGeneration = _pendingNativePagerScrollGeneration;
4615
+ resizedPagerTransition = _pendingNativePagerScrollTransition;
4616
+ // Clear the old target before frame changes can deliver an animation end.
4617
+ [self cancelPendingNativePagerScroll];
4618
+ }
2924
4619
  [self syncScrollEdgeAppearance];
2925
4620
  _containerView.frame = self.bounds;
2926
4621
  [self registerExternalOuterPager];
@@ -2950,7 +4645,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2950
4645
  animated:NO
2951
4646
  completion:nil];
2952
4647
  }
2953
- [_nativeTabBarView setProgress:_currentIndex];
4648
+ [self updateNativeTabProgress:_currentIndex];
2954
4649
  }
2955
4650
  // UIKit frame assignment is undefined while a view has a non-identity transform.
2956
4651
  // Restore transforms before settling page and shared-header frames.
@@ -2991,16 +4686,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
2991
4686
  [self updateTopScrollEdgeForScrollView:_observedScrollView];
2992
4687
  [self updateScrollEdgeContentMasks];
2993
4688
  [self updateHeaderSettledStateForceBusy:NO];
2994
- dispatch_async(dispatch_get_main_queue(), ^{
2995
- if (!self->_isBeingRecycled) {
2996
- [self prepareAdjacentPageInsets];
2997
- [self attachScrollObserverForCurrentPage];
2998
- }
2999
- });
4689
+ [self logHomeVisualGeometry:@"layout" scrollView:_observedScrollView];
4690
+ [self scheduleCoalescedScrollReconcile];
4691
+ if (resizedPagerCompletion != nil && _directNativePagerEnabled &&
4692
+ !_isBeingRecycled && !_isPagerDragging && _generation == resizedPagerGeneration &&
4693
+ _transitionId == resizedPagerTransition && resizedPagerDestination >= 0 &&
4694
+ resizedPagerDestination < _pageControllers.count) {
4695
+ [_pagerScrollView setContentOffset:CGPointMake(
4696
+ [self directPagerOffsetForIndex:resizedPagerDestination], 0
4697
+ ) animated:NO];
4698
+ resizedPagerCompletion(YES);
4699
+ }
4700
+ [self syncNativeToolbarState];
3000
4701
  }
3001
4702
 
3002
4703
  - (void)prepareForRecycle
3003
4704
  {
4705
+ [self cancelNativeToolbarSettlement];
4706
+ [self cancelPendingNativePagerScroll];
3004
4707
  [_externalOuterPager removeNestedOverlayObserver:self];
3005
4708
  _externalOuterPager = nil;
3006
4709
  [self cancelTopInsetReboundCheck];
@@ -3009,11 +4712,15 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3009
4712
  [self cancelHeaderSettledCheck];
3010
4713
  [self publishHeaderSettledAtTop:NO identityChanged:NO];
3011
4714
  _isBeingRecycled = YES;
4715
+ _toolbarTransitionPending = NO;
4716
+ [_nativeTabBarView updateToolbarPagerIndex:-1 busy:YES];
3012
4717
  _pendingTopOverlayAppearanceCommit = NO;
3013
4718
  [self syncScrollEdgeAppearance];
3014
4719
  _generation++;
3015
4720
  [_mountingRemovedScrollViews removeAllObjects];
3016
4721
  _needsScrollObserverReattachAfterMount = NO;
4722
+ _awaitingScrollOwnerForCurrentPage = NO;
4723
+ _scrollReconcileScheduled = NO;
3017
4724
  [_releasedPageScrollStates removeAllObjects];
3018
4725
  [self detachSharedHeaderPressCancellationGesture];
3019
4726
  [self detachScrollObserver];
@@ -3102,6 +4809,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3102
4809
  _pendingInitialPage = 0;
3103
4810
  _headerHeight = 0;
3104
4811
  _stickyHeaderHeight = 0;
4812
+ _stickyHeaderHeights = nil;
3105
4813
  _topOverlayHeight = 0;
3106
4814
  _externalTopOverlayTag = 0;
3107
4815
  _externalTopOverlayView = nil;
@@ -3110,7 +4818,12 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3110
4818
  _externalOuterTransitioning = NO;
3111
4819
  _topScrollEdgeEnabled = NO;
3112
4820
  _topScrollEdgeEffect = RNCCollapsiblePagerViewTopScrollEdgeEffect::None;
4821
+ _homeVisualStartMono = 0;
4822
+ _homeVisualLastScrollLog = 0;
4823
+ _homeVisualLastLayoutLog = 0;
4824
+ _homeVisualLastGeometrySignature = nil;
3113
4825
  _nativeTabBarHeight = 44;
4826
+ _nativeTabBarTrailingReservedWidth = 0;
3114
4827
  _nativeSubHeaderHeight = 74;
3115
4828
  _headerOffset = 0;
3116
4829
  _currentLogicalOffset = 0;
@@ -3139,7 +4852,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3139
4852
  _needsPropsReapply = YES;
3140
4853
  _layoutDirection = @"ltr";
3141
4854
  [_nativeTabBarView updateItemsJSON:@"[]"];
3142
- [_nativeTabBarView setProgress:0];
4855
+ [_nativeTabBarView updateConfigJSON:@"{}"];
4856
+ [self updateNativeTabProgress:0];
3143
4857
  [_nativeSubHeaderView updateConfigJSON:@"{}"];
3144
4858
  _isBeingRecycled = NO;
3145
4859
  }
@@ -3192,6 +4906,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3192
4906
  _layoutDirection = RCTNSStringFromString(toString(newViewProps.layoutDirection));
3193
4907
  [_nativeTabBarView setLeftToRight:self.isLtrLayout];
3194
4908
  [_nativeSubHeaderView setLeftToRight:self.isLtrLayout];
4909
+ [self setNeedsLayout];
4910
+ }
4911
+ if (_needsPropsReapply ||
4912
+ oldViewProps.nativeTabBarTrailingReservedWidth != newViewProps.nativeTabBarTrailingReservedWidth) {
4913
+ double reserved = newViewProps.nativeTabBarTrailingReservedWidth;
4914
+ _nativeTabBarTrailingReservedWidth = std::isfinite(reserved) && reserved >= 0 ? reserved : 0;
4915
+ [self setNeedsLayout];
3195
4916
  }
3196
4917
  BOOL insetsChanged = NO;
3197
4918
  if (_needsPropsReapply || oldViewProps.headerHeight != newViewProps.headerHeight) {
@@ -3203,6 +4924,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3203
4924
  _stickyHeaderHeight = MAX(0, newViewProps.stickyHeaderHeight);
3204
4925
  insetsChanged = YES;
3205
4926
  }
4927
+ if (_needsPropsReapply || oldViewProps.stickyHeaderHeights != newViewProps.stickyHeaderHeights) {
4928
+ NSString *json = RCTNSStringFromString(newViewProps.stickyHeaderHeights);
4929
+ NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
4930
+ id parsed = data.length == 0 ? nil : [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
4931
+ _stickyHeaderHeights = [parsed isKindOfClass:NSArray.class] ? parsed : nil;
4932
+ insetsChanged = YES;
4933
+ }
3206
4934
  if (_needsPropsReapply || oldViewProps.topScrollEdgeEffect != newViewProps.topScrollEdgeEffect) {
3207
4935
  BOOL enabled = newViewProps.topScrollEdgeEffect != RNCCollapsiblePagerViewTopScrollEdgeEffect::None;
3208
4936
  BOOL enabledChanged = _topScrollEdgeEnabled != enabled;
@@ -3239,6 +4967,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3239
4967
  }
3240
4968
  if (_needsPropsReapply ||
3241
4969
  oldViewProps.externalTopOverlayTag != newViewProps.externalTopOverlayTag) {
4970
+ if (_topOverlayView == nil && _externalTopOverlayTag > 0 &&
4971
+ _externalTopOverlayTag != newViewProps.externalTopOverlayTag) {
4972
+ [self clearProgrammaticScrollEdges];
4973
+ }
3242
4974
  _externalTopOverlayTag = newViewProps.externalTopOverlayTag;
3243
4975
  [self registerExternalOuterPager];
3244
4976
  insetsChanged = [self resolveExternalTopOverlay] || insetsChanged;
@@ -3257,6 +4989,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3257
4989
  _retainedPages = RCTNSStringFromString(newViewProps.retainedPages);
3258
4990
  [self setNeedsLayout];
3259
4991
  }
4992
+ if (_needsPropsReapply || oldViewProps.nativeTabBarConfig != newViewProps.nativeTabBarConfig) {
4993
+ [_nativeTabBarView updateConfigJSON:RCTNSStringFromString(newViewProps.nativeTabBarConfig)];
4994
+ }
3260
4995
  if (_needsPropsReapply || oldViewProps.nativeTabBarItems != newViewProps.nativeTabBarItems) {
3261
4996
  NSString *itemsJSON = RCTNSStringFromString(newViewProps.nativeTabBarItems);
3262
4997
  [_nativeTabBarView updateItemsJSON:itemsJSON];
@@ -3272,7 +5007,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3272
5007
  }
3273
5008
  if (_needsPropsReapply ||
3274
5009
  oldViewProps.nativeTabBarHeight != newViewProps.nativeTabBarHeight ||
5010
+ oldViewProps.nativeTabBarVariant != newViewProps.nativeTabBarVariant ||
3275
5011
  oldViewProps.nativeTabBarContentPaddingHorizontal != newViewProps.nativeTabBarContentPaddingHorizontal ||
5012
+ oldViewProps.nativeTabBarContentPaddingVertical != newViewProps.nativeTabBarContentPaddingVertical ||
3276
5013
  oldViewProps.nativeTabBarItemSpacing != newViewProps.nativeTabBarItemSpacing ||
3277
5014
  oldViewProps.nativeTabBarFontSize != newViewProps.nativeTabBarFontSize ||
3278
5015
  oldViewProps.nativeTabBarFontFamily != newViewProps.nativeTabBarFontFamily ||
@@ -3289,7 +5026,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3289
5026
  NSString *fontFamily = RCTNSStringFromString(newViewProps.nativeTabBarFontFamily);
3290
5027
  [_nativeTabBarView
3291
5028
  updateStyleWithHeight:_nativeTabBarHeight
5029
+ variant:RCTNSStringFromString(newViewProps.nativeTabBarVariant)
3292
5030
  contentPaddingHorizontal:MAX(0, newViewProps.nativeTabBarContentPaddingHorizontal)
5031
+ contentPaddingVertical:MAX(0, newViewProps.nativeTabBarContentPaddingVertical)
3293
5032
  itemSpacing:MAX(0, newViewProps.nativeTabBarItemSpacing)
3294
5033
  fontSize:newViewProps.nativeTabBarFontSize > 0 ? newViewProps.nativeTabBarFontSize : 16
3295
5034
  fontFamily:fontFamily
@@ -3314,14 +5053,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3314
5053
  if (insetsChanged) {
3315
5054
  [self reapplyInsetsToObservedScrollView];
3316
5055
  [self setNeedsLayout];
5056
+ [self logHomeVisualGeometry:@"props-inset" scrollView:_observedScrollView];
3317
5057
  }
3318
5058
  _applyingTopOverlayInsetChange = NO;
5059
+ [self syncNativeToolbarState];
3319
5060
  if (!_nativeTabBarView.hidden) {
3320
5061
  [_nativeTabBarView.superview bringSubviewToFront:_nativeTabBarView];
3321
5062
  }
3322
5063
  if (!_nativeSubHeaderView.hidden) {
3323
5064
  [_nativeSubHeaderView.superview bringSubviewToFront:_nativeSubHeaderView];
3324
5065
  }
5066
+ [self bringReservedStickyControlToFront];
3325
5067
  [_sharedHeaderHostView.superview bringSubviewToFront:_sharedHeaderHostView];
3326
5068
  if (_stickyHeaderIsPinned) {
3327
5069
  [_pinnedStickyHostView.superview bringSubviewToFront:_pinnedStickyHostView];
@@ -3349,17 +5091,112 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3349
5091
 
3350
5092
  - (UIScrollView *)verticalScrollViewForPageAtIndex:(NSInteger)pageIndex
3351
5093
  {
3352
- if (pageIndex < 0 || pageIndex >= _pageControllers.count) return nil;
3353
- UIView *pageView = _pageControllers[pageIndex].view;
3354
- UIScrollView *explicitScroller = [self findExplicitNativeScrollerInView:pageView];
3355
- if (explicitScroller != nil) return explicitScroller;
3356
- UIScrollView *fabricScrollView = [self findFabricScrollViewInView:pageView];
3357
- return fabricScrollView ?: [self findVerticalScrollViewInView:pageView];
5094
+ return [self resolveScrollCandidateForPageAtIndex:pageIndex].scrollView;
5095
+ }
5096
+
5097
+ - (RNCScrollCandidateResolution)resolveScrollCandidateForPageAtIndex:(NSInteger)pageIndex
5098
+ {
5099
+ if (pageIndex < 0 || pageIndex >= _pageControllers.count) return {};
5100
+ return [self resolveScrollCandidateInView:_pageControllers[pageIndex].view];
5101
+ }
5102
+
5103
+ // Single-pass tiered resolution replaces three separate subtree walks while
5104
+ // distinguishing genuinely static pages from pages with unready scroll hosts.
5105
+ - (RNCScrollCandidateResolution)resolveScrollCandidateInView:(UIView *)view
5106
+ {
5107
+ RNCScrollCandidateResolution resolution;
5108
+ if (view == nil || view == _sharedHeaderHostView || RNCIsNativeOverlayHost(view)) return resolution;
5109
+ if (view != self &&
5110
+ [view isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
5111
+ UIScrollView *nested = [(RNCCollapsiblePagerViewComponentView *)view
5112
+ currentVerticalScrollViewForParentPager];
5113
+ if (nested != nil) {
5114
+ resolution.scrollView = nested;
5115
+ resolution.tier = RNCScrollCandidateTierExplicitScroller;
5116
+ } else {
5117
+ resolution.hasUnreadyScrollHost = YES;
5118
+ }
5119
+ return resolution;
5120
+ }
5121
+
5122
+ Class nativeListClass = NSClassFromString(@"HybridNativeListComponent");
5123
+ if (nativeListClass != Nil && [view isKindOfClass:nativeListClass]) {
5124
+ resolution.hasUnreadyScrollHost = YES;
5125
+ }
5126
+
5127
+ if ([view isKindOfClass:RNCNativeScrollerComponentView.class]) {
5128
+ UIScrollView *scrollView = ((RNCNativeScrollerComponentView *)view).scrollView;
5129
+ if (![_mountingRemovedScrollViews containsObject:scrollView]) {
5130
+ resolution.scrollView = scrollView;
5131
+ resolution.tier = RNCScrollCandidateTierExplicitScroller;
5132
+ return resolution;
5133
+ }
5134
+ } else if ([view isKindOfClass:RCTScrollViewComponentView.class]) {
5135
+ RCTScrollViewComponentView *componentView = (RCTScrollViewComponentView *)view;
5136
+ UIScrollView *scrollView = componentView.scrollView;
5137
+ if (![_mountingRemovedScrollViews containsObject:scrollView]) {
5138
+ if ([componentView.nativeId hasPrefix:RNCCollapsiblePagerNativeScrollerIDPrefix]) {
5139
+ resolution.scrollView = scrollView;
5140
+ resolution.tier = RNCScrollCandidateTierExplicitScroller;
5141
+ return resolution;
5142
+ }
5143
+ if (!scrollView.alwaysBounceHorizontal) {
5144
+ resolution.scrollView = scrollView;
5145
+ resolution.tier = RNCScrollCandidateTierFabricScrollView;
5146
+ }
5147
+ }
5148
+ } else if ([view isKindOfClass:UICollectionView.class]) {
5149
+ UICollectionView *collectionView = (UICollectionView *)view;
5150
+ if (![_mountingRemovedScrollViews containsObject:collectionView]) {
5151
+ UICollectionViewLayout *layout = collectionView.collectionViewLayout;
5152
+ BOOL isVerticalLayout = ![layout isKindOfClass:UICollectionViewFlowLayout.class] ||
5153
+ ((UICollectionViewFlowLayout *)layout).scrollDirection == UICollectionViewScrollDirectionVertical;
5154
+ if (isVerticalLayout) {
5155
+ BOOL hasNativeListHost = RNCNativeListComponentForScrollView(collectionView) != nil;
5156
+ BOOL isMountedNativeList = hasNativeListHost && RNCIsMountedNativeListScrollView(collectionView);
5157
+ BOOL hasUsableBounds = CGRectGetWidth(collectionView.bounds) > 0 &&
5158
+ CGRectGetHeight(collectionView.bounds) > 0;
5159
+ if (hasNativeListHost && !isMountedNativeList) {
5160
+ resolution.hasUnreadyScrollHost = YES;
5161
+ } else if (!hasUsableBounds) {
5162
+ resolution.hasUnreadyScrollHost = YES;
5163
+ } else {
5164
+ resolution.scrollView = collectionView;
5165
+ resolution.tier = isMountedNativeList
5166
+ ? RNCScrollCandidateTierVerifiedNativeList
5167
+ : RNCScrollCandidateTierGenericFallback;
5168
+ // React slots inside a verified list may own independent scroll views.
5169
+ if (isMountedNativeList) return resolution;
5170
+ }
5171
+ }
5172
+ }
5173
+ } else if ([view isKindOfClass:UIScrollView.class]) {
5174
+ UIScrollView *scrollView = (UIScrollView *)view;
5175
+ if (![_mountingRemovedScrollViews containsObject:scrollView] &&
5176
+ !scrollView.alwaysBounceHorizontal &&
5177
+ scrollView.contentSize.width <= scrollView.bounds.size.width + 1) {
5178
+ resolution.scrollView = scrollView;
5179
+ resolution.tier = RNCScrollCandidateTierGenericFallback;
5180
+ }
5181
+ }
5182
+
5183
+ for (UIView *subview in view.subviews) {
5184
+ RNCScrollCandidateResolution child = [self resolveScrollCandidateInView:subview];
5185
+ resolution.hasUnreadyScrollHost |= child.hasUnreadyScrollHost;
5186
+ if (child.tier > resolution.tier) {
5187
+ resolution.scrollView = child.scrollView;
5188
+ resolution.tier = child.tier;
5189
+ if (resolution.tier == RNCScrollCandidateTierExplicitScroller) {
5190
+ return resolution;
5191
+ }
5192
+ }
5193
+ }
5194
+ return resolution;
3358
5195
  }
3359
5196
 
3360
5197
  - (UIScrollView *)findExplicitNativeScrollerInView:(UIView *)view
3361
5198
  {
3362
- if (view == _sharedHeaderHostView) return nil;
5199
+ if (view == _sharedHeaderHostView || RNCIsNativeOverlayHost(view)) return nil;
3363
5200
  if (view != self &&
3364
5201
  [view isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
3365
5202
  return [(RNCCollapsiblePagerViewComponentView *)view
@@ -3386,7 +5223,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3386
5223
 
3387
5224
  - (UIScrollView *)findFabricScrollViewInView:(UIView *)view
3388
5225
  {
3389
- if (view == _sharedHeaderHostView) return nil;
5226
+ if (view == _sharedHeaderHostView || RNCIsNativeOverlayHost(view)) return nil;
3390
5227
  if (view != self &&
3391
5228
  [view isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
3392
5229
  return [(RNCCollapsiblePagerViewComponentView *)view
@@ -3409,7 +5246,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3409
5246
 
3410
5247
  - (UIScrollView *)findVerticalScrollViewInView:(UIView *)view
3411
5248
  {
3412
- if (view == _sharedHeaderHostView ||
5249
+ if (view == _sharedHeaderHostView || RNCIsNativeOverlayHost(view) ||
3413
5250
  ([view isKindOfClass:UIScrollView.class] &&
3414
5251
  [_mountingRemovedScrollViews containsObject:(UIScrollView *)view])) return nil;
3415
5252
  // A parent pager must follow the nested pager's active page instead of the
@@ -3450,6 +5287,19 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3450
5287
  return nil;
3451
5288
  }
3452
5289
 
5290
+ - (void)scheduleCoalescedScrollReconcile
5291
+ {
5292
+ if (_isBeingRecycled || _scrollReconcileScheduled) return;
5293
+ _scrollReconcileScheduled = YES;
5294
+ NSUInteger generation = _generation;
5295
+ dispatch_async(dispatch_get_main_queue(), ^{
5296
+ self->_scrollReconcileScheduled = NO;
5297
+ if (self->_isBeingRecycled || self->_generation != generation) return;
5298
+ [self prepareAdjacentPageInsets];
5299
+ [self attachScrollObserverForCurrentPage];
5300
+ });
5301
+ }
5302
+
3453
5303
  - (void)scheduleScrollObserverRetryForCurrentPage
3454
5304
  {
3455
5305
  if (_scrollResolveRetryScheduled || _scrollResolveRetryAttempt >= 12 ||
@@ -3502,29 +5352,35 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3502
5352
  _pendingFallbackScrollView = nil;
3503
5353
  _pendingFallbackScrollViewDetectedAt = 0;
3504
5354
  }
3505
- UIScrollView *candidate = [self verticalScrollViewForPageAtIndex:_currentIndex];
5355
+ RNCScrollCandidateResolution resolution = [self resolveScrollCandidateForPageAtIndex:_currentIndex];
5356
+ UIScrollView *candidate = resolution.scrollView;
3506
5357
  if (_nativeSmoothHeaderScrollEnabled && _currentIndex >= 0 && _currentIndex < _pageControllers.count) {
3507
5358
  RNCGuardNestedHorizontalPans(_pageControllers[_currentIndex].view, _verticalPagerGesture);
3508
5359
  }
3509
5360
  if (candidate == nil) {
3510
5361
  [self detachScrollObserver];
3511
5362
  [self restoreSharedHeadersToContainer];
3512
- // Stop retrying released lists on unrelated commits without discarding a
3513
- // surviving identity or offset. A relevant insertion resumes recovery.
3514
- if (_needsScrollObserverReattachAfterMount) {
3515
- _needsScrollObserverReattachAfterMount = NO;
5363
+ _needsScrollObserverReattachAfterMount = NO;
5364
+ _pendingFallbackScrollView = nil;
5365
+ _pendingFallbackScrollViewDetectedAt = 0;
5366
+ _awaitingScrollOwnerForCurrentPage = YES;
5367
+ // Only schedule bounded retry when the page has an unready scroll host in
5368
+ // its subtree or a released scroll owner awaiting replacement. Static pages
5369
+ // without a scroll host do not spin retry timers, and late replacements on
5370
+ // any page also attach deterministically via readiness notifications.
5371
+ BOOL hasReleasedOwnerAwaitingReplacement = _releasedPageScrollStates[self.currentPageKey] != nil;
5372
+ if (resolution.hasUnreadyScrollHost || hasReleasedOwnerAwaitingReplacement) {
5373
+ [self scheduleScrollObserverRetryForCurrentPage];
5374
+ } else {
3516
5375
  _scrollResolveRetryToken += 1;
3517
5376
  _scrollResolveRetryScheduled = NO;
3518
5377
  _scrollResolveRetryAttempt = 0;
3519
- _pendingFallbackScrollView = nil;
3520
- _pendingFallbackScrollViewDetectedAt = 0;
3521
- } else {
3522
- [self scheduleScrollObserverRetryForCurrentPage];
3523
5378
  }
3524
5379
  return;
3525
5380
  }
3526
5381
  if ([candidate isKindOfClass:UICollectionView.class] &&
3527
5382
  candidate != _observedScrollView && !RNCIsMountedNativeListScrollView(candidate)) {
5383
+ _awaitingScrollOwnerForCurrentPage = YES;
3528
5384
  if (_pendingFallbackScrollView != candidate) {
3529
5385
  _pendingFallbackScrollView = candidate;
3530
5386
  _pendingFallbackScrollViewDetectedAt = CACurrentMediaTime();
@@ -3536,6 +5392,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3536
5392
  return;
3537
5393
  }
3538
5394
  }
5395
+ _awaitingScrollOwnerForCurrentPage = NO;
3539
5396
  _scrollResolveRetryAttempt = 0;
3540
5397
  _scrollResolveRetryPageIndex = _currentIndex;
3541
5398
  _scrollResolveRetryToken += 1;
@@ -3894,8 +5751,105 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3894
5751
  [_managedRefreshControls removeObjectForKey:scrollView];
3895
5752
  if (current != nil) [_managedRefreshControls setObject:current forKey:scrollView];
3896
5753
  }
3897
- [RNCRefreshControlOffsetState setOffset:self.effectiveTopOverlayHeight + _headerHeight + _stickyHeaderHeight
5754
+ [RNCRefreshControlOffsetState setOffset:_headerHeight + self.currentStickyHeaderHeight
3898
5755
  forControl:current owner:self];
5756
+ if (previous != current) [self logHomeVisualGeometry:@"refresh-bind" scrollView:scrollView];
5757
+ }
5758
+
5759
+ - (void)logHomeVisualGeometry:(NSString *)phase scrollView:(UIScrollView *)scrollView
5760
+ {
5761
+ #if DEBUG
5762
+ if (self.window == nil || _isBeingRecycled) return;
5763
+ CFTimeInterval now = CACurrentMediaTime();
5764
+ if (_homeVisualStartMono == 0) _homeVisualStartMono = now;
5765
+ if ([phase isEqualToString:@"pull"] && now - _homeVisualLastScrollLog < 0.2) return;
5766
+ if ([phase isEqualToString:@"pull"]) _homeVisualLastScrollLog = now;
5767
+ UIRefreshControl *control = scrollView.refreshControl;
5768
+ CGRect controlWindow = control != nil
5769
+ ? [control convertRect:control.bounds toView:self.window] : CGRectZero;
5770
+ CGRect overlayWindow = [_topOverlayHostView convertRect:_topOverlayHostView.bounds
5771
+ toView:self.window];
5772
+ CGRect stickyWindow = [_stickyHeaderView convertRect:_stickyHeaderView.bounds
5773
+ toView:self.window];
5774
+ CGRect maskWindow = _sharedHeaderMaskView != nil
5775
+ ? [_sharedHeaderHostView convertRect:_sharedHeaderMaskView.frame toView:self.window]
5776
+ : CGRectZero;
5777
+ CGFloat pageMaskWindowY = [_containerView convertPoint:
5778
+ CGPointMake(0, _pageMaskBoundary) toView:self.window].y;
5779
+ BOOL layoutPhase = [phase isEqualToString:@"layout"] ||
5780
+ [phase isEqualToString:@"did-mount"];
5781
+ NSString *signature = [NSString stringWithFormat:
5782
+ @"%.1f:%ld:%ld:%.1f:%d:%.1f:%.1f:%.1f:%d:%d",
5783
+ self.effectiveTopOverlayHeight, (long)_headerHeight,
5784
+ (long)self.currentStickyHeaderHeight, scrollView.contentInset.top, control != nil,
5785
+ CGRectGetMinY(maskWindow), CGRectGetHeight(maskWindow), _pageMaskBoundary,
5786
+ _stickyHeaderIsPinned, _topScrollEdgeEnabled];
5787
+ if (layoutPhase && now - _homeVisualStartMono >= 2.0 &&
5788
+ [_homeVisualLastGeometrySignature isEqualToString:signature] &&
5789
+ now - _homeVisualLastLayoutLog < 2.0) return;
5790
+ if (layoutPhase) {
5791
+ _homeVisualLastLayoutLog = now;
5792
+ _homeVisualLastGeometrySignature = signature;
5793
+ }
5794
+ CGFloat visualYEstimate = CGRectGetMinY(controlWindow) +
5795
+ (control != nil ? control.layer.sublayerTransform.m42 : 0);
5796
+ CALayer *firstChild = control.layer.sublayers.firstObject;
5797
+ BOOL childAttached = firstChild != nil && control.window == self.window;
5798
+ CGRect firstChildWindow = childAttached
5799
+ ? [firstChild convertRect:firstChild.bounds toLayer:self.window.layer]
5800
+ : CGRectZero;
5801
+ CGFloat overscroll = scrollView != nil
5802
+ ? -(scrollView.contentOffset.y + scrollView.contentInset.top) : 0;
5803
+ double epochMs = [NSDate.date timeIntervalSince1970] * 1000;
5804
+ double monoMs = now * 1000;
5805
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
5806
+ @"[IOS-HOME-VISUAL] epochMs=%.0f monoMs=%.0f phase=%@ pagerTag=%ld generation=%lu pageIndex=%ld window=%d edge=%d overlay=%.1f header=%ld sticky=%ld collapse=%.1f scrollY=%.1f insetTop=%.1f overscroll=%.1f refresh=%d refreshing=%d controlY=%.1f controlH=%.1f sublayerY=%.1f visualYEstimate=%.1f overlayY=%.1f overlayBottom=%.1f stickyY=%.1f stickyBottom=%.1f maskY=%.1f maskH=%.1f pageMaskWindowY=%.1f",
5807
+ epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
5808
+ (long)_currentIndex, self.window != nil, _topScrollEdgeEnabled,
5809
+ self.effectiveTopOverlayHeight, (long)_headerHeight, (long)self.currentStickyHeaderHeight,
5810
+ _headerOffset, scrollView.contentOffset.y, scrollView.contentInset.top,
5811
+ overscroll, control != nil, control.isRefreshing,
5812
+ CGRectGetMinY(controlWindow), CGRectGetHeight(controlWindow),
5813
+ control != nil ? control.layer.sublayerTransform.m42 : 0, visualYEstimate,
5814
+ CGRectGetMinY(overlayWindow), CGRectGetMaxY(overlayWindow),
5815
+ CGRectGetMinY(stickyWindow), CGRectGetMaxY(stickyWindow),
5816
+ CGRectGetMinY(maskWindow), CGRectGetHeight(maskWindow), pageMaskWindowY]);
5817
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
5818
+ @"[IOS-HOME-VISUAL] epochMs=%.0f monoMs=%.0f phase=%@-refresh-layer pagerTag=%ld generation=%lu pageIndex=%ld boundsY=%.1f boundsH=%.1f centerY=%.1f transformTY=%.1f layerPositionY=%.1f layerTransformY=%.1f directChildCount=%lu firstChildAttached=%d firstChildWindowY=%.1f firstChildWindowH=%.1f",
5819
+ epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
5820
+ (long)_currentIndex, control.bounds.origin.y, control.bounds.size.height,
5821
+ control.center.y, control.transform.ty, control.layer.position.y,
5822
+ control.layer.transform.m42, (unsigned long)control.layer.sublayers.count,
5823
+ childAttached, CGRectGetMinY(firstChildWindow), CGRectGetHeight(firstChildWindow)]);
5824
+ if (![phase isEqualToString:@"pull"]) {
5825
+ CALayer *topCover = _topEdgeSeparatorCover;
5826
+ CALayer *stickyCover = _stickyEdgeSeparatorCover;
5827
+ UIColor *color = topCover.backgroundColor != nil
5828
+ ? [UIColor colorWithCGColor:topCover.backgroundColor] : nil;
5829
+ CGFloat red = 0, green = 0, blue = 0, alpha = 0;
5830
+ [color getRed:&red green:&green blue:&blue alpha:&alpha];
5831
+ CGRect topCoverWindow = topCover.superlayer != nil
5832
+ ? [topCover convertRect:topCover.bounds toLayer:self.window.layer] : CGRectZero;
5833
+ CGRect stickyCoverWindow = stickyCover.superlayer != nil
5834
+ ? [stickyCover convertRect:stickyCover.bounds toLayer:self.window.layer] : CGRectZero;
5835
+ RNCCollapsiblePagerLog([NSString stringWithFormat:
5836
+ @"[IOS-HOME-VISUAL] epochMs=%.0f monoMs=%.0f phase=%@-edge pagerTag=%ld generation=%lu pageIndex=%ld trait=%ld override=%ld style=%ld pinned=%d topHostY=%.1f topHostBottom=%.1f stickyHostY=%.1f stickyHostBottom=%.1f topInteractionSameScroll=%d stickyInteractionSameScroll=%d topCover=%d topCoverHidden=%d topCoverY=%.1f topCoverH=%.3f stickyCover=%d stickyCoverHidden=%d stickyCoverY=%.1f stickyCoverH=%.3f coverRGBA=%.3f,%.3f,%.3f,%.3f scale=%.1f",
5837
+ epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
5838
+ (long)_currentIndex, (long)self.traitCollection.userInterfaceStyle,
5839
+ (long)_topOverlayHostView.overrideUserInterfaceStyle,
5840
+ (long)_topScrollEdgeEffect, _stickyHeaderIsPinned,
5841
+ CGRectGetMinY(overlayWindow), CGRectGetMaxY(overlayWindow),
5842
+ CGRectGetMinY(stickyWindow), CGRectGetMaxY(stickyWindow),
5843
+ _topEdgeInteraction.scrollView == scrollView,
5844
+ _stickyEdgeInteraction.scrollView == scrollView,
5845
+ topCover != nil, topCover.hidden, CGRectGetMinY(topCoverWindow),
5846
+ CGRectGetHeight(topCoverWindow), stickyCover != nil,
5847
+ stickyCover.hidden,
5848
+ CGRectGetMinY(stickyCoverWindow),
5849
+ CGRectGetHeight(stickyCoverWindow), red, green, blue, alpha,
5850
+ self.window.screen.scale]);
5851
+ }
5852
+ #endif
3899
5853
  }
3900
5854
 
3901
5855
  - (void)releaseRefreshControlForScrollView:(UIScrollView *)scrollView
@@ -3959,6 +5913,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
3959
5913
  // still represents the old list, before Fabric applies its next owner's props.
3960
5914
  - (void)restoreScrollViewState:(UIScrollView *)scrollView resetSavedOffset:(BOOL)resetSavedOffset
3961
5915
  {
5916
+ [self releaseProgrammaticScrollEdge:scrollView];
3962
5917
  [self updateNativeScrollerViewport:scrollView stickyHeight:0];
3963
5918
  [self releaseRefreshControlForScrollView:scrollView];
3964
5919
  if (scrollView == _observedScrollView) {
@@ -4086,7 +6041,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4086
6041
  // suppress its later vertical movement while the pager is still pending.
4087
6042
  scrollView.directionalLockEnabled = _nativeSmoothHeaderScrollEnabled
4088
6043
  ? NO : [_originalDirectionalLockEnabled objectForKey:scrollView].boolValue;
4089
- [self updateNativeScrollerViewport:scrollView stickyHeight:_stickyHeaderHeight + self.effectiveTopOverlayHeight];
6044
+ CGFloat stickyHeight = [self stickyHeaderHeightForPageIndex:pageIndex];
6045
+ [self updateNativeScrollerViewport:scrollView stickyHeight:stickyHeight + self.effectiveTopOverlayHeight];
4090
6046
  [self updateRefreshControlForScrollView:scrollView];
4091
6047
  CGFloat previousTopInset = scrollView.contentInset.top;
4092
6048
  CGFloat previousLogicalOffset = scrollView.contentOffset.y + previousTopInset;
@@ -4097,13 +6053,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4097
6053
  CGFloat refreshInset = appliedTop != nil && scrollView.refreshControl != nil
4098
6054
  ? MAX(0, previousTopInset - appliedTop.doubleValue) : 0;
4099
6055
  UIEdgeInsets next = original;
4100
- next.top += self.effectiveTopOverlayHeight + _headerHeight + _stickyHeaderHeight;
6056
+ next.top += self.effectiveTopOverlayHeight + _headerHeight + stickyHeight;
4101
6057
  CGFloat pagerTopInset = next.top;
4102
6058
  next.top += refreshInset;
4103
6059
  [_appliedTopInsets setObject:@(pagerTopInset) forKey:scrollView];
4104
6060
  // Short pages still need enough range to collapse the header; long pages
4105
6061
  // must end at the last row rather than leave a header-sized blank footer.
4106
- next.bottom += MAX(0, scrollView.bounds.size.height - _stickyHeaderHeight - self.effectiveTopOverlayHeight
6062
+ next.bottom += MAX(0, scrollView.bounds.size.height - stickyHeight - self.effectiveTopOverlayHeight
4107
6063
  - original.top - original.bottom - scrollView.contentSize.height);
4108
6064
  if (UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, next) && !restore) {
4109
6065
  // UICollectionView may report contentSize during a bounce without changing
@@ -4137,6 +6093,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4137
6093
  restoredLogicalOffset = _headerOffset + (_headerOffset >= _headerHeight ? body : 0);
4138
6094
  if (_transitionPageOffsets != nil) [_transitionCompensatedPages addIndex:pageIndex];
4139
6095
  if (deferredReleasedIdentity || scrollView.bounds.size.height <= 0 || scrollView.contentSize.height <= 0) {
6096
+ // Align a fresh page before content measurement while retaining its pending restore.
6097
+ if (!deferredReleasedIdentity && saved == nil && _headerOffset == 0) {
6098
+ [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, -next.top) animated:NO];
6099
+ }
4140
6100
  [_pendingPageRestoreKeys addObject:pageKey];
4141
6101
  _syntheticPageRestore = previousSyntheticRestore;
4142
6102
  return;
@@ -4189,8 +6149,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4189
6149
 
4190
6150
  - (void)updateNativeScrollerViewport:(UIScrollView *)scrollView stickyHeight:(CGFloat)height
4191
6151
  {
4192
- if ([scrollView.superview isKindOfClass:RNCNativeScrollerComponentView.class]) {
4193
- [(RNCNativeScrollerComponentView *)scrollView.superview setPagerStickyHeight:height forOwner:self];
6152
+ id host = scrollView.superview;
6153
+ if ([host respondsToSelector:@selector(setPagerStickyHeight:forOwner:)]) {
6154
+ [host setPagerStickyHeight:height forOwner:self];
4194
6155
  }
4195
6156
  }
4196
6157
 
@@ -4262,6 +6223,69 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4262
6223
  }
4263
6224
 
4264
6225
 
6226
+ - (void)nativeScrollViewDidBecomeReadyNotification:(NSNotification *)notification
6227
+ {
6228
+ if ([notification.object isKindOfClass:UIScrollView.class]) {
6229
+ [self nativeScrollViewDidBecomeReady:(UIScrollView *)notification.object];
6230
+ }
6231
+ }
6232
+
6233
+ - (void)nativeScrollViewDidBecomeReady:(UIScrollView *)scrollView
6234
+ {
6235
+ if (_isBeingRecycled || self.window == nil || scrollView == nil ||
6236
+ [_mountingRemovedScrollViews containsObject:scrollView]) return;
6237
+ for (UIView *ancestor = scrollView.superview;
6238
+ ancestor != nil && ancestor != self;
6239
+ ancestor = ancestor.superview) {
6240
+ if ([ancestor isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
6241
+ RNCCollapsiblePagerViewComponentView *nestedPager =
6242
+ (RNCCollapsiblePagerViewComponentView *)ancestor;
6243
+ if ([nestedPager currentVerticalScrollViewForParentPager] != scrollView) return;
6244
+ break;
6245
+ }
6246
+ }
6247
+ NSInteger pageIndex = NSNotFound;
6248
+ for (NSInteger index = 0; index < _pageControllers.count; index++) {
6249
+ if ([scrollView isDescendantOfView:_pageControllers[index].view]) {
6250
+ pageIndex = index;
6251
+ break;
6252
+ }
6253
+ }
6254
+ if (pageIndex == NSNotFound) return;
6255
+ if ([self verticalScrollViewForPageAtIndex:pageIndex] != scrollView) return;
6256
+
6257
+ NSString *pageKey = [self pageKeyForIndex:pageIndex];
6258
+ BOOL hasReleasedStateForPage = _releasedPageScrollStates[pageKey] != nil;
6259
+ BOOL currentPageNeedsOwner = pageIndex == _currentIndex &&
6260
+ (_awaitingScrollOwnerForCurrentPage || _needsScrollObserverReattachAfterMount ||
6261
+ hasReleasedStateForPage ||
6262
+ (_observedScrollView == nil &&
6263
+ (_scrollReconcileScheduled || RNCIsMountedNativeListScrollView(scrollView))) ||
6264
+ (_observedScrollView != nil &&
6265
+ [_observedScrollView isKindOfClass:UICollectionView.class] &&
6266
+ !RNCIsMountedNativeListScrollView(_observedScrollView) &&
6267
+ _observedScrollView != scrollView));
6268
+
6269
+ if (!hasReleasedStateForPage && !currentPageNeedsOwner &&
6270
+ !_needsScrollObserverReattachAfterMount) return;
6271
+
6272
+ if (_nativeSmoothHeaderScrollEnabled) {
6273
+ NSInteger first = MAX(0, _currentIndex - 1);
6274
+ NSInteger last = MIN((NSInteger)_pageControllers.count - 1, _currentIndex + 1);
6275
+ BOOL isOwnedScroller = [scrollView.superview isKindOfClass:RNCNativeScrollerComponentView.class] &&
6276
+ ((RNCNativeScrollerComponentView *)scrollView.superview).scrollView == scrollView;
6277
+ if ((pageIndex >= first && pageIndex <= last || pageIndex == _destinationIndex) &&
6278
+ (RNCIsMountedNativeListScrollView(scrollView) || isOwnedScroller) &&
6279
+ [_originalInsets objectForKey:scrollView] == nil) {
6280
+ [self applyInsetsToScrollView:scrollView pageIndex:pageIndex restore:YES];
6281
+ }
6282
+ }
6283
+
6284
+ if (currentPageNeedsOwner && !_transitioning && !_isPagerDragging) {
6285
+ [self attachScrollObserverForCurrentPage];
6286
+ }
6287
+ }
6288
+
4265
6289
  - (void)nativeScroller:(RNCNativeScrollerComponentView *)scroller
4266
6290
  callerInsetChangedFrom:(UIEdgeInsets)previous to:(UIEdgeInsets)next
4267
6291
  {
@@ -4313,6 +6337,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4313
6337
  if (context == RNCScrollRefreshControlContext) {
4314
6338
  UIScrollView *scrollView = (UIScrollView *)object;
4315
6339
  [self updateRefreshControlForScrollView:scrollView];
6340
+ [self logHomeVisualGeometry:@"refresh-control-change" scrollView:scrollView];
4316
6341
  if (scrollView == _observedScrollView && !_syntheticPageRestore &&
4317
6342
  (!_nativeSmoothHeaderScrollEnabled || (!_transitioning && _transitionPageOffsets == nil))) {
4318
6343
  [self updateHeaderForScrollView:scrollView];
@@ -4320,6 +6345,11 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4320
6345
  return;
4321
6346
  }
4322
6347
  if (context == RNCCollapsiblePagerContentOffsetContext && object == _observedScrollView) {
6348
+ if ([keyPath isEqualToString:@"contentOffset"] &&
6349
+ -(((UIScrollView *)object).contentOffset.y +
6350
+ ((UIScrollView *)object).contentInset.top) > 5) {
6351
+ [self logHomeVisualGeometry:@"pull" scrollView:(UIScrollView *)object];
6352
+ }
4323
6353
  if (_pendingTopInsetReboundScrollView == object &&
4324
6354
  ([keyPath isEqualToString:@"contentOffset"] || [keyPath isEqualToString:@"contentInset"])) {
4325
6355
  if (((UIScrollView *)object).panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
@@ -4458,6 +6488,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4458
6488
 
4459
6489
  #pragma mark - Pager navigation
4460
6490
 
6491
+ - (void)cancelPendingNativePagerScroll
6492
+ {
6493
+ [self stopProgrammaticTabProgress];
6494
+ if (_pendingNativePagerScrollCompletion == nil) return;
6495
+ _pendingNativePagerScrollCompletion = nil;
6496
+ _pendingNativePagerScrollGeneration = 0;
6497
+ _pendingNativePagerScrollTransition = 0;
6498
+ _pendingNativePagerScrollTarget = 0;
6499
+ CGPoint offset = _pagerScrollView.contentOffset;
6500
+ [_pagerScrollView setContentOffset:offset animated:NO];
6501
+ }
6502
+
4461
6503
  - (BOOL)isLtrLayout
4462
6504
  {
4463
6505
  return [_layoutDirection isEqualToString:@"ltr"];
@@ -4467,6 +6509,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4467
6509
  {
4468
6510
  [self cancelTopInsetReboundCheck];
4469
6511
  if (_isBeingRecycled || index < 0 || index >= _pageControllers.count) return;
6512
+ [self cancelNativeToolbarSettlement];
4470
6513
  _hasReceivedPageCommand = YES;
4471
6514
  _hasAppliedInitialPage = YES;
4472
6515
  if (_transitioning || _isPagerDragging) {
@@ -4488,14 +6531,21 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4488
6531
  [self attachScrollObserverForCurrentPage];
4489
6532
  [self emitPageSelected:index];
4490
6533
  [self emitDiagnostics:@"page-selected"];
6534
+ [self syncNativeToolbarState];
4491
6535
  return;
4492
6536
  }
4493
6537
 
6538
+ if (_directNativePagerEnabled && animated && index != _currentIndex) {
6539
+ [self adoptCurrentScrollEdgeForProgrammaticTransition:NO];
6540
+ }
4494
6541
  [self beginPageStateTransition];
4495
6542
  [self preparePageForHorizontalTransitionAtIndex:index];
4496
6543
  _destinationIndex = index;
4497
6544
  [self liftSharedHeadersForPagerTransition:@"programmatic"];
4498
6545
  [self detachScrollObserver];
6546
+ if (_directNativePagerEnabled && animated && index != _currentIndex) {
6547
+ [self beginProgrammaticScrollEdgesToIndex:index allowExternalOverlay:NO];
6548
+ }
4499
6549
  BOOL forward = (index > _currentIndex && self.isLtrLayout) ||
4500
6550
  (index < _currentIndex && !self.isLtrLayout);
4501
6551
  UIPageViewControllerNavigationDirection direction = forward
@@ -4510,13 +6560,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4510
6560
  CGFloat targetOffset = [self directPagerOffsetForIndex:index];
4511
6561
  void (^animations)(void) = ^{
4512
6562
  [self->_pagerScrollView setContentOffset:CGPointMake(targetOffset, 0)];
4513
- [self->_nativeTabBarView setProgress:index];
6563
+ if (self->_tabProgressDisplayLink == nil) [self->_nativeTabBarView setProgress:index];
4514
6564
  [self updatePageStateTransitionProgress:index];
4515
6565
  };
4516
6566
  void (^completion)(BOOL) = ^(BOOL finished) {
4517
6567
  __strong __typeof__(weakSelf) self = weakSelf;
4518
6568
  if (self == nil || self->_generation != capturedGeneration ||
4519
6569
  self->_transitionId != capturedTransition || self->_isBeingRecycled) return;
6570
+ [self stopProgrammaticTabProgress];
4520
6571
  self->_pagerScrollView.scrollEnabled = self->_scrollEnabled;
4521
6572
  if (finished) {
4522
6573
  [self detachScrollObserver];
@@ -4535,13 +6586,42 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4535
6586
  };
4536
6587
 
4537
6588
  if (animated && index != _currentIndex) {
6589
+ BOOL useNativeAnimatedScroll = NO;
6590
+ if (@available(iOS 27.0, *)) {
6591
+ useNativeAnimatedScroll = _nativeSmoothHeaderScrollEnabled && _topScrollEdgeEnabled &&
6592
+ _topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
6593
+ _topOverlayView != nil && _externalTopOverlayTag <= 0 && self.window != nil;
6594
+ }
6595
+ if (useNativeAnimatedScroll) {
6596
+ // Keep the traversed pages owned until UIKit finishes scrolling.
6597
+ NSInteger first = MIN(_currentIndex, index);
6598
+ NSInteger last = MAX(_currentIndex, index);
6599
+ _programmaticPageMaskIndexes = [NSIndexSet indexSetWithIndexesInRange:
6600
+ NSMakeRange(first, last - first + 1)];
6601
+ [self updateScrollEdgeContentMasks];
6602
+ }
4538
6603
  _pagerScrollView.scrollEnabled = NO;
4539
- [UIView animateWithDuration:0.28
4540
- delay:0
4541
- options:UIViewAnimationOptionCurveEaseInOut |
4542
- UIViewAnimationOptionAllowUserInteraction
4543
- animations:animations
4544
- completion:completion];
6604
+ if (useNativeAnimatedScroll) {
6605
+ if (fabs(_pagerScrollView.contentOffset.x - targetOffset) <= 0.5) {
6606
+ [self updateNativeTabProgress:index];
6607
+ [self updatePageStateTransitionProgress:index];
6608
+ completion(YES);
6609
+ } else {
6610
+ _pendingNativePagerScrollCompletion = [completion copy];
6611
+ _pendingNativePagerScrollGeneration = capturedGeneration;
6612
+ _pendingNativePagerScrollTransition = capturedTransition;
6613
+ _pendingNativePagerScrollTarget = targetOffset;
6614
+ [_pagerScrollView setContentOffset:CGPointMake(targetOffset, 0) animated:YES];
6615
+ }
6616
+ } else {
6617
+ if ([_nativeTabBarView usesControlledTextProgress]) [self startProgrammaticTabProgress];
6618
+ [UIView animateWithDuration:0.28
6619
+ delay:0
6620
+ options:UIViewAnimationOptionCurveEaseInOut |
6621
+ UIViewAnimationOptionAllowUserInteraction
6622
+ animations:animations
6623
+ completion:completion];
6624
+ }
4545
6625
  } else {
4546
6626
  [UIView performWithoutAnimation:animations];
4547
6627
  completion(YES);
@@ -4583,7 +6663,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4583
6663
  if (self->_generation != generation || self->_transitionId != transition ||
4584
6664
  self->_isBeingRecycled) return;
4585
6665
  [self finishPageStateTransition];
6666
+ self->_programmaticPageMaskIndexes = nil;
4586
6667
  self->_transitioning = NO;
6668
+ BOOL hadProgrammaticScrollEdges = self->_programmaticScrollEdgeOwners.count > 0;
6669
+ [self finishProgrammaticScrollEdges];
4587
6670
  if (self->_hasPendingDirectNativePagerChange) {
4588
6671
  BOOL enabled = self->_pendingDirectNativePagerEnabled;
4589
6672
  self->_hasPendingDirectNativePagerChange = NO;
@@ -4592,11 +6675,16 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4592
6675
  [self rebuildSlots];
4593
6676
  }
4594
6677
  if (!self->_hasAppliedInitialPage) [self setNeedsLayout];
6678
+ if (hadProgrammaticScrollEdges && !self->_transitioning && !self->_needsSlotRebuild) {
6679
+ [self attachScrollObserverForCurrentPage];
6680
+ }
4595
6681
  [self drainPendingGoTo];
4596
- if (!self->_transitioning && !self->_needsSlotRebuild) {
6682
+ if (!self->_transitioning && !self->_isPagerDragging && self->_pendingGoToIndex < 0) self->_toolbarTransitionPending = NO;
6683
+ if (!hadProgrammaticScrollEdges && !self->_transitioning && !self->_needsSlotRebuild) {
4597
6684
  [self attachScrollObserverForCurrentPage];
4598
6685
  }
4599
6686
  [self updateScrollEdgeContentMasks];
6687
+ [self syncNativeToolbarState];
4600
6688
  });
4601
6689
  }
4602
6690
 
@@ -4647,21 +6735,30 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4647
6735
 
4648
6736
  - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
4649
6737
  {
6738
+ if (scrollView == _pagerScrollView) [self cancelPendingNativePagerScroll];
6739
+ ++_transitionId;
4650
6740
  [self updateHeaderSettledStateForceBusy:YES];
4651
6741
  if (_nativeSmoothHeaderScrollEnabled && scrollView == _pagerScrollView) {
4652
6742
  [_contentPressCancellationGesture cancelPressForPan:scrollView.panGestureRecognizer];
4653
6743
  }
6744
+ if (_directNativePagerEnabled) [self adoptCurrentScrollEdgeForProgrammaticTransition:YES];
4654
6745
  [self beginPageStateTransition];
4655
6746
  if (_directNativePagerEnabled) {
4656
6747
  [self preparePageForHorizontalTransitionAtIndex:_currentIndex - 1];
4657
6748
  [self preparePageForHorizontalTransitionAtIndex:_currentIndex + 1];
4658
6749
  }
4659
6750
  // A user drag owns the result even if UIKit later completes the old animation.
4660
- ++_transitionId;
6751
+ _programmaticPageMaskIndexes = nil;
4661
6752
  [self liftSharedHeadersForPagerTransition:@"interactive"];
4662
6753
  [self detachScrollObserver];
4663
6754
  _isPagerDragging = YES;
4664
6755
  _transitioning = YES;
6756
+ if (_directNativePagerEnabled) {
6757
+ if (_currentIndex > 0) [self beginProgrammaticScrollEdgesToIndex:_currentIndex - 1 allowExternalOverlay:YES];
6758
+ if (_currentIndex + 1 < _pageControllers.count) {
6759
+ [self beginProgrammaticScrollEdgesToIndex:_currentIndex + 1 allowExternalOverlay:YES];
6760
+ }
6761
+ }
4665
6762
  if (_nativeSmoothHeaderScrollEnabled) {
4666
6763
  RNCCollapsiblePagerLog([NSString stringWithFormat:
4667
6764
  @"gesture-owner=pager page=%ld",
@@ -4707,7 +6804,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4707
6804
  [self directPagerOffsetForIndex:index],
4708
6805
  0
4709
6806
  ) animated:NO];
4710
- [_nativeTabBarView setProgress:index];
6807
+ [self updateNativeTabProgress:index];
4711
6808
  [self attachScrollObserverForCurrentPageAfterTransition:YES];
4712
6809
  if (emitSelection &&
4713
6810
  (_pendingGoToIndex < 0 || _pendingGoToIndex == index)) {
@@ -4758,7 +6855,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4758
6855
  [self detachScrollObserver];
4759
6856
  _currentIndex = index;
4760
6857
  _destinationIndex = index;
4761
- [_nativeTabBarView setProgress:index];
6858
+ [self updateNativeTabProgress:index];
4762
6859
  [self attachScrollObserverForCurrentPageAfterTransition:YES];
4763
6860
  // A newer tab tap remains authoritative while its queued command runs.
4764
6861
  if (emitSelection &&
@@ -4794,6 +6891,20 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4794
6891
  [self finishPagerScrollEmittingSelection:YES];
4795
6892
  }
4796
6893
 
6894
+ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
6895
+ {
6896
+ if (scrollView != _pagerScrollView || _pendingNativePagerScrollCompletion == nil ||
6897
+ scrollView.isDragging || _generation != _pendingNativePagerScrollGeneration ||
6898
+ _transitionId != _pendingNativePagerScrollTransition ||
6899
+ fabs(scrollView.contentOffset.x - _pendingNativePagerScrollTarget) > 0.5) return;
6900
+ void (^completion)(BOOL) = _pendingNativePagerScrollCompletion;
6901
+ _pendingNativePagerScrollCompletion = nil;
6902
+ _pendingNativePagerScrollGeneration = 0;
6903
+ _pendingNativePagerScrollTransition = 0;
6904
+ _pendingNativePagerScrollTarget = 0;
6905
+ completion(YES);
6906
+ }
6907
+
4797
6908
  - (void)scrollViewDidScroll:(UIScrollView *)scrollView
4798
6909
  {
4799
6910
  CGFloat width = scrollView.bounds.size.width;
@@ -4805,7 +6916,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4805
6916
  position = MAX(0, MIN(position, (NSInteger)_pageControllers.count - 1));
4806
6917
  [self updatePageStateTransitionProgress:progress];
4807
6918
  [self updateScrollEdgeContentMasks];
4808
- [_nativeTabBarView setProgress:progress];
6919
+ if (_tabProgressDisplayLink == nil) [self updateNativeTabProgress:progress];
4809
6920
  const auto emitter = [self eventEmitter];
4810
6921
  if (emitter) {
4811
6922
  emitter->onPageScroll({.position = (double)position, .offset = (double)offset});
@@ -4824,7 +6935,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4824
6935
  }
4825
6936
  [self updatePageStateTransitionProgress:tabProgress];
4826
6937
  [self updateScrollEdgeContentMasks];
4827
- [_nativeTabBarView setProgress:tabProgress];
6938
+ [self updateNativeTabProgress:tabProgress];
4828
6939
  const auto emitter = [self eventEmitter];
4829
6940
  if (emitter) {
4830
6941
  emitter->onPageScroll({.position = (double)position, .offset = (double)offset});
@@ -4895,7 +7006,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4895
7006
  UIEdgeInsets adjustedInset = owner.adjustedContentInset;
4896
7007
  NSString *geometry = [NSString stringWithFormat:
4897
7008
  @"%.4f:%ld:%ld:%@:%@:%@:%@:%@:%@:%@",
4898
- _headerOffset, (long)_headerHeight, (long)_stickyHeaderHeight,
7009
+ _headerOffset, (long)_headerHeight, (long)self.currentStickyHeaderHeight,
4899
7010
  NSStringFromCGPoint(owner.contentOffset), NSStringFromCGSize(owner.contentSize),
4900
7011
  NSStringFromCGRect(owner.bounds), NSStringFromUIEdgeInsets(inset),
4901
7012
  NSStringFromUIEdgeInsets(adjustedInset), NSStringFromCGRect(headerRect), NSStringFromCGRect(ownerRect)];
@@ -4978,6 +7089,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4978
7089
  {
4979
7090
  UIScrollView *scrollView = _pagerTopScrollView;
4980
7091
  if (_dispatchingPagerTop || ![self matchesPagerTop:scrollView]) return;
7092
+ CGFloat clampedTarget = MIN(MAX(_pagerTopLogicalTarget, 0), _headerHeight);
7093
+ if (clampedTarget != _pagerTopLogicalTarget) {
7094
+ _pagerTopLogicalTarget = clampedTarget;
7095
+ CGFloat physicalTarget = RNCLimitRestoredScrollOffset(clampedTarget - scrollView.contentInset.top,
7096
+ scrollView.contentSize.height, scrollView.bounds.size.height, scrollView.contentInset.top, scrollView.contentInset.bottom);
7097
+ [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, physicalTarget) animated:NO];
7098
+ }
4981
7099
  CGFloat logical = scrollView.contentOffset.y + scrollView.contentInset.top;
4982
7100
  if (fabs(logical - _pagerTopLogicalTarget) > 0.5) return;
4983
7101
  _pageOffsets[_pagerTopPageKey] = @(_nativeSmoothHeaderScrollEnabled ? 0 : _pagerTopLogicalTarget);
@@ -4989,14 +7107,44 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
4989
7107
  }
4990
7108
 
4991
7109
  - (void)scrollToTop:(NSInteger)target animated:(BOOL)animated
7110
+ {
7111
+ [self tryScrollToTop:target animated:animated];
7112
+ }
7113
+
7114
+ - (BOOL)tryScrollToTop:(NSInteger)target animated:(BOOL)animated
7115
+ {
7116
+ if (target != 0 && target != 1) return NO;
7117
+ return [self scrollHeaderToOffset:(target == 1 ? _headerHeight : 0) animated:animated];
7118
+ }
7119
+
7120
+ // The header offset is stored apart from the body, so a collapsed header can sit
7121
+ // above a body that is already at its top.
7122
+ - (BOOL)isAwayFromPageTop
7123
+ {
7124
+ return _headerOffset > 0.5;
7125
+ }
7126
+
7127
+ - (void)scrollHeaderBy:(double)delta
7128
+ {
7129
+ if (!std::isfinite(delta)) return;
7130
+ [self scrollHeaderToOffset:MIN(MAX(_headerOffset + delta, 0), _headerHeight) animated:NO];
7131
+ }
7132
+
7133
+ - (void)scrollHeaderToOffset:(double)offset
7134
+ {
7135
+ if (!std::isfinite(offset)) return;
7136
+ [self scrollHeaderToOffset:MIN(MAX(offset, 0), _headerHeight) animated:NO];
7137
+ }
7138
+
7139
+ - (BOOL)scrollHeaderToOffset:(CGFloat)logicalTarget animated:(BOOL)animated
4992
7140
  {
4993
7141
  [self cancelTopInsetReboundCheck];
4994
7142
  UIScrollView *scrollView = _observedScrollView;
4995
7143
  NSString *key = _observedPageKey;
4996
- if ((target != 0 && target != 1) || _isBeingRecycled || _transitioning || _isPagerDragging ||
7144
+ if (_isBeingRecycled || _transitioning || _isPagerDragging ||
4997
7145
  _transitionPageOffsets != nil || _syntheticPageRestore || scrollView == nil || scrollView.window == nil ||
4998
7146
  key == nil || ![key isEqualToString:self.currentPageKey] || _observedPageIndex != _currentIndex ||
4999
- _observedPageGeneration != _generation || self.window == nil) return;
7147
+ _observedPageGeneration != _generation || self.window == nil) return NO;
5000
7148
  [self cancelPagerTop];
5001
7149
  // Old List phase2 notifications must run before the new target owns this page.
5002
7150
  [NSNotificationCenter.defaultCenter postNotificationName:@"OneKeyNativeListCancelScrollCommand" object:scrollView];
@@ -5009,7 +7157,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
5009
7157
  [_alignedBodyKeys removeObject:key];
5010
7158
  [_suspendedBodyKeys removeObject:key];
5011
7159
  [_displayBodyOverrides removeObjectForKey:key];
5012
- CGFloat logicalTarget = target == 1 ? _headerHeight : 0;
7160
+ logicalTarget = MIN(MAX(logicalTarget, 0), _headerHeight);
5013
7161
  _pageOffsets[key] = @(_nativeSmoothHeaderScrollEnabled ? 0 : logicalTarget);
5014
7162
  _pagerTopScrollView = scrollView;
5015
7163
  _pagerTopPageKey = [key copy];
@@ -5026,6 +7174,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
5026
7174
  [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, physicalTarget) animated:animated];
5027
7175
  _dispatchingPagerTop = NO;
5028
7176
  [self finishPagerTopIfReached];
7177
+ return YES;
5029
7178
  }
5030
7179
 
5031
7180
  - (void)setPage:(NSInteger)index