@onekeyfe/react-native-pager-view 6.7.0-4 → 6.7.0-40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/android/build.gradle +1 -0
- package/android/src/androidTest/AndroidManifest.xml +7 -0
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +233 -43
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +596 -27
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
- package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
- package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
- package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
- package/docs/SPEC.md +700 -10
- package/ios/RNCCollapsiblePagerViewComponentView.mm +2221 -94
- package/ios/RNCNativeScrollerComponentView.h +2 -0
- package/ios/RNCNativeScrollerComponentView.mm +42 -0
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +562 -1
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
- package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
- package/lib/module/CollapsiblePagerView.js +75 -11
- package/lib/module/CollapsiblePagerView.web.js +653 -8
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/lib/module/NativeScroller.web.js +3 -0
- package/lib/module/NativeScrollerNativeComponent.ts +42 -46
- package/lib/module/PagerViewNativeComponent.ts +20 -25
- package/lib/module/WebCollapsiblePagerPage.js +7 -2
- package/lib/module/index.native.js +9 -0
- package/lib/typescript/src/CollapsiblePagerView.d.ts +62 -4
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +56 -2
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
- package/lib/typescript/src/NativeScroller.d.ts +5 -3
- package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
- package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
- package/lib/typescript/src/PagerView.d.ts +1 -1
- package/lib/typescript/src/PagerView.web.d.ts +1 -1
- package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
- package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
- package/lib/typescript/src/index.native.d.ts +13 -0
- package/lib/typescript/src/usePagerView.d.ts +2 -2
- package/lib/typescript/src/utils.d.ts +2 -2
- package/package.json +22 -7
- package/react-native-pager-view.podspec +1 -0
- package/src/CollapsiblePagerView.tsx +208 -12
- package/src/CollapsiblePagerView.web.tsx +587 -7
- package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/src/NativeScroller.tsx +14 -4
- package/src/NativeScroller.web.tsx +15 -1
- package/src/NativeScrollerNativeComponent.ts +42 -46
- package/src/PagerViewNativeComponent.ts +20 -25
- package/src/WebCollapsiblePagerPage.tsx +7 -2
- package/src/index.native.tsx +30 -0
|
@@ -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,26 @@ 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
|
+
|
|
153
210
|
static UIView *RNCScrollComponentView(UIScrollView *scrollView)
|
|
154
211
|
{
|
|
155
212
|
for (UIView *view = scrollView; view != nil; view = view.superview) {
|
|
@@ -344,11 +401,70 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
344
401
|
(long)pagerState]);
|
|
345
402
|
}
|
|
346
403
|
|
|
404
|
+
static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFloat fallback, CGFloat minimum, CGFloat maximum)
|
|
405
|
+
{
|
|
406
|
+
id value = entry[key];
|
|
407
|
+
if (![value isKindOfClass:NSNumber.class]) return fallback;
|
|
408
|
+
double dimension = [value doubleValue];
|
|
409
|
+
return std::isfinite(dimension) ? MIN(maximum, MAX(minimum, dimension)) : fallback;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
@protocol RNCPagerNamedSVGBridge <NSObject>
|
|
413
|
+
+ (void)cancelWithOwner:(id)owner;
|
|
414
|
+
+ (void)requestWithOwner:(id)owner name:(NSString *)name color:(NSString *)color
|
|
415
|
+
width:(NSInteger)width height:(NSInteger)height scale:(double)scale
|
|
416
|
+
complete:(void (^)(UIImage *))complete;
|
|
417
|
+
@end
|
|
418
|
+
|
|
419
|
+
@interface RNCPagerToolbarButton : UIButton
|
|
420
|
+
@property (nonatomic, strong) UIColor *baseColor;
|
|
421
|
+
@property (nonatomic, strong) UIColor *hoverColor;
|
|
422
|
+
@property (nonatomic, strong) UIColor *pressedColor;
|
|
423
|
+
@property (nonatomic) BOOL hovering;
|
|
424
|
+
@property (nonatomic) CGFloat iconSize;
|
|
425
|
+
- (void)refreshBackground;
|
|
426
|
+
@end
|
|
427
|
+
@implementation RNCPagerToolbarButton
|
|
428
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
429
|
+
if ((self = [super initWithFrame:frame])) {
|
|
430
|
+
self.adjustsImageWhenHighlighted = NO;
|
|
431
|
+
[self addGestureRecognizer:[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hover:)]];
|
|
432
|
+
}
|
|
433
|
+
return self;
|
|
434
|
+
}
|
|
435
|
+
- (CGRect)imageRectForContentRect:(CGRect)contentRect {
|
|
436
|
+
CGFloat side = MIN(self.iconSize, MIN(CGRectGetWidth(contentRect), CGRectGetHeight(contentRect)));
|
|
437
|
+
return CGRectMake(CGRectGetMidX(contentRect) - side / 2, CGRectGetMidY(contentRect) - side / 2, side, side);
|
|
438
|
+
}
|
|
439
|
+
- (void)hover:(UIHoverGestureRecognizer *)gesture {
|
|
440
|
+
self.hovering = gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged;
|
|
441
|
+
[self refreshBackground];
|
|
442
|
+
}
|
|
443
|
+
- (void)setEnabled:(BOOL)enabled {
|
|
444
|
+
[super setEnabled:enabled];
|
|
445
|
+
if (!enabled) self.hovering = NO;
|
|
446
|
+
[self refreshBackground];
|
|
447
|
+
}
|
|
448
|
+
- (void)setHighlighted:(BOOL)highlighted {
|
|
449
|
+
[super setHighlighted:highlighted];
|
|
450
|
+
[self refreshBackground];
|
|
451
|
+
}
|
|
452
|
+
- (void)refreshBackground {
|
|
453
|
+
self.backgroundColor = self.enabled && self.highlighted ? self.pressedColor : (self.enabled && self.hovering ? self.hoverColor : self.baseColor);
|
|
454
|
+
}
|
|
455
|
+
@end
|
|
456
|
+
|
|
347
457
|
@interface RNCCollapsiblePagerNativeTabBarView : UIView <UIScrollViewDelegate>
|
|
348
458
|
@property (nonatomic, copy) RNCCollapsiblePagerNativeTabPressHandler onTabPress;
|
|
459
|
+
@property (nonatomic, copy) void (^onToolbarPress)(NSString *, CGRect);
|
|
460
|
+
@property (nonatomic, copy) void (^onToolbarNeedsSettlement)(void);
|
|
461
|
+
- (void)updateToolbarPagerIndex:(NSInteger)index busy:(BOOL)busy;
|
|
462
|
+
- (void)updateConfigJSON:(NSString *)json;
|
|
349
463
|
- (void)updateItemsJSON:(NSString *)itemsJSON;
|
|
350
464
|
- (void)updateStyleWithHeight:(CGFloat)height
|
|
465
|
+
variant:(NSString *)variant
|
|
351
466
|
contentPaddingHorizontal:(CGFloat)contentPaddingHorizontal
|
|
467
|
+
contentPaddingVertical:(CGFloat)contentPaddingVertical
|
|
352
468
|
itemSpacing:(CGFloat)itemSpacing
|
|
353
469
|
fontSize:(CGFloat)fontSize
|
|
354
470
|
fontFamily:(NSString *)fontFamily
|
|
@@ -359,18 +475,58 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
359
475
|
indicatorHeight:(CGFloat)indicatorHeight
|
|
360
476
|
indicatorBottom:(CGFloat)indicatorBottom;
|
|
361
477
|
- (void)setProgress:(CGFloat)progress;
|
|
478
|
+
- (BOOL)usesControlledTextProgress;
|
|
479
|
+
- (BOOL)ownsSettledToolbar;
|
|
362
480
|
- (void)setLeftToRight:(BOOL)leftToRight;
|
|
363
481
|
- (void)updateAncestorGesturePrecedence;
|
|
364
482
|
@end
|
|
365
483
|
|
|
366
484
|
@implementation RNCCollapsiblePagerNativeTabBarView {
|
|
367
485
|
RNCCollapsiblePagerHorizontalScrollView *_scrollView;
|
|
486
|
+
UIView *_trackView;
|
|
368
487
|
UIView *_indicatorView;
|
|
369
488
|
NSArray<NSDictionary *> *_items;
|
|
370
489
|
NSMutableArray<UIButton *> *_buttons;
|
|
371
490
|
NSMutableArray<NSValue *> *_indicatorFrames;
|
|
372
491
|
CGFloat _barHeight;
|
|
373
492
|
CGFloat _contentPaddingHorizontal;
|
|
493
|
+
CGFloat _contentPaddingVertical;
|
|
494
|
+
BOOL _segmented;
|
|
495
|
+
BOOL _textVariant;
|
|
496
|
+
BOOL _pillVariant;
|
|
497
|
+
NSDictionary *_config;
|
|
498
|
+
RNCPagerToolbarButton *_toolbarButton;
|
|
499
|
+
NSString *_toolbarKey;
|
|
500
|
+
BOOL _toolbarPagerBusy;
|
|
501
|
+
NSInteger _toolbarPageIndex;
|
|
502
|
+
NSDictionary *_committedToolbarEntry;
|
|
503
|
+
NSString *_desiredToolbarKey;
|
|
504
|
+
NSDictionary *_desiredToolbarEntry;
|
|
505
|
+
UIImage *_loadedToolbarImage;
|
|
506
|
+
BOOL _toolbarPresenceAnimating;
|
|
507
|
+
BOOL _toolbarPresenceInterrupted;
|
|
508
|
+
NSString *_toolbarTouchKey;
|
|
509
|
+
BOOL _toolbarTouchStarted;
|
|
510
|
+
NSString *_iconIdentity;
|
|
511
|
+
NSObject *_iconOwner;
|
|
512
|
+
NSInteger _progressSource;
|
|
513
|
+
NSInteger _progressDestination;
|
|
514
|
+
CGFloat _progressFraction;
|
|
515
|
+
CGFloat _nativeProgress;
|
|
516
|
+
BOOL _hasNativeProgress;
|
|
517
|
+
BOOL _hasMappedPageProgress;
|
|
518
|
+
CGFloat _toolbarReservedWidth;
|
|
519
|
+
BOOL _toolbarVisible;
|
|
520
|
+
NSUInteger _toolbarAnimationGeneration;
|
|
521
|
+
NSString *_loadedIconIdentity;
|
|
522
|
+
BOOL _iconRequestPending;
|
|
523
|
+
UIImage *_readyToolbarImage;
|
|
524
|
+
NSString *_readyToolbarIdentity;
|
|
525
|
+
NSString *_failedIconIdentity;
|
|
526
|
+
CGFloat _toolbarSize;
|
|
527
|
+
CGFloat _toolbarIconSize;
|
|
528
|
+
CGFloat _toolbarContentWidth;
|
|
529
|
+
CGFloat _toolbarTrailingInset;
|
|
374
530
|
CGFloat _itemSpacing;
|
|
375
531
|
CGFloat _fontSize;
|
|
376
532
|
NSString *_fontFamily;
|
|
@@ -389,10 +545,27 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
389
545
|
{
|
|
390
546
|
if (self = [super initWithFrame:frame]) {
|
|
391
547
|
_items = @[];
|
|
548
|
+
_config = @{};
|
|
549
|
+
_toolbarPagerBusy = YES;
|
|
550
|
+
_toolbarPageIndex = -1;
|
|
551
|
+
_toolbarButton = [RNCPagerToolbarButton new];
|
|
552
|
+
_toolbarButton.layer.cornerRadius = 19;
|
|
553
|
+
_toolbarButton.hidden = YES;
|
|
554
|
+
_toolbarButton.alpha = 0;
|
|
555
|
+
_toolbarButton.userInteractionEnabled = NO;
|
|
556
|
+
_toolbarButton.accessibilityElementsHidden = YES;
|
|
557
|
+
_toolbarButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
558
|
+
_toolbarButton.iconSize = 24;
|
|
559
|
+
[_toolbarButton addTarget:self action:@selector(toolbarTouchDown) forControlEvents:UIControlEventTouchDown];
|
|
560
|
+
[_toolbarButton addTarget:self action:@selector(toolbarPress:forEvent:) forControlEvents:UIControlEventTouchUpInside];
|
|
561
|
+
[_toolbarButton addTarget:self action:@selector(toolbarCancel) forControlEvents:UIControlEventTouchCancel | UIControlEventTouchUpOutside];
|
|
562
|
+
[self addSubview:_toolbarButton];
|
|
392
563
|
_buttons = [NSMutableArray new];
|
|
393
564
|
_indicatorFrames = [NSMutableArray new];
|
|
394
565
|
_barHeight = 44;
|
|
395
566
|
_contentPaddingHorizontal = 20;
|
|
567
|
+
_contentPaddingVertical = 0;
|
|
568
|
+
_segmented = NO;
|
|
396
569
|
_itemSpacing = 8;
|
|
397
570
|
_fontSize = 16;
|
|
398
571
|
_activeTextColor = UIColor.labelColor;
|
|
@@ -414,6 +587,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
414
587
|
_scrollView.delegate = self;
|
|
415
588
|
[self addSubview:_scrollView];
|
|
416
589
|
|
|
590
|
+
_trackView = [UIView new];
|
|
591
|
+
_trackView.userInteractionEnabled = NO;
|
|
592
|
+
[_scrollView addSubview:_trackView];
|
|
593
|
+
|
|
417
594
|
_indicatorView = [UIView new];
|
|
418
595
|
_indicatorView.userInteractionEnabled = NO;
|
|
419
596
|
[_scrollView addSubview:_indicatorView];
|
|
@@ -430,6 +607,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
430
607
|
return [UIFont systemFontOfSize:_fontSize weight:UIFontWeightMedium];
|
|
431
608
|
}
|
|
432
609
|
|
|
610
|
+
- (UIFont *)activeTabFont
|
|
611
|
+
{
|
|
612
|
+
NSString *activeFamily = _config[@"activeFontFamily"];
|
|
613
|
+
if (activeFamily.length > 0) {
|
|
614
|
+
return [UIFont fontWithName:activeFamily size:_fontSize]
|
|
615
|
+
?: [UIFont systemFontOfSize:_fontSize weight:UIFontWeightSemibold];
|
|
616
|
+
}
|
|
617
|
+
UIFont *normalFont = _fontFamily.length > 0 ? [UIFont fontWithName:_fontFamily size:_fontSize] : nil;
|
|
618
|
+
return normalFont != nil ? [RCTFont updateFont:normalFont withWeight:@"600"]
|
|
619
|
+
: [UIFont systemFontOfSize:_fontSize weight:UIFontWeightSemibold];
|
|
620
|
+
}
|
|
621
|
+
|
|
433
622
|
- (void)updateItemsJSON:(NSString *)itemsJSON
|
|
434
623
|
{
|
|
435
624
|
NSData *data = [itemsJSON dataUsingEncoding:NSUTF8StringEncoding];
|
|
@@ -464,11 +653,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
464
653
|
for (UIButton *button in _buttons) [_scrollView bringSubviewToFront:button];
|
|
465
654
|
_shouldCenterSelectedItem = YES;
|
|
466
655
|
self.hidden = _items.count == 0;
|
|
656
|
+
if (_hasNativeProgress) [self setProgress:_nativeProgress];
|
|
657
|
+
else if ([_config[@"controlled"] boolValue]) {
|
|
658
|
+
NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
|
|
659
|
+
if (selected != NSNotFound) { _progress = selected; _progressSource = selected; _progressDestination = selected; _progressFraction = 0; }
|
|
660
|
+
}
|
|
467
661
|
[self setNeedsLayout];
|
|
468
662
|
}
|
|
469
663
|
|
|
470
664
|
- (void)updateStyleWithHeight:(CGFloat)height
|
|
665
|
+
variant:(NSString *)variant
|
|
471
666
|
contentPaddingHorizontal:(CGFloat)contentPaddingHorizontal
|
|
667
|
+
contentPaddingVertical:(CGFloat)contentPaddingVertical
|
|
472
668
|
itemSpacing:(CGFloat)itemSpacing
|
|
473
669
|
fontSize:(CGFloat)fontSize
|
|
474
670
|
fontFamily:(NSString *)fontFamily
|
|
@@ -480,19 +676,28 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
480
676
|
indicatorBottom:(CGFloat)indicatorBottom
|
|
481
677
|
{
|
|
482
678
|
_barHeight = MAX(1, height);
|
|
679
|
+
BOOL wasSegmented = _segmented;
|
|
680
|
+
_segmented = [variant isEqualToString:@"segmented"];
|
|
681
|
+
_textVariant = [variant isEqualToString:@"text"];
|
|
682
|
+
_pillVariant = [variant isEqualToString:@"pill"];
|
|
483
683
|
_contentPaddingHorizontal = MAX(0, contentPaddingHorizontal);
|
|
684
|
+
_contentPaddingVertical = MAX(0, contentPaddingVertical);
|
|
484
685
|
_itemSpacing = MAX(0, itemSpacing);
|
|
485
686
|
_fontSize = MAX(1, fontSize);
|
|
486
687
|
_fontFamily = [fontFamily copy];
|
|
487
|
-
self.backgroundColor = backgroundColor ?: UIColor.clearColor;
|
|
488
|
-
_scrollView.backgroundColor = self.backgroundColor;
|
|
688
|
+
self.backgroundColor = _segmented ? UIColor.clearColor : (backgroundColor ?: UIColor.clearColor);
|
|
689
|
+
_scrollView.backgroundColor = _textVariant ? UIColor.clearColor : self.backgroundColor;
|
|
690
|
+
_scrollView.scrollEnabled = !_segmented;
|
|
691
|
+
if (_segmented && !wasSegmented) [_scrollView setContentOffset:CGPointZero animated:NO];
|
|
692
|
+
_trackView.hidden = !_segmented;
|
|
693
|
+
_trackView.backgroundColor = backgroundColor ?: UIColor.clearColor;
|
|
489
694
|
_activeTextColor = activeTextColor ?: UIColor.labelColor;
|
|
490
695
|
_inactiveTextColor = inactiveTextColor ?: UIColor.secondaryLabelColor;
|
|
491
696
|
_indicatorColor = indicatorColor ?: _activeTextColor;
|
|
492
697
|
_indicatorHeight = MAX(0, indicatorHeight);
|
|
493
698
|
_indicatorBottom = MAX(0, indicatorBottom);
|
|
494
699
|
_indicatorView.backgroundColor = _indicatorColor;
|
|
495
|
-
_indicatorView.layer.cornerRadius = _indicatorHeight / 2;
|
|
700
|
+
_indicatorView.layer.cornerRadius = _segmented ? 0 : _indicatorHeight / 2;
|
|
496
701
|
for (UIButton *button in _buttons) button.titleLabel.font = self.tabFont;
|
|
497
702
|
[self setNeedsLayout];
|
|
498
703
|
}
|
|
@@ -547,22 +752,83 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
547
752
|
RNCLogNativeTabScrollBoundary(@"primary", @"end", scrollView, _scrollStartOffsetX);
|
|
548
753
|
}
|
|
549
754
|
|
|
755
|
+
- (CGFloat)itemPaddingHorizontal
|
|
756
|
+
{
|
|
757
|
+
id value = _config[@"itemPaddingHorizontal"];
|
|
758
|
+
if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] >= 0) {
|
|
759
|
+
return [value doubleValue];
|
|
760
|
+
}
|
|
761
|
+
return _textVariant ? 10 : (_pillVariant ? 14 : 8);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// The tab row and toolbar share a centered band no wider than contentMaxWidth;
|
|
765
|
+
// the bar background still covers the full width.
|
|
766
|
+
- (CGRect)contentRowFrame
|
|
767
|
+
{
|
|
768
|
+
CGFloat width = CGRectGetWidth(self.bounds);
|
|
769
|
+
id value = _config[@"contentMaxWidth"];
|
|
770
|
+
if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] > 0 &&
|
|
771
|
+
[value doubleValue] < width) {
|
|
772
|
+
CGFloat rowWidth = [value doubleValue];
|
|
773
|
+
return CGRectMake(floor((width - rowWidth) / 2), 0, rowWidth, CGRectGetHeight(self.bounds));
|
|
774
|
+
}
|
|
775
|
+
return self.bounds;
|
|
776
|
+
}
|
|
777
|
+
|
|
550
778
|
- (void)layoutSubviews
|
|
551
779
|
{
|
|
552
780
|
[super layoutSubviews];
|
|
553
|
-
|
|
781
|
+
CGFloat reserved = _toolbarReservedWidth;
|
|
782
|
+
CGRect row = [self contentRowFrame];
|
|
783
|
+
[self bringSubviewToFront:_toolbarButton];
|
|
784
|
+
_scrollView.frame = CGRectMake(CGRectGetMinX(row) + (_leftToRight ? 0 : reserved), 0,
|
|
785
|
+
MAX(0, CGRectGetWidth(row) - reserved), CGRectGetHeight(self.bounds));
|
|
786
|
+
CGFloat inset = _toolbarTrailingInset - (_toolbarSize - _toolbarContentWidth) / 2;
|
|
787
|
+
_toolbarButton.frame = CGRectMake(_leftToRight ? CGRectGetMaxX(row) - inset - _toolbarSize : CGRectGetMinX(row) + inset,
|
|
788
|
+
(CGRectGetHeight(self.bounds) - _toolbarSize) / 2, _toolbarSize, _toolbarSize);
|
|
789
|
+
if (_segmented) {
|
|
790
|
+
CGFloat width = CGRectGetWidth(_scrollView.bounds);
|
|
791
|
+
CGFloat height = CGRectGetHeight(self.bounds);
|
|
792
|
+
CGFloat insetX = MIN(_contentPaddingHorizontal, width / 2);
|
|
793
|
+
CGFloat insetY = MIN(_contentPaddingVertical, height / 2);
|
|
794
|
+
CGRect trackFrame = CGRectMake(insetX, insetY,
|
|
795
|
+
MAX(0, width - 2 * insetX), MAX(0, height - 2 * insetY));
|
|
796
|
+
_trackView.frame = trackFrame;
|
|
797
|
+
_trackView.layer.cornerRadius = CGRectGetHeight(trackFrame) / 2;
|
|
798
|
+
_scrollView.contentSize = _scrollView.bounds.size;
|
|
799
|
+
[_indicatorFrames removeAllObjects];
|
|
800
|
+
NSUInteger count = _buttons.count;
|
|
801
|
+
[_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
|
|
802
|
+
CGFloat first = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) * index / count;
|
|
803
|
+
CGFloat last = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) * (index + 1) / count;
|
|
804
|
+
CGFloat x = self->_leftToRight ? first : CGRectGetMaxX(trackFrame) - (last - CGRectGetMinX(trackFrame));
|
|
805
|
+
CGFloat end = self->_leftToRight ? last : CGRectGetMaxX(trackFrame) - (first - CGRectGetMinX(trackFrame));
|
|
806
|
+
button.frame = CGRectMake(x, CGRectGetMinY(trackFrame), MAX(0, end - x), CGRectGetHeight(trackFrame));
|
|
807
|
+
CGRect thumbFrame = CGRectMake(x + 2, CGRectGetMinY(trackFrame) + 2,
|
|
808
|
+
MAX(0, CGRectGetWidth(button.frame) - 4), MAX(0, CGRectGetHeight(trackFrame) - 4));
|
|
809
|
+
[self->_indicatorFrames addObject:[NSValue valueWithCGRect:thumbFrame]];
|
|
810
|
+
}];
|
|
811
|
+
_indicatorView.layer.cornerRadius = MAX(0, CGRectGetHeight(trackFrame) - 4) / 2;
|
|
812
|
+
[self updatePresentation];
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
_trackView.frame = CGRectZero;
|
|
554
816
|
UIFont *font = self.tabFont;
|
|
555
817
|
NSMutableArray<NSNumber *> *widths = [NSMutableArray arrayWithCapacity:_buttons.count];
|
|
556
818
|
CGFloat itemsWidth = 0;
|
|
557
819
|
for (UIButton *button in _buttons) {
|
|
558
820
|
NSString *title = [button titleForState:UIControlStateNormal] ?: @"";
|
|
559
821
|
CGFloat textWidth = ceil([title sizeWithAttributes:@{NSFontAttributeName: font}].width);
|
|
560
|
-
|
|
822
|
+
if (_textVariant) {
|
|
823
|
+
UIFont *activeFont = self.activeTabFont;
|
|
824
|
+
textWidth = MAX(textWidth, ceil([title sizeWithAttributes:@{NSFontAttributeName: activeFont}].width));
|
|
825
|
+
}
|
|
826
|
+
CGFloat buttonWidth = MAX(44, textWidth + 2 * self.itemPaddingHorizontal);
|
|
561
827
|
[widths addObject:@(buttonWidth)];
|
|
562
828
|
itemsWidth += buttonWidth;
|
|
563
829
|
}
|
|
564
830
|
if (_buttons.count > 1) itemsWidth += (_buttons.count - 1) * _itemSpacing;
|
|
565
|
-
CGFloat contentWidth = MAX(CGRectGetWidth(
|
|
831
|
+
CGFloat contentWidth = MAX(CGRectGetWidth(_scrollView.bounds),
|
|
566
832
|
itemsWidth + _contentPaddingHorizontal * 2);
|
|
567
833
|
_scrollView.contentSize = CGSizeMake(contentWidth, MAX(_barHeight, CGRectGetHeight(self.bounds)));
|
|
568
834
|
[_indicatorFrames removeAllObjects];
|
|
@@ -573,6 +839,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
573
839
|
[_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
|
|
574
840
|
CGFloat buttonWidth = widths[index].doubleValue;
|
|
575
841
|
if (!self->_leftToRight) x -= buttonWidth;
|
|
842
|
+
if (self->_pillVariant) {
|
|
843
|
+
CGFloat insetY = MIN(self->_contentPaddingVertical, self->_barHeight / 2);
|
|
844
|
+
button.frame = CGRectMake(x, insetY, buttonWidth, MAX(0, self->_barHeight - 2 * insetY));
|
|
845
|
+
[self->_indicatorFrames addObject:[NSValue valueWithCGRect:button.frame]];
|
|
846
|
+
if (self->_leftToRight) x += buttonWidth + self->_itemSpacing;
|
|
847
|
+
else x -= self->_itemSpacing;
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
576
850
|
button.frame = CGRectMake(x, 0, buttonWidth, self->_barHeight);
|
|
577
851
|
NSString *title = [button titleForState:UIControlStateNormal] ?: @"";
|
|
578
852
|
CGFloat textWidth = ceil([title sizeWithAttributes:@{NSFontAttributeName: font}].width);
|
|
@@ -592,19 +866,515 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
592
866
|
[self updatePresentation];
|
|
593
867
|
}
|
|
594
868
|
|
|
869
|
+
- (Class<RNCPagerNamedSVGBridge>)iconBridge {
|
|
870
|
+
Class cls = NSClassFromString(@"OneKeyNamedSVGBridge");
|
|
871
|
+
if (![cls respondsToSelector:@selector(cancelWithOwner:)] ||
|
|
872
|
+
![cls respondsToSelector:@selector(requestWithOwner:name:color:width:height:scale:complete:)]) return Nil;
|
|
873
|
+
return (Class<RNCPagerNamedSVGBridge>)cls;
|
|
874
|
+
}
|
|
875
|
+
- (void)updateConfigJSON:(NSString *)json {
|
|
876
|
+
BOOL wasOwned = [self ownsSettledToolbar];
|
|
877
|
+
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
|
878
|
+
id parsed = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
879
|
+
_config = [parsed isKindOfClass:NSDictionary.class] ? parsed : @{};
|
|
880
|
+
BOOL owned = [self ownsSettledToolbar];
|
|
881
|
+
if (owned != wasOwned) {
|
|
882
|
+
if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
|
|
883
|
+
_iconOwner = [NSObject new];
|
|
884
|
+
_iconRequestPending = NO;
|
|
885
|
+
_readyToolbarImage = nil;
|
|
886
|
+
_readyToolbarIdentity = nil;
|
|
887
|
+
_desiredToolbarKey = nil;
|
|
888
|
+
_desiredToolbarEntry = nil;
|
|
889
|
+
[self suspendToolbar];
|
|
890
|
+
if (!owned) {
|
|
891
|
+
++_toolbarAnimationGeneration;
|
|
892
|
+
[_toolbarButton.layer removeAllAnimations];
|
|
893
|
+
_toolbarPresenceAnimating = NO;
|
|
894
|
+
_toolbarPresenceInterrupted = NO;
|
|
895
|
+
_toolbarButton.alpha = _toolbarVisible ? 1 : 0;
|
|
896
|
+
_toolbarButton.hidden = !_toolbarVisible;
|
|
897
|
+
[self setToolbarInteractive:_toolbarVisible];
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if (!owned) {
|
|
901
|
+
_toolbarTouchKey = nil;
|
|
902
|
+
_toolbarButton.highlighted = NO;
|
|
903
|
+
_toolbarButton.hovering = NO;
|
|
904
|
+
}
|
|
905
|
+
_toolbarButton.adjustsImageWhenDisabled = !owned;
|
|
906
|
+
NSString *key = _config[@"selectedKey"];
|
|
907
|
+
if (![_config[@"controlled"] boolValue]) {
|
|
908
|
+
_progress = RNCClamp(_nativeProgress, 0, MAX(0, (NSInteger)_items.count - 1));
|
|
909
|
+
key = _items.count ? _items[(NSInteger)round(_progress)][@"key"] : nil;
|
|
910
|
+
}
|
|
911
|
+
if (_hasNativeProgress) {
|
|
912
|
+
[self setProgress:_nativeProgress];
|
|
913
|
+
} else {
|
|
914
|
+
NSUInteger index = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:key]; }];
|
|
915
|
+
if (index != NSNotFound) {
|
|
916
|
+
_progress = index;
|
|
917
|
+
_progressSource = index;
|
|
918
|
+
_progressDestination = index;
|
|
919
|
+
_progressFraction = 0;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
[self updateToolbarForKey:key];
|
|
923
|
+
[self setNeedsLayout];
|
|
924
|
+
}
|
|
925
|
+
- (BOOL)pillAnimationDisabled
|
|
926
|
+
{
|
|
927
|
+
id value = _config[@"indicatorAnimationEnabled"];
|
|
928
|
+
return _pillVariant && [value isKindOfClass:NSNumber.class] && ![value boolValue];
|
|
929
|
+
}
|
|
930
|
+
- (BOOL)usesControlledTextProgress {
|
|
931
|
+
return (_textVariant || (_pillVariant && !self.pillAnimationDisabled)) && [_config[@"controlled"] boolValue];
|
|
932
|
+
}
|
|
933
|
+
- (void)setLegacyToolbarVisible:(BOOL)visible {
|
|
934
|
+
_toolbarButton.enabled = visible;
|
|
935
|
+
_toolbarButton.userInteractionEnabled = visible;
|
|
936
|
+
_toolbarButton.accessibilityElementsHidden = !visible;
|
|
937
|
+
_toolbarButton.isAccessibilityElement = visible;
|
|
938
|
+
if (_toolbarVisible == visible) return;
|
|
939
|
+
_toolbarVisible = visible;
|
|
940
|
+
NSUInteger generation = ++_toolbarAnimationGeneration;
|
|
941
|
+
CALayer *presentation = _toolbarButton.layer.presentationLayer;
|
|
942
|
+
CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
|
|
943
|
+
[_toolbarButton.layer removeAllAnimations];
|
|
944
|
+
_toolbarButton.alpha = alpha;
|
|
945
|
+
_toolbarButton.enabled = visible;
|
|
946
|
+
_toolbarButton.userInteractionEnabled = visible;
|
|
947
|
+
_toolbarButton.accessibilityElementsHidden = !visible;
|
|
948
|
+
if (visible) _toolbarButton.hidden = NO;
|
|
949
|
+
if (self.window == nil) {
|
|
950
|
+
_toolbarButton.alpha = visible ? 1 : 0;
|
|
951
|
+
_toolbarButton.hidden = !visible;
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
[UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
|
|
955
|
+
self->_toolbarButton.alpha = visible ? 1 : 0;
|
|
956
|
+
} completion:^(BOOL finished) {
|
|
957
|
+
if (self->_toolbarAnimationGeneration == generation && !visible) {
|
|
958
|
+
self->_toolbarButton.hidden = YES;
|
|
959
|
+
[self applyReadyLegacyToolbarImage];
|
|
960
|
+
}
|
|
961
|
+
}];
|
|
962
|
+
}
|
|
963
|
+
- (void)applyReadyLegacyToolbarImage {
|
|
964
|
+
if (_readyToolbarImage == nil || ![_readyToolbarIdentity isEqualToString:_iconIdentity]) return;
|
|
965
|
+
CALayer *presentation = _toolbarButton.layer.presentationLayer;
|
|
966
|
+
if (_toolbarButton.alpha > 0.001 || (presentation && presentation.opacity > 0.001)) return;
|
|
967
|
+
[_toolbarButton setImage:_readyToolbarImage forState:UIControlStateNormal];
|
|
968
|
+
_loadedIconIdentity = _readyToolbarIdentity;
|
|
969
|
+
_loadedToolbarImage = _readyToolbarImage;
|
|
970
|
+
_readyToolbarImage = nil;
|
|
971
|
+
_readyToolbarIdentity = nil;
|
|
972
|
+
_iconRequestPending = NO;
|
|
973
|
+
[self setLegacyToolbarVisible:YES];
|
|
974
|
+
}
|
|
975
|
+
- (void)updateLegacyToolbarForKey:(NSString *)key {
|
|
976
|
+
NSDictionary *toolbar = [_config[@"toolbar"] isKindOfClass:NSDictionary.class] ? _config[@"toolbar"] : nil;
|
|
977
|
+
_toolbarReservedWidth = toolbar == nil ? 0 : 44;
|
|
978
|
+
if (toolbar.count > 0) {
|
|
979
|
+
_toolbarReservedWidth = 0;
|
|
980
|
+
for (id value in toolbar.allValues) {
|
|
981
|
+
NSDictionary *entry = [value isKindOfClass:NSDictionary.class] ? value : @{};
|
|
982
|
+
CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
|
|
983
|
+
CGFloat content = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, size), 0, size);
|
|
984
|
+
CGFloat trailing = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
|
|
985
|
+
_toolbarReservedWidth = MAX(_toolbarReservedWidth, content + trailing);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
NSDictionary *entry = [toolbar[key ?: @""] isKindOfClass:NSDictionary.class] ? toolbar[key] : nil;
|
|
989
|
+
NSString *name = [entry[@"iconName"] isKindOfClass:NSString.class] ? entry[@"iconName"] : nil;
|
|
990
|
+
if (![_toolbarKey isEqualToString:key]) {
|
|
991
|
+
_toolbarTouchKey = nil;
|
|
992
|
+
_toolbarButton.highlighted = NO;
|
|
993
|
+
_toolbarButton.hovering = NO;
|
|
994
|
+
}
|
|
995
|
+
_toolbarKey = [key copy];
|
|
996
|
+
if (name.length == 0) {
|
|
997
|
+
_toolbarTouchKey = nil;
|
|
998
|
+
_toolbarButton.accessibilityLabel = nil;
|
|
999
|
+
_toolbarButton.accessibilityIdentifier = nil;
|
|
1000
|
+
if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
|
|
1001
|
+
_iconOwner = [NSObject new];
|
|
1002
|
+
_iconRequestPending = NO;
|
|
1003
|
+
_readyToolbarImage = nil;
|
|
1004
|
+
_readyToolbarIdentity = nil;
|
|
1005
|
+
[self setLegacyToolbarVisible:NO];
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
_toolbarSize = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
|
|
1009
|
+
_toolbarIconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, _toolbarSize), 1, _toolbarSize);
|
|
1010
|
+
_toolbarContentWidth = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, _toolbarSize), 0, _toolbarSize);
|
|
1011
|
+
_toolbarTrailingInset = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
|
|
1012
|
+
_toolbarButton.layer.cornerRadius = _toolbarSize / 2;
|
|
1013
|
+
_toolbarButton.iconSize = _toolbarIconSize;
|
|
1014
|
+
[_toolbarButton setNeedsLayout];
|
|
1015
|
+
_toolbarButton.baseColor = [entry[@"selected"] boolValue] ? ([RCTConvert UIColor:entry[@"selectedBackgroundColor"]] ?: UIColor.clearColor) : UIColor.clearColor;
|
|
1016
|
+
_toolbarButton.hoverColor = [RCTConvert UIColor:entry[@"hoverBackgroundColor"]] ?: _toolbarButton.baseColor;
|
|
1017
|
+
_toolbarButton.pressedColor = [RCTConvert UIColor:entry[@"pressedBackgroundColor"]] ?: _toolbarButton.baseColor;
|
|
1018
|
+
[_toolbarButton refreshBackground];
|
|
1019
|
+
_toolbarButton.accessibilityLabel = entry[@"accessibilityLabel"];
|
|
1020
|
+
_toolbarButton.accessibilityIdentifier = entry[@"testID"];
|
|
1021
|
+
NSString *color = [entry[@"iconColor"] isKindOfClass:NSString.class] ? entry[@"iconColor"] : @"#000000";
|
|
1022
|
+
CGFloat scale = self.window.screen.scale ?: UIScreen.mainScreen.scale;
|
|
1023
|
+
NSString *identity = [NSString stringWithFormat:@"%@|%@|%g|%g", name, color, scale, _toolbarIconSize];
|
|
1024
|
+
if ([_loadedIconIdentity isEqualToString:identity] && [_toolbarButton imageForState:UIControlStateNormal] != nil) {
|
|
1025
|
+
if (_iconRequestPending) {
|
|
1026
|
+
[[self iconBridge] cancelWithOwner:_iconOwner];
|
|
1027
|
+
_iconOwner = [NSObject new];
|
|
1028
|
+
}
|
|
1029
|
+
_iconIdentity = identity;
|
|
1030
|
+
_iconRequestPending = NO;
|
|
1031
|
+
_readyToolbarImage = nil;
|
|
1032
|
+
_readyToolbarIdentity = nil;
|
|
1033
|
+
[self setLegacyToolbarVisible:YES];
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
if ((_iconRequestPending || [_failedIconIdentity isEqualToString:identity]) && [_iconIdentity isEqualToString:identity]) return;
|
|
1037
|
+
if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
|
|
1038
|
+
NSObject *owner = [NSObject new];
|
|
1039
|
+
_iconOwner = owner;
|
|
1040
|
+
_iconIdentity = identity;
|
|
1041
|
+
_iconRequestPending = NO;
|
|
1042
|
+
_readyToolbarImage = nil;
|
|
1043
|
+
_readyToolbarIdentity = nil;
|
|
1044
|
+
[self setLegacyToolbarVisible:NO];
|
|
1045
|
+
if ([_failedIconIdentity isEqualToString:identity] || self.window == nil) return;
|
|
1046
|
+
_iconRequestPending = YES;
|
|
1047
|
+
__weak __typeof__(self) weakSelf = self;
|
|
1048
|
+
[[self iconBridge] requestWithOwner:owner name:name color:color width:(NSInteger)ceil(_toolbarIconSize * scale) height:(NSInteger)ceil(_toolbarIconSize * scale) scale:scale complete:^(UIImage *image) {
|
|
1049
|
+
__strong __typeof__(weakSelf) self = weakSelf;
|
|
1050
|
+
if (!self || self->_iconOwner != owner || ![self->_iconIdentity isEqualToString:identity] || !self.window) return;
|
|
1051
|
+
if (image == nil) {
|
|
1052
|
+
self->_iconRequestPending = NO;
|
|
1053
|
+
self->_failedIconIdentity = identity;
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
UIImage *scaled = image.CGImage ? [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] : image;
|
|
1057
|
+
self->_readyToolbarImage = [scaled imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
1058
|
+
self->_readyToolbarIdentity = identity;
|
|
1059
|
+
[self applyReadyLegacyToolbarImage];
|
|
1060
|
+
}];
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
- (BOOL)ownsSettledToolbar {
|
|
1064
|
+
return [_config[@"controlled"] boolValue] && [_config[@"toolbar"] isKindOfClass:NSDictionary.class];
|
|
1065
|
+
}
|
|
1066
|
+
- (BOOL)toolbarCanCommit {
|
|
1067
|
+
if (!self.window) return NO;
|
|
1068
|
+
if (![self ownsSettledToolbar]) return YES;
|
|
1069
|
+
if (_toolbarPagerBusy || _toolbarPageIndex < 0) return NO;
|
|
1070
|
+
NSArray *pages = [_config[@"pageKeys"] isKindOfClass:NSArray.class] ? _config[@"pageKeys"] : @[];
|
|
1071
|
+
NSArray *items = [_items valueForKey:@"key"];
|
|
1072
|
+
BOOL valid = pages.count > 0 && [pages containsObject:_config[@"selectedKey"] ?: @""] &&
|
|
1073
|
+
[NSSet setWithArray:pages].count == pages.count && [NSSet setWithArray:items].count == items.count;
|
|
1074
|
+
for (id key in pages) if (![items containsObject:key]) { valid = NO; break; }
|
|
1075
|
+
return !valid || (_toolbarPageIndex < pages.count && [pages[_toolbarPageIndex] isEqual:_config[@"selectedKey"]]);
|
|
1076
|
+
}
|
|
1077
|
+
- (void)setToolbarInteractive:(BOOL)interactive {
|
|
1078
|
+
_toolbarButton.enabled = interactive;
|
|
1079
|
+
_toolbarButton.userInteractionEnabled = interactive;
|
|
1080
|
+
_toolbarButton.accessibilityElementsHidden = !interactive;
|
|
1081
|
+
_toolbarButton.isAccessibilityElement = interactive;
|
|
1082
|
+
if (!interactive) {
|
|
1083
|
+
_toolbarTouchKey = nil;
|
|
1084
|
+
_toolbarButton.highlighted = NO;
|
|
1085
|
+
_toolbarButton.hovering = NO;
|
|
1086
|
+
[_toolbarButton refreshBackground];
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
- (void)cancelToolbarRequest {
|
|
1090
|
+
if (_iconRequestPending || _readyToolbarImage) {
|
|
1091
|
+
if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
|
|
1092
|
+
_iconOwner = [NSObject new];
|
|
1093
|
+
_iconRequestPending = NO;
|
|
1094
|
+
_readyToolbarImage = nil;
|
|
1095
|
+
_readyToolbarIdentity = nil;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
- (void)suspendToolbar {
|
|
1099
|
+
[self setToolbarInteractive:NO];
|
|
1100
|
+
[self cancelToolbarRequest];
|
|
1101
|
+
_desiredToolbarKey = nil;
|
|
1102
|
+
_desiredToolbarEntry = nil;
|
|
1103
|
+
if (_toolbarPresenceAnimating) {
|
|
1104
|
+
CALayer *presentation = _toolbarButton.layer.presentationLayer;
|
|
1105
|
+
CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
|
|
1106
|
+
++_toolbarAnimationGeneration;
|
|
1107
|
+
[_toolbarButton.layer removeAllAnimations];
|
|
1108
|
+
_toolbarButton.alpha = alpha;
|
|
1109
|
+
_toolbarPresenceAnimating = NO;
|
|
1110
|
+
_toolbarPresenceInterrupted = YES;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
- (void)updateToolbarPagerIndex:(NSInteger)index busy:(BOOL)busy {
|
|
1114
|
+
if (_toolbarPagerBusy == busy && (busy || _toolbarPageIndex == index)) return;
|
|
1115
|
+
_toolbarPagerBusy = busy;
|
|
1116
|
+
if (!busy) _toolbarPageIndex = index;
|
|
1117
|
+
NSString *key = [_config[@"controlled"] boolValue] ? _config[@"selectedKey"] : _toolbarKey;
|
|
1118
|
+
[self updateToolbarForKey:key];
|
|
1119
|
+
}
|
|
1120
|
+
- (void)setToolbarVisible:(BOOL)visible {
|
|
1121
|
+
if (_toolbarVisible == visible && !_toolbarPresenceInterrupted) return;
|
|
1122
|
+
_toolbarVisible = visible;
|
|
1123
|
+
_toolbarPresenceInterrupted = NO;
|
|
1124
|
+
NSUInteger generation = ++_toolbarAnimationGeneration;
|
|
1125
|
+
CALayer *presentation = _toolbarButton.layer.presentationLayer;
|
|
1126
|
+
CGFloat alpha = presentation ? presentation.opacity : _toolbarButton.alpha;
|
|
1127
|
+
[_toolbarButton.layer removeAllAnimations];
|
|
1128
|
+
_toolbarButton.alpha = alpha;
|
|
1129
|
+
if (visible) _toolbarButton.hidden = NO;
|
|
1130
|
+
if (!self.window) {
|
|
1131
|
+
_toolbarPresenceAnimating = NO;
|
|
1132
|
+
_toolbarButton.alpha = visible ? 1 : 0;
|
|
1133
|
+
_toolbarButton.hidden = !visible;
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
_toolbarPresenceAnimating = YES;
|
|
1137
|
+
[UIView animateWithDuration:0.10 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
|
|
1138
|
+
self->_toolbarButton.alpha = visible ? 1 : 0;
|
|
1139
|
+
} completion:^(BOOL finished) {
|
|
1140
|
+
if (self->_toolbarAnimationGeneration != generation) return;
|
|
1141
|
+
self->_toolbarPresenceAnimating = NO;
|
|
1142
|
+
if (!visible) self->_toolbarButton.hidden = YES;
|
|
1143
|
+
}];
|
|
1144
|
+
}
|
|
1145
|
+
- (void)commitToolbarImage:(UIImage *)image identity:(NSString *)identity {
|
|
1146
|
+
if (![self toolbarCanCommit] || !_desiredToolbarKey || !_desiredToolbarEntry) return;
|
|
1147
|
+
NSDictionary *entry = _desiredToolbarEntry;
|
|
1148
|
+
BOOL changed = ![_toolbarKey isEqualToString:_desiredToolbarKey] || ![_committedToolbarEntry isEqual:entry] || _loadedToolbarImage != image;
|
|
1149
|
+
if (![_toolbarKey isEqualToString:_desiredToolbarKey]) [self setToolbarInteractive:NO];
|
|
1150
|
+
_toolbarKey = [_desiredToolbarKey copy];
|
|
1151
|
+
_committedToolbarEntry = entry;
|
|
1152
|
+
_toolbarSize = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
|
|
1153
|
+
_toolbarIconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, _toolbarSize), 1, _toolbarSize);
|
|
1154
|
+
_toolbarContentWidth = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, _toolbarSize), 0, _toolbarSize);
|
|
1155
|
+
_toolbarTrailingInset = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
|
|
1156
|
+
_toolbarButton.layer.cornerRadius = _toolbarSize / 2;
|
|
1157
|
+
_toolbarButton.iconSize = _toolbarIconSize;
|
|
1158
|
+
[_toolbarButton setNeedsLayout];
|
|
1159
|
+
_toolbarButton.baseColor = [entry[@"selected"] boolValue] ? ([RCTConvert UIColor:entry[@"selectedBackgroundColor"]] ?: UIColor.clearColor) : UIColor.clearColor;
|
|
1160
|
+
_toolbarButton.hoverColor = [RCTConvert UIColor:entry[@"hoverBackgroundColor"]] ?: _toolbarButton.baseColor;
|
|
1161
|
+
_toolbarButton.pressedColor = [RCTConvert UIColor:entry[@"pressedBackgroundColor"]] ?: _toolbarButton.baseColor;
|
|
1162
|
+
[_toolbarButton refreshBackground];
|
|
1163
|
+
_toolbarButton.accessibilityLabel = entry[@"accessibilityLabel"];
|
|
1164
|
+
_toolbarButton.accessibilityIdentifier = entry[@"testID"];
|
|
1165
|
+
[_toolbarButton setImage:image forState:UIControlStateNormal];
|
|
1166
|
+
_loadedIconIdentity = identity;
|
|
1167
|
+
_loadedToolbarImage = image;
|
|
1168
|
+
_readyToolbarImage = nil;
|
|
1169
|
+
_readyToolbarIdentity = nil;
|
|
1170
|
+
_iconRequestPending = NO;
|
|
1171
|
+
[self setToolbarVisible:YES];
|
|
1172
|
+
[self setToolbarInteractive:YES];
|
|
1173
|
+
if (changed) [self setNeedsLayout];
|
|
1174
|
+
}
|
|
1175
|
+
- (void)applyReadyToolbarImage {
|
|
1176
|
+
if (!_readyToolbarImage || ![_readyToolbarIdentity isEqualToString:_iconIdentity] || ![self toolbarCanCommit]) return;
|
|
1177
|
+
[self commitToolbarImage:_readyToolbarImage identity:_readyToolbarIdentity];
|
|
1178
|
+
}
|
|
1179
|
+
- (void)hideFailedToolbar {
|
|
1180
|
+
[self setToolbarInteractive:NO];
|
|
1181
|
+
_toolbarKey = nil;
|
|
1182
|
+
_committedToolbarEntry = nil;
|
|
1183
|
+
[_toolbarButton setImage:nil forState:UIControlStateNormal];
|
|
1184
|
+
_toolbarButton.accessibilityLabel = nil;
|
|
1185
|
+
_toolbarButton.accessibilityIdentifier = nil;
|
|
1186
|
+
[self setToolbarVisible:NO];
|
|
1187
|
+
}
|
|
1188
|
+
- (void)updateToolbarForKey:(NSString *)key {
|
|
1189
|
+
if (![self ownsSettledToolbar]) { [self updateLegacyToolbarForKey:key]; return; }
|
|
1190
|
+
NSDictionary *toolbar = [_config[@"toolbar"] isKindOfClass:NSDictionary.class] ? _config[@"toolbar"] : nil;
|
|
1191
|
+
_toolbarReservedWidth = toolbar == nil ? 0 : 44;
|
|
1192
|
+
if (toolbar.count > 0) {
|
|
1193
|
+
_toolbarReservedWidth = 0;
|
|
1194
|
+
for (id value in toolbar.allValues) {
|
|
1195
|
+
NSDictionary *entry = [value isKindOfClass:NSDictionary.class] ? value : @{};
|
|
1196
|
+
CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
|
|
1197
|
+
CGFloat content = RNCPagerToolbarDimension(entry, @"contentWidth", MIN(24, size), 0, size);
|
|
1198
|
+
CGFloat trailing = RNCPagerToolbarDimension(entry, @"trailingInset", 20, 0, 128);
|
|
1199
|
+
_toolbarReservedWidth = MAX(_toolbarReservedWidth, content + trailing);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (![self toolbarCanCommit]) { [self suspendToolbar]; return; }
|
|
1203
|
+
NSDictionary *entry = [toolbar[key ?: @""] isKindOfClass:NSDictionary.class] ? toolbar[key] : nil;
|
|
1204
|
+
NSString *name = [entry[@"iconName"] isKindOfClass:NSString.class] ? entry[@"iconName"] : nil;
|
|
1205
|
+
if (!name.length) {
|
|
1206
|
+
[self cancelToolbarRequest];
|
|
1207
|
+
_desiredToolbarKey = nil;
|
|
1208
|
+
_desiredToolbarEntry = nil;
|
|
1209
|
+
_toolbarKey = nil;
|
|
1210
|
+
_committedToolbarEntry = nil;
|
|
1211
|
+
[self setToolbarInteractive:NO];
|
|
1212
|
+
_toolbarButton.accessibilityLabel = nil;
|
|
1213
|
+
_toolbarButton.accessibilityIdentifier = nil;
|
|
1214
|
+
[self setToolbarVisible:NO];
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
_desiredToolbarKey = [key copy];
|
|
1218
|
+
_desiredToolbarEntry = [entry copy];
|
|
1219
|
+
CGFloat size = RNCPagerToolbarDimension(entry, @"size", 38, 1, 128);
|
|
1220
|
+
CGFloat iconSize = RNCPagerToolbarDimension(entry, @"iconSize", MIN(24, size), 1, size);
|
|
1221
|
+
NSString *color = [entry[@"iconColor"] isKindOfClass:NSString.class] ? entry[@"iconColor"] : @"#000000";
|
|
1222
|
+
CGFloat scale = self.window.screen.scale ?: UIScreen.mainScreen.scale;
|
|
1223
|
+
NSString *identity = [NSString stringWithFormat:@"%@|%@|%g|%g", name, color, scale, iconSize];
|
|
1224
|
+
if ([_loadedIconIdentity isEqualToString:identity] && _loadedToolbarImage) {
|
|
1225
|
+
[self cancelToolbarRequest];
|
|
1226
|
+
_iconIdentity = identity;
|
|
1227
|
+
[self commitToolbarImage:_loadedToolbarImage identity:identity];
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
if ([_iconIdentity isEqualToString:identity] && (_iconRequestPending || _readyToolbarImage)) {
|
|
1231
|
+
[self setToolbarInteractive:NO];
|
|
1232
|
+
[self applyReadyToolbarImage];
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
[self cancelToolbarRequest];
|
|
1236
|
+
_iconIdentity = identity;
|
|
1237
|
+
[self setToolbarInteractive:NO];
|
|
1238
|
+
if ([_failedIconIdentity isEqualToString:identity]) { [self hideFailedToolbar]; return; }
|
|
1239
|
+
NSObject *owner = [NSObject new];
|
|
1240
|
+
_iconOwner = owner;
|
|
1241
|
+
_iconRequestPending = YES;
|
|
1242
|
+
__weak __typeof__(self) weakSelf = self;
|
|
1243
|
+
[[self iconBridge] requestWithOwner:owner name:name color:color width:(NSInteger)ceil(iconSize * scale) height:(NSInteger)ceil(iconSize * scale) scale:scale complete:^(UIImage *image) {
|
|
1244
|
+
__strong __typeof__(weakSelf) self = weakSelf;
|
|
1245
|
+
if (!self || self->_iconOwner != owner || ![self->_iconIdentity isEqualToString:identity] || !self.window) return;
|
|
1246
|
+
self->_iconRequestPending = NO;
|
|
1247
|
+
if (!image) {
|
|
1248
|
+
self->_failedIconIdentity = identity;
|
|
1249
|
+
if ([self toolbarCanCommit]) [self hideFailedToolbar];
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
UIImage *scaled = image.CGImage ? [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] : image;
|
|
1253
|
+
self->_readyToolbarImage = [scaled imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
1254
|
+
self->_readyToolbarIdentity = identity;
|
|
1255
|
+
[self applyReadyToolbarImage];
|
|
1256
|
+
}];
|
|
1257
|
+
}
|
|
1258
|
+
- (void)didMoveToWindow {
|
|
1259
|
+
[super didMoveToWindow];
|
|
1260
|
+
if (![self ownsSettledToolbar]) {
|
|
1261
|
+
if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner];
|
|
1262
|
+
_iconIdentity = nil;
|
|
1263
|
+
_loadedIconIdentity = nil;
|
|
1264
|
+
_iconRequestPending = NO;
|
|
1265
|
+
_readyToolbarImage = nil;
|
|
1266
|
+
_readyToolbarIdentity = nil;
|
|
1267
|
+
_failedIconIdentity = nil;
|
|
1268
|
+
_iconOwner = [NSObject new];
|
|
1269
|
+
_toolbarAnimationGeneration++;
|
|
1270
|
+
[_toolbarButton.layer removeAllAnimations];
|
|
1271
|
+
_toolbarVisible = NO;
|
|
1272
|
+
_toolbarButton.alpha = 0;
|
|
1273
|
+
_toolbarButton.hidden = YES;
|
|
1274
|
+
_toolbarButton.enabled = NO;
|
|
1275
|
+
_toolbarButton.userInteractionEnabled = NO;
|
|
1276
|
+
_toolbarButton.accessibilityElementsHidden = YES;
|
|
1277
|
+
_toolbarTouchKey = nil;
|
|
1278
|
+
_toolbarTouchStarted = NO;
|
|
1279
|
+
_toolbarButton.highlighted = NO;
|
|
1280
|
+
_toolbarButton.hovering = NO;
|
|
1281
|
+
[self updateToolbarForKey:_toolbarKey];
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
[self suspendToolbar];
|
|
1285
|
+
_toolbarPagerBusy = YES;
|
|
1286
|
+
_toolbarPageIndex = -1;
|
|
1287
|
+
_toolbarTouchStarted = NO;
|
|
1288
|
+
if (self.window && self.onToolbarNeedsSettlement) self.onToolbarNeedsSettlement();
|
|
1289
|
+
}
|
|
1290
|
+
- (void)dealloc { if (_iconOwner) [[self iconBridge] cancelWithOwner:_iconOwner]; }
|
|
1291
|
+
- (void)toolbarTouchDown {
|
|
1292
|
+
_toolbarTouchStarted = YES;
|
|
1293
|
+
_toolbarTouchKey = _toolbarButton.enabled && [self toolbarCanCommit] ? [_toolbarKey copy] : nil;
|
|
1294
|
+
}
|
|
1295
|
+
- (void)toolbarCancel {
|
|
1296
|
+
_toolbarTouchKey = nil;
|
|
1297
|
+
if (![self ownsSettledToolbar]) _toolbarTouchStarted = NO;
|
|
1298
|
+
}
|
|
1299
|
+
- (void)toolbarPress:(UIControl *)sender forEvent:(UIEvent *)event {
|
|
1300
|
+
if (![self ownsSettledToolbar]) {
|
|
1301
|
+
NSString *key = _toolbarTouchStarted ? _toolbarTouchKey : _toolbarKey;
|
|
1302
|
+
_toolbarTouchStarted = NO; _toolbarTouchKey = nil;
|
|
1303
|
+
if (key && [key isEqualToString:_toolbarKey] && !_toolbarButton.hidden && _toolbarButton.enabled && self.window && self.onToolbarPress)
|
|
1304
|
+
self.onToolbarPress(key, [_toolbarButton convertRect:_toolbarButton.bounds toView:self.window]);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
BOOL pointer = event && event.type == UIEventTypeTouches;
|
|
1308
|
+
NSString *key = pointer ? (_toolbarTouchStarted ? _toolbarTouchKey : nil) : _toolbarKey;
|
|
1309
|
+
if (pointer) { _toolbarTouchStarted = NO; _toolbarTouchKey = nil; }
|
|
1310
|
+
BOOL selectedMatches = ![_config[@"controlled"] boolValue] || [key isEqual:_config[@"selectedKey"]];
|
|
1311
|
+
if (key && selectedMatches && [key isEqualToString:_toolbarKey] && [self toolbarCanCommit] &&
|
|
1312
|
+
!_toolbarButton.hidden && _toolbarButton.enabled && self.onToolbarPress) {
|
|
1313
|
+
self.onToolbarPress(key, [_toolbarButton convertRect:_toolbarButton.bounds toView:self.window]);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
595
1317
|
- (void)setProgress:(CGFloat)progress
|
|
596
1318
|
{
|
|
1319
|
+
_hasMappedPageProgress = NO;
|
|
1320
|
+
_nativeProgress = progress;
|
|
1321
|
+
_hasNativeProgress = YES;
|
|
597
1322
|
if (_items.count == 0) return;
|
|
598
1323
|
if (fabs(_progress - progress) >= 0.001) _shouldCenterSelectedItem = YES;
|
|
1324
|
+
if ([_config[@"controlled"] boolValue]) {
|
|
1325
|
+
NSArray *pageKeys = [_config[@"pageKeys"] isKindOfClass:NSArray.class] ? _config[@"pageKeys"] : @[];
|
|
1326
|
+
NSMutableArray<NSNumber *> *indices = [NSMutableArray new];
|
|
1327
|
+
NSSet *unique = [NSSet setWithArray:pageKeys];
|
|
1328
|
+
NSArray *itemKeys = [_items valueForKey:@"key"];
|
|
1329
|
+
BOOL valid = pageKeys.count > 0 && [pageKeys containsObject:_config[@"selectedKey"] ?: @""] && unique.count == pageKeys.count && [NSSet setWithArray:itemKeys].count == itemKeys.count;
|
|
1330
|
+
for (NSString *key in pageKeys) {
|
|
1331
|
+
NSUInteger index = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:key]; }];
|
|
1332
|
+
if (index == NSNotFound) { valid = NO; break; }
|
|
1333
|
+
[indices addObject:@(index)];
|
|
1334
|
+
}
|
|
1335
|
+
if (!valid) {
|
|
1336
|
+
NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
|
|
1337
|
+
if (selected == NSNotFound) return;
|
|
1338
|
+
_progressSource = selected; _progressDestination = selected; _progressFraction = 0;
|
|
1339
|
+
_progress = selected;
|
|
1340
|
+
if (_indicatorFrames.count == _items.count) [self updatePresentation];
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
_hasMappedPageProgress = YES;
|
|
1344
|
+
CGFloat bounded = RNCClamp(progress, 0, pageKeys.count - 1);
|
|
1345
|
+
NSInteger lower = (NSInteger)floor(bounded);
|
|
1346
|
+
NSInteger upper = MIN(lower + 1, pageKeys.count - 1);
|
|
1347
|
+
_progressSource = indices[lower].integerValue;
|
|
1348
|
+
_progressDestination = indices[upper].integerValue;
|
|
1349
|
+
_progressFraction = bounded - lower;
|
|
1350
|
+
progress = _progressSource + (_progressDestination - _progressSource) * _progressFraction;
|
|
1351
|
+
}
|
|
599
1352
|
_progress = RNCClamp(progress, 0, _items.count - 1);
|
|
600
1353
|
if (_indicatorFrames.count == _items.count) [self updatePresentation];
|
|
601
1354
|
}
|
|
602
1355
|
|
|
1356
|
+
- (NSInteger)visualFontOwnerIndex:(NSInteger)semanticIndex {
|
|
1357
|
+
if (_textVariant && [_config[@"controlled"] boolValue] && _hasMappedPageProgress) {
|
|
1358
|
+
return _progressFraction < 0.5 ? _progressSource : _progressDestination;
|
|
1359
|
+
}
|
|
1360
|
+
return semanticIndex;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
603
1363
|
- (void)updatePresentation
|
|
604
1364
|
{
|
|
605
1365
|
NSInteger count = _buttons.count;
|
|
606
1366
|
if (count == 0 || _indicatorFrames.count != count) return;
|
|
607
1367
|
CGFloat progress = RNCClamp(_progress, 0, count - 1);
|
|
1368
|
+
BOOL snapToSelection = self.pillAnimationDisabled;
|
|
1369
|
+
if (snapToSelection) {
|
|
1370
|
+
// The pill and label colors jump to the selection instead of following progress.
|
|
1371
|
+
NSInteger snapped = (NSInteger)round(progress);
|
|
1372
|
+
if ([_config[@"controlled"] boolValue]) {
|
|
1373
|
+
NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
|
|
1374
|
+
if (selected != NSNotFound) snapped = (NSInteger)selected;
|
|
1375
|
+
}
|
|
1376
|
+
progress = RNCClamp(snapped, 0, count - 1);
|
|
1377
|
+
}
|
|
608
1378
|
NSInteger lower = (NSInteger)floor(progress);
|
|
609
1379
|
NSInteger upper = MIN(lower + 1, count - 1);
|
|
610
1380
|
CGFloat fraction = progress - lower;
|
|
@@ -614,14 +1384,35 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
614
1384
|
CGRectGetMinX(fromFrame) + (CGRectGetMinX(toFrame) - CGRectGetMinX(fromFrame)) * fraction,
|
|
615
1385
|
CGRectGetMinY(fromFrame),
|
|
616
1386
|
CGRectGetWidth(fromFrame) + (CGRectGetWidth(toFrame) - CGRectGetWidth(fromFrame)) * fraction,
|
|
617
|
-
_indicatorHeight
|
|
1387
|
+
_segmented ? CGRectGetHeight(fromFrame) : _indicatorHeight
|
|
618
1388
|
);
|
|
1389
|
+
if (_pillVariant) {
|
|
1390
|
+
// Leading edge leads and trailing edge lags while moving between tabs.
|
|
1391
|
+
CGFloat leading = 1 - (1 - fraction) * (1 - fraction);
|
|
1392
|
+
CGFloat trailing = fraction * fraction;
|
|
1393
|
+
BOOL forward = CGRectGetMinX(toFrame) >= CGRectGetMinX(fromFrame);
|
|
1394
|
+
CGFloat left = CGRectGetMinX(fromFrame) + (CGRectGetMinX(toFrame) - CGRectGetMinX(fromFrame)) * (forward ? trailing : leading);
|
|
1395
|
+
CGFloat right = CGRectGetMaxX(fromFrame) + (CGRectGetMaxX(toFrame) - CGRectGetMaxX(fromFrame)) * (forward ? leading : trailing);
|
|
1396
|
+
indicatorFrame = CGRectMake(left, CGRectGetMinY(fromFrame), MAX(0, right - left), CGRectGetHeight(fromFrame));
|
|
1397
|
+
_indicatorView.layer.cornerRadius = CGRectGetHeight(indicatorFrame) / 2;
|
|
1398
|
+
}
|
|
619
1399
|
_indicatorView.frame = indicatorFrame;
|
|
620
|
-
_indicatorView.hidden =
|
|
1400
|
+
_indicatorView.hidden = _textVariant || CGRectGetHeight(indicatorFrame) <= 0;
|
|
621
1401
|
|
|
622
1402
|
NSInteger selectedIndex = (NSInteger)round(progress);
|
|
1403
|
+
if ([_config[@"controlled"] boolValue]) {
|
|
1404
|
+
NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
|
|
1405
|
+
selectedIndex = selected == NSNotFound ? -1 : (NSInteger)selected;
|
|
1406
|
+
}
|
|
1407
|
+
NSInteger fontOwnerIndex = [self visualFontOwnerIndex:selectedIndex];
|
|
1408
|
+
NSString *key = selectedIndex >= 0 && selectedIndex < count ? _items[selectedIndex][@"key"] : nil;
|
|
1409
|
+
[self updateToolbarForKey:key];
|
|
623
1410
|
[_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
|
|
624
1411
|
CGFloat emphasis = 1 - MIN(1, fabs(progress - index));
|
|
1412
|
+
if ([self->_config[@"controlled"] boolValue] && !snapToSelection) {
|
|
1413
|
+
emphasis = index == self->_progressSource ? 1 - self->_progressFraction : 0;
|
|
1414
|
+
if (index == self->_progressDestination) emphasis += self->_progressFraction;
|
|
1415
|
+
}
|
|
625
1416
|
UIColor *color = RNCInterpolateColor(
|
|
626
1417
|
self->_inactiveTextColor,
|
|
627
1418
|
self->_activeTextColor,
|
|
@@ -629,12 +1420,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
629
1420
|
self.traitCollection
|
|
630
1421
|
);
|
|
631
1422
|
[button setTitleColor:color forState:UIControlStateNormal];
|
|
1423
|
+
if (self->_textVariant) {
|
|
1424
|
+
button.titleLabel.font = index == fontOwnerIndex
|
|
1425
|
+
? self.activeTabFont
|
|
1426
|
+
: self.tabFont;
|
|
1427
|
+
}
|
|
632
1428
|
button.accessibilityTraits = index == selectedIndex
|
|
633
1429
|
? UIAccessibilityTraitButton | UIAccessibilityTraitSelected
|
|
634
1430
|
: UIAccessibilityTraitButton;
|
|
635
1431
|
}];
|
|
636
1432
|
|
|
637
|
-
if (_shouldCenterSelectedItem && !_scrollView.tracking && !_scrollView.dragging &&
|
|
1433
|
+
if (_shouldCenterSelectedItem && !_segmented && !_scrollView.tracking && !_scrollView.dragging &&
|
|
638
1434
|
!_scrollView.decelerating && CGRectGetWidth(_scrollView.bounds) > 0) {
|
|
639
1435
|
CGFloat maximumOffset = MAX(0, _scrollView.contentSize.width - CGRectGetWidth(_scrollView.bounds));
|
|
640
1436
|
CGFloat desiredOffset = RNCClamp(
|
|
@@ -1433,6 +2229,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1433
2229
|
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)other { return YES; }
|
|
1434
2230
|
@end
|
|
1435
2231
|
|
|
2232
|
+
@protocol RNCPagerPresentationProgressTarget <NSObject>
|
|
2233
|
+
- (void)sampleProgrammaticTabProgress:(CADisplayLink *)link;
|
|
2234
|
+
- (void)sampleToolbarSettlement:(CADisplayLink *)link;
|
|
2235
|
+
@end
|
|
2236
|
+
|
|
2237
|
+
@interface RNCPagerPresentationProgressProxy : NSObject
|
|
2238
|
+
@property (nonatomic, weak) id<RNCPagerPresentationProgressTarget> target;
|
|
2239
|
+
@property (nonatomic, assign) BOOL toolbarSettlement;
|
|
2240
|
+
@end
|
|
2241
|
+
@implementation RNCPagerPresentationProgressProxy
|
|
2242
|
+
- (void)tick:(CADisplayLink *)link {
|
|
2243
|
+
id<RNCPagerPresentationProgressTarget> target = self.target;
|
|
2244
|
+
if (target && self.toolbarSettlement) [target sampleToolbarSettlement:link];
|
|
2245
|
+
else if (target) [target sampleProgrammaticTabProgress:link];
|
|
2246
|
+
else [link invalidate];
|
|
2247
|
+
}
|
|
2248
|
+
@end
|
|
2249
|
+
|
|
1436
2250
|
@interface RNCCollapsiblePagerViewComponentView () <
|
|
1437
2251
|
RCTRNCCollapsiblePagerViewViewProtocol,
|
|
1438
2252
|
UIPageViewControllerDataSource,
|
|
@@ -1441,33 +2255,57 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1441
2255
|
UIGestureRecognizerDelegate,
|
|
1442
2256
|
RCTMountingTransactionObserving,
|
|
1443
2257
|
RNCNativeScrollerInsetCoordinator,
|
|
1444
|
-
RNCPagerViewNestedOverlayObserver
|
|
2258
|
+
RNCPagerViewNestedOverlayObserver,
|
|
2259
|
+
RNCPagerPresentationProgressTarget
|
|
1445
2260
|
>
|
|
2261
|
+
- (void)syncNativeToolbarState;
|
|
2262
|
+
- (void)cancelNativeToolbarSettlement;
|
|
2263
|
+
- (void)scheduleNativeToolbarSettlement;
|
|
1446
2264
|
- (void)finishPagerScrollEmittingSelection:(BOOL)emitSelection;
|
|
2265
|
+
- (void)cancelPendingNativePagerScroll;
|
|
1447
2266
|
- (void)completeTransitionOnNextRunLoopForGeneration:(NSUInteger)generation
|
|
1448
2267
|
transition:(NSUInteger)transition;
|
|
1449
2268
|
- (void)setDirectNativePagerEnabled:(BOOL)enabled;
|
|
1450
2269
|
- (void)attachSharedHeadersToScrollView:(UIScrollView *)scrollView;
|
|
1451
2270
|
- (void)liftSharedHeadersForPagerTransition:(NSString *)reason;
|
|
1452
2271
|
- (void)restoreSharedHeadersToContainer;
|
|
2272
|
+
- (NSInteger)currentStickyHeaderHeight;
|
|
1453
2273
|
- (void)layoutSharedHeaders;
|
|
2274
|
+
- (void)bringReservedStickyControlToFront;
|
|
1454
2275
|
- (void)restorePinnedStickyHeader;
|
|
1455
2276
|
- (void)updatePinnedStickyHeader;
|
|
1456
2277
|
- (UIScrollView *)currentVerticalScrollViewForParentPager;
|
|
1457
2278
|
- (UIScrollView *)verticalScrollViewForPageAtIndex:(NSInteger)pageIndex;
|
|
2279
|
+
- (RNCScrollCandidateResolution)resolveScrollCandidateForPageAtIndex:(NSInteger)pageIndex;
|
|
2280
|
+
- (RNCScrollCandidateResolution)resolveScrollCandidateInView:(UIView *)view;
|
|
1458
2281
|
- (UIScrollView *)findExplicitNativeScrollerInView:(UIView *)view;
|
|
1459
2282
|
- (UIScrollView *)findFabricScrollViewInView:(UIView *)view;
|
|
1460
2283
|
- (UIScrollView *)findVerticalScrollViewInView:(UIView *)view;
|
|
2284
|
+
- (void)scheduleCoalescedScrollReconcile;
|
|
1461
2285
|
- (void)scheduleScrollObserverRetryForCurrentPage;
|
|
1462
2286
|
- (void)preparePageForHorizontalTransitionAtIndex:(NSInteger)pageIndex;
|
|
1463
2287
|
- (void)updateSharedHeaderPressCancellationGesture;
|
|
1464
2288
|
- (void)detachSharedHeaderPressCancellationGesture;
|
|
1465
2289
|
- (void)updateRefreshControlForScrollView:(UIScrollView *)scrollView;
|
|
1466
2290
|
- (void)releaseRefreshControlForScrollView:(UIScrollView *)scrollView;
|
|
2291
|
+
- (void)logHomeVisualGeometry:(NSString *)phase scrollView:(UIScrollView *)scrollView;
|
|
1467
2292
|
- (void)cancelTopInsetReboundCheck;
|
|
1468
2293
|
- (void)scheduleTopInsetReboundCheck;
|
|
1469
2294
|
- (void)syncScrollEdgeAppearance;
|
|
1470
2295
|
- (void)updateHardEdgeSeparatorCovers;
|
|
2296
|
+
- (void)updateTopOverlayThemeBackground;
|
|
2297
|
+
- (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay;
|
|
2298
|
+
- (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay;
|
|
2299
|
+
- (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay;
|
|
2300
|
+
- (RNCCollapsiblePagerTransitionEdgeOwner *)borrowedPinnedStickyOwner;
|
|
2301
|
+
- (void)releaseProgrammaticScrollEdge:(UIScrollView *)scrollView;
|
|
2302
|
+
- (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex;
|
|
2303
|
+
- (BOOL)layoutStandInScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner;
|
|
2304
|
+
- (void)layoutStandInScrollEdges;
|
|
2305
|
+
- (void)releaseProgrammaticScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner;
|
|
2306
|
+
- (void)clearProgrammaticScrollEdges;
|
|
2307
|
+
- (void)finishProgrammaticScrollEdges;
|
|
2308
|
+
- (BOOL)hasProgrammaticScrollEdgeForPage:(UIView *)page;
|
|
1471
2309
|
- (void)updateScrollEdgeContentMasks;
|
|
1472
2310
|
- (void)restoreScrollEdgeContentMasks;
|
|
1473
2311
|
- (void)sharedHeaderPressCancellationGestureChanged:(UIPanGestureRecognizer *)recognizer;
|
|
@@ -1506,6 +2344,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1506
2344
|
UILabel *_stickyEdgeMarker;
|
|
1507
2345
|
CALayer *_topEdgeSeparatorCover;
|
|
1508
2346
|
CALayer *_stickyEdgeSeparatorCover;
|
|
2347
|
+
CALayer *_topOverlayThemeBackgroundLayer;
|
|
1509
2348
|
__weak UIView *_topEdgeInteractionHost;
|
|
1510
2349
|
__weak UIView *_stickyEdgeInteractionHost;
|
|
1511
2350
|
__weak UIScrollView *_topEdgeScrollView;
|
|
@@ -1517,6 +2356,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1517
2356
|
NSInteger _pendingInitialPage;
|
|
1518
2357
|
NSInteger _headerHeight;
|
|
1519
2358
|
NSInteger _stickyHeaderHeight;
|
|
2359
|
+
NSArray *_stickyHeaderHeights;
|
|
1520
2360
|
CGFloat _topOverlayHeight;
|
|
1521
2361
|
NSInteger _externalTopOverlayTag;
|
|
1522
2362
|
__weak UIView *_externalTopOverlayView;
|
|
@@ -1535,6 +2375,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1535
2375
|
NSUInteger _pendingTopInsetReboundGeneration;
|
|
1536
2376
|
NSTimer *_topInsetReboundTimer;
|
|
1537
2377
|
CGFloat _nativeTabBarHeight;
|
|
2378
|
+
CGFloat _nativeTabBarTrailingReservedWidth;
|
|
1538
2379
|
CGFloat _nativeSubHeaderHeight;
|
|
1539
2380
|
CGFloat _headerOffset;
|
|
1540
2381
|
BOOL _scrollEnabled;
|
|
@@ -1543,12 +2384,31 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1543
2384
|
BOOL _nativeSmoothHeaderScrollEnabled;
|
|
1544
2385
|
UIPanGestureRecognizer *_blockerGesture;
|
|
1545
2386
|
BOOL _transitioning;
|
|
2387
|
+
BOOL _toolbarTransitionPending;
|
|
2388
|
+
CADisplayLink *_toolbarSettleDisplayLink;
|
|
2389
|
+
NSUInteger _toolbarSettleGeneration;
|
|
2390
|
+
NSUInteger _toolbarSettleTransition;
|
|
2391
|
+
NSInteger _toolbarSettlePage;
|
|
2392
|
+
CGFloat _toolbarSettleWidth;
|
|
2393
|
+
NSUInteger _toolbarSettleTicks;
|
|
2394
|
+
BOOL _toolbarSettleAttempted;
|
|
1546
2395
|
BOOL _isPagerDragging;
|
|
1547
2396
|
BOOL _directNativePagerEnabled;
|
|
1548
2397
|
BOOL _pendingDirectNativePagerEnabled;
|
|
1549
2398
|
BOOL _hasPendingDirectNativePagerChange;
|
|
1550
2399
|
BOOL _hasReceivedPageCommand;
|
|
1551
2400
|
NSUInteger _transitionId;
|
|
2401
|
+
void (^_pendingNativePagerScrollCompletion)(BOOL);
|
|
2402
|
+
NSUInteger _pendingNativePagerScrollGeneration;
|
|
2403
|
+
NSUInteger _pendingNativePagerScrollTransition;
|
|
2404
|
+
CGFloat _pendingNativePagerScrollTarget;
|
|
2405
|
+
CADisplayLink *_tabProgressDisplayLink;
|
|
2406
|
+
NSUInteger _tabProgressGeneration;
|
|
2407
|
+
NSUInteger _tabProgressTransition;
|
|
2408
|
+
CGFloat _tabProgressWidth;
|
|
2409
|
+
NSIndexSet *_programmaticPageMaskIndexes;
|
|
2410
|
+
NSMapTable<UIScrollView *, RNCCollapsiblePagerTransitionEdgeOwner *> *_programmaticScrollEdges;
|
|
2411
|
+
NSMutableArray<RNCCollapsiblePagerTransitionEdgeOwner *> *_programmaticScrollEdgeOwners;
|
|
1552
2412
|
// OneKey patch: Retain the latest tab tap while an animation is in flight.
|
|
1553
2413
|
NSInteger _pendingGoToIndex;
|
|
1554
2414
|
BOOL _pendingGoToAnimated;
|
|
@@ -1576,6 +2436,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1576
2436
|
NSMapTable<UIScrollView *, NSValue *> *_originalInsets;
|
|
1577
2437
|
NSMapTable<UIScrollView *, UIRefreshControl *> *_managedRefreshControls;
|
|
1578
2438
|
NSHashTable<UIScrollView *> *_refreshControlObservedScrollViews;
|
|
2439
|
+
CFTimeInterval _homeVisualLastScrollLog;
|
|
2440
|
+
CFTimeInterval _homeVisualLastLayoutLog;
|
|
2441
|
+
CFTimeInterval _homeVisualStartMono;
|
|
2442
|
+
NSString *_homeVisualLastGeometrySignature;
|
|
2443
|
+
CGFloat _homeVisualLastThemeOpacity;
|
|
2444
|
+
CFTimeInterval _homeVisualLastThemeLog;
|
|
2445
|
+
BOOL _homeVisualThemeHolding;
|
|
1579
2446
|
NSMapTable<UIScrollView *, NSNumber *> *_appliedTopInsets;
|
|
1580
2447
|
NSMapTable<UIScrollView *, NSValue *> *_originalIndicatorInsets;
|
|
1581
2448
|
NSMapTable<UIScrollView *, NSNumber *> *_originalAlwaysBounceVertical;
|
|
@@ -1614,6 +2481,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1614
2481
|
RNCCollapsiblePagerOuterPagerPanGestureRecognizer *_sharedHeaderOuterPagerGesture;
|
|
1615
2482
|
RNCCollapsiblePagerVerticalPagerGuardGestureRecognizer *_verticalPagerGesture;
|
|
1616
2483
|
BOOL _observingContentOffset;
|
|
2484
|
+
BOOL _awaitingScrollOwnerForCurrentPage;
|
|
2485
|
+
BOOL _scrollReconcileScheduled;
|
|
1617
2486
|
BOOL _scrollResolveRetryScheduled;
|
|
1618
2487
|
CFTimeInterval _pendingFallbackScrollViewDetectedAt;
|
|
1619
2488
|
NSInteger _scrollResolveRetryPageIndex;
|
|
@@ -1645,6 +2514,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1645
2514
|
_displayBodyOverrides = [NSMutableDictionary new];
|
|
1646
2515
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nativeListScrollCommandAccepted:)
|
|
1647
2516
|
name:@"OneKeyNativeListScrollCommandAccepted" object:nil];
|
|
2517
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nativeScrollViewDidBecomeReadyNotification:)
|
|
2518
|
+
name:@"OneKeyNativeScrollViewDidBecomeReady" object:nil];
|
|
1648
2519
|
_pendingPageRestoreKeys = [NSMutableSet new];
|
|
1649
2520
|
_releasedPageScrollStates = [NSMutableDictionary new];
|
|
1650
2521
|
_mountingRemovedScrollViews = [NSHashTable weakObjectsHashTable];
|
|
@@ -1714,6 +2585,23 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1714
2585
|
});
|
|
1715
2586
|
}
|
|
1716
2587
|
};
|
|
2588
|
+
_nativeTabBarView.onToolbarNeedsSettlement = ^{
|
|
2589
|
+
__strong __typeof__(weakSelf) self = weakSelf;
|
|
2590
|
+
if (!self) return;
|
|
2591
|
+
NSUInteger generation = self->_generation;
|
|
2592
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
2593
|
+
if (self->_generation == generation) [self syncNativeToolbarState];
|
|
2594
|
+
});
|
|
2595
|
+
};
|
|
2596
|
+
_nativeTabBarView.onToolbarPress = ^(NSString *key, CGRect rect) {
|
|
2597
|
+
__strong __typeof__(weakSelf) self = weakSelf;
|
|
2598
|
+
if (!self || self->_isBeingRecycled) return;
|
|
2599
|
+
const auto emitter = [self eventEmitter];
|
|
2600
|
+
if (emitter) emitter->onNativeToolbarPress({
|
|
2601
|
+
.key = std::string(key.UTF8String ?: ""),
|
|
2602
|
+
.anchorRect = {.x = rect.origin.x, .y = rect.origin.y, .width = rect.size.width, .height = rect.size.height}
|
|
2603
|
+
});
|
|
2604
|
+
};
|
|
1717
2605
|
[_sharedHeaderHostView addSubview:_nativeTabBarView];
|
|
1718
2606
|
|
|
1719
2607
|
_nativeSubHeaderView = [RNCCollapsiblePagerNativeSubHeaderView new];
|
|
@@ -1774,11 +2662,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1774
2662
|
if (hitView != nil && !sharedHeaderPointIsVisible &&
|
|
1775
2663
|
(hitView == _sharedHeaderHostView ||
|
|
1776
2664
|
[hitView isDescendantOfView:_sharedHeaderHostView])) return nil;
|
|
1777
|
-
if (hitView != nil && _ownedPageMasks.count > 0 &&
|
|
2665
|
+
if (hitView != nil && (_ownedPageMasks.count > 0 || _programmaticScrollEdges.count > 0) &&
|
|
1778
2666
|
[_containerView convertPoint:point fromView:self].y < _pageMaskBoundary) {
|
|
1779
2667
|
for (UIView *page in _ownedPageMasks.keyEnumerator.allObjects) {
|
|
1780
2668
|
if ([hitView isDescendantOfView:page]) return nil;
|
|
1781
2669
|
}
|
|
2670
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdges.objectEnumerator) {
|
|
2671
|
+
if (owner.page != nil && [hitView isDescendantOfView:owner.page]) return nil;
|
|
2672
|
+
}
|
|
1782
2673
|
}
|
|
1783
2674
|
return hitView;
|
|
1784
2675
|
}
|
|
@@ -1795,6 +2686,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1795
2686
|
- (void)didMoveToWindow
|
|
1796
2687
|
{
|
|
1797
2688
|
[super didMoveToWindow];
|
|
2689
|
+
[self cancelNativeToolbarSettlement];
|
|
2690
|
+
if (self.window == nil) [self stopProgrammaticTabProgress];
|
|
2691
|
+
if (self.window == nil && _pendingNativePagerScrollCompletion != nil) {
|
|
2692
|
+
[self cancelPendingNativePagerScroll];
|
|
2693
|
+
_pagerScrollView.scrollEnabled = _scrollEnabled;
|
|
2694
|
+
[self finishPagerScrollEmittingSelection:NO];
|
|
2695
|
+
}
|
|
2696
|
+
[self syncNativeToolbarState];
|
|
1798
2697
|
[self registerExternalOuterPager];
|
|
1799
2698
|
BOOL externalHeightChanged = [self resolveExternalTopOverlay];
|
|
1800
2699
|
if (self.window == nil) [self restoreScrollEdgeContentMasks];
|
|
@@ -1803,8 +2702,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1803
2702
|
[self updateTopScrollEdgeForScrollView:_observedScrollView];
|
|
1804
2703
|
[self updateSharedHeaderPressCancellationGesture];
|
|
1805
2704
|
[self updateHeaderSettledStateForceBusy:NO];
|
|
2705
|
+
[self logHomeVisualGeometry:@"window" scrollView:_observedScrollView];
|
|
1806
2706
|
for (UIScrollView *scrollView in _originalInsets.keyEnumerator) {
|
|
1807
|
-
[self updateNativeScrollerViewport:scrollView stickyHeight:self.window == nil ? 0 :
|
|
2707
|
+
[self updateNativeScrollerViewport:scrollView stickyHeight:self.window == nil ? 0 : self.currentStickyHeaderHeight + self.effectiveTopOverlayHeight];
|
|
1808
2708
|
}
|
|
1809
2709
|
if (externalHeightChanged) [self reapplyInsetsToObservedScrollView];
|
|
1810
2710
|
// OneKey patch: removing a decelerating page from its window can suppress
|
|
@@ -1830,7 +2730,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1830
2730
|
|
|
1831
2731
|
- (CGFloat)effectiveTopOverlayHeight
|
|
1832
2732
|
{
|
|
1833
|
-
|
|
2733
|
+
BOOL localOverlayPending = _topScrollEdgeEnabled && _topOverlayHeight > 0 &&
|
|
2734
|
+
_externalTopOverlayTag <= 0;
|
|
2735
|
+
return _topOverlayView != nil || localOverlayPending
|
|
2736
|
+
? _topOverlayHeight : _externalTopOverlayHeight;
|
|
1834
2737
|
}
|
|
1835
2738
|
|
|
1836
2739
|
- (BOOL)hasFixedTopOverlay
|
|
@@ -1851,6 +2754,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1851
2754
|
}
|
|
1852
2755
|
}
|
|
1853
2756
|
if (_externalOuterPager == outer) return;
|
|
2757
|
+
if (_topOverlayView == nil && _externalTopOverlayTag > 0) {
|
|
2758
|
+
[self clearProgrammaticScrollEdges];
|
|
2759
|
+
}
|
|
1854
2760
|
[_externalOuterPager removeNestedOverlayObserver:self];
|
|
1855
2761
|
_externalOuterPager = outer;
|
|
1856
2762
|
_externalOuterPageActive = NO;
|
|
@@ -1882,6 +2788,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1882
2788
|
}
|
|
1883
2789
|
BOOL changed = _externalTopOverlayView != nextView ||
|
|
1884
2790
|
fabs(_externalTopOverlayHeight - nextHeight) > 0.5;
|
|
2791
|
+
if (changed && _topOverlayView == nil && _externalTopOverlayTag > 0) {
|
|
2792
|
+
[self clearProgrammaticScrollEdges];
|
|
2793
|
+
}
|
|
1885
2794
|
_externalTopOverlayView = nextView;
|
|
1886
2795
|
_externalTopOverlayHeight = nextHeight;
|
|
1887
2796
|
_topOverlayHostView.hidden = !self.hasFixedTopOverlay;
|
|
@@ -1893,9 +2802,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1893
2802
|
{
|
|
1894
2803
|
if (_isBeingRecycled || _externalOuterPager == nil || _externalTopOverlayTag <= 0) return;
|
|
1895
2804
|
if (_externalOuterPageActive == active && _externalOuterTransitioning == transitioning) return;
|
|
2805
|
+
if ((transitioning || !active) && _topOverlayView == nil) {
|
|
2806
|
+
[self clearProgrammaticScrollEdges];
|
|
2807
|
+
}
|
|
1896
2808
|
BOOL wasTransitioning = _externalOuterTransitioning;
|
|
1897
2809
|
_externalOuterPageActive = active;
|
|
1898
2810
|
_externalOuterTransitioning = transitioning;
|
|
2811
|
+
[self syncNativeToolbarState];
|
|
1899
2812
|
if (transitioning && !wasTransitioning) {
|
|
1900
2813
|
[self updateTopScrollEdgeForScrollView:nil];
|
|
1901
2814
|
[self liftSharedHeadersForPagerTransition:@"outer"];
|
|
@@ -1913,6 +2826,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1913
2826
|
[super traitCollectionDidChange:previousTraitCollection];
|
|
1914
2827
|
if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) {
|
|
1915
2828
|
[self syncScrollEdgeAppearance];
|
|
2829
|
+
[self updateTopOverlayThemeBackground];
|
|
2830
|
+
[self logHomeVisualGeometry:@"trait" scrollView:_observedScrollView];
|
|
1916
2831
|
}
|
|
1917
2832
|
}
|
|
1918
2833
|
|
|
@@ -1938,6 +2853,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1938
2853
|
|
|
1939
2854
|
- (void)restoreScrollEdgeContentMasks
|
|
1940
2855
|
{
|
|
2856
|
+
[self clearProgrammaticScrollEdges];
|
|
2857
|
+
_programmaticPageMaskIndexes = nil;
|
|
1941
2858
|
if (_sharedHeaderHostView.maskView == _sharedHeaderMaskView) {
|
|
1942
2859
|
_sharedHeaderHostView.maskView = _originalSharedHeaderMaskView;
|
|
1943
2860
|
}
|
|
@@ -1956,12 +2873,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1956
2873
|
|
|
1957
2874
|
- (void)updateScrollEdgeContentMasks
|
|
1958
2875
|
{
|
|
2876
|
+
[self layoutStandInScrollEdges];
|
|
1959
2877
|
[self updateHardEdgeSeparatorCovers];
|
|
1960
2878
|
BOOL enabled = _topScrollEdgeEnabled &&
|
|
1961
2879
|
(self.hasFixedTopOverlay || _stickyHeaderView != nil) &&
|
|
1962
2880
|
self.window != nil && !_isBeingRecycled;
|
|
1963
2881
|
if (!enabled) {
|
|
1964
2882
|
[self restoreScrollEdgeContentMasks];
|
|
2883
|
+
[self updateTopOverlayThemeBackground];
|
|
1965
2884
|
return;
|
|
1966
2885
|
}
|
|
1967
2886
|
if (self.hasFixedTopOverlay && _sharedHeaderHostView.window == self.window &&
|
|
@@ -2001,11 +2920,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2001
2920
|
_pageMaskBoundary = boundary;
|
|
2002
2921
|
NSMutableSet<UIView *> *visiblePages = [NSMutableSet new];
|
|
2003
2922
|
if (transitioning) {
|
|
2004
|
-
for (
|
|
2005
|
-
UIView *page =
|
|
2923
|
+
for (NSUInteger index = 0; index < _pageControllers.count; index++) {
|
|
2924
|
+
UIView *page = _pageControllers[index].view;
|
|
2925
|
+
BOOL programmaticParticipant = [_programmaticPageMaskIndexes containsIndex:index];
|
|
2926
|
+
if ([self hasProgrammaticScrollEdgeForPage:page]) continue;
|
|
2006
2927
|
if (page.window != self.window ||
|
|
2007
|
-
!
|
|
2008
|
-
|
|
2928
|
+
(!programmaticParticipant &&
|
|
2929
|
+
!CGRectIntersectsRect([page convertRect:page.bounds toView:_containerView],
|
|
2930
|
+
_containerView.bounds))) continue;
|
|
2009
2931
|
[visiblePages addObject:page];
|
|
2010
2932
|
UIView *mask = [_ownedPageMasks objectForKey:page];
|
|
2011
2933
|
if (mask == nil) {
|
|
@@ -2017,8 +2939,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2017
2939
|
}
|
|
2018
2940
|
CGFloat localTop = [_containerView convertPoint:CGPointMake(0, boundary)
|
|
2019
2941
|
toView:page].y;
|
|
2020
|
-
|
|
2942
|
+
CGRect maskFrame = CGRectMake(0, localTop, CGRectGetWidth(page.bounds),
|
|
2021
2943
|
MAX(0, CGRectGetHeight(page.bounds) - localTop));
|
|
2944
|
+
if (programmaticParticipant) {
|
|
2945
|
+
[UIView performWithoutAnimation:^{ mask.frame = maskFrame; }];
|
|
2946
|
+
} else {
|
|
2947
|
+
mask.frame = maskFrame;
|
|
2948
|
+
}
|
|
2022
2949
|
}
|
|
2023
2950
|
}
|
|
2024
2951
|
for (UIView *page in _ownedPageMasks.keyEnumerator.allObjects) {
|
|
@@ -2031,6 +2958,102 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2031
2958
|
[_ownedPageMasks removeObjectForKey:page];
|
|
2032
2959
|
[_originalPageMasks removeObjectForKey:page];
|
|
2033
2960
|
}
|
|
2961
|
+
[self updateTopOverlayThemeBackground];
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
- (void)updateTopOverlayThemeBackground
|
|
2965
|
+
{
|
|
2966
|
+
if (@available(iOS 27.0, *)) {
|
|
2967
|
+
BOOL localHardOverlay = !_isBeingRecycled && _topScrollEdgeEnabled &&
|
|
2968
|
+
_topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
|
|
2969
|
+
_nativeSmoothHeaderScrollEnabled && _topOverlayView != nil &&
|
|
2970
|
+
_externalTopOverlayTag <= 0 && _topOverlayHeight > 0 && _headerHeight > 0 &&
|
|
2971
|
+
_topOverlayHostView.window == self.window && self.window != nil &&
|
|
2972
|
+
!CGRectIsEmpty(_topOverlayHostView.bounds);
|
|
2973
|
+
if (!localHardOverlay) {
|
|
2974
|
+
[_topOverlayThemeBackgroundLayer removeFromSuperlayer];
|
|
2975
|
+
_topOverlayThemeBackgroundLayer = nil;
|
|
2976
|
+
_homeVisualThemeHolding = NO;
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
UIColor *color = nil;
|
|
2981
|
+
for (UIView *view = self; view != nil; view = view.superview) {
|
|
2982
|
+
UIColor *candidate = [view.backgroundColor resolvedColorWithTraitCollection:
|
|
2983
|
+
_topOverlayHostView.traitCollection];
|
|
2984
|
+
if (candidate != nil && CGColorGetAlpha(candidate.CGColor) >= 1) {
|
|
2985
|
+
color = candidate;
|
|
2986
|
+
break;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
if (color == nil) {
|
|
2990
|
+
[_topOverlayThemeBackgroundLayer removeFromSuperlayer];
|
|
2991
|
+
_topOverlayThemeBackgroundLayer = nil;
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
UIScrollView *scrollView = _observedScrollView;
|
|
2996
|
+
BOOL geometryReady = scrollView != nil &&
|
|
2997
|
+
_sharedHeaderScrollView == scrollView && _topEdgeScrollView == scrollView &&
|
|
2998
|
+
_topEdgeInteraction.scrollView == scrollView &&
|
|
2999
|
+
scrollView.topEdgeEffect.style == UIScrollEdgeEffectStyle.hardStyle &&
|
|
3000
|
+
_sharedHeaderMaskView != nil &&
|
|
3001
|
+
_sharedHeaderHostView.maskView == _sharedHeaderMaskView &&
|
|
3002
|
+
_headerView.window == self.window;
|
|
3003
|
+
if (_topOverlayThemeBackgroundLayer == nil && !geometryReady) return;
|
|
3004
|
+
BOOL created = _topOverlayThemeBackgroundLayer == nil;
|
|
3005
|
+
if (created) {
|
|
3006
|
+
_topOverlayThemeBackgroundLayer = [CALayer layer];
|
|
3007
|
+
_topOverlayThemeBackgroundLayer.name = @"onekey-top-overlay-theme-background";
|
|
3008
|
+
_topOverlayThemeBackgroundLayer.actions = @{
|
|
3009
|
+
@"position": NSNull.null, @"bounds": NSNull.null,
|
|
3010
|
+
@"opacity": NSNull.null, @"backgroundColor": NSNull.null
|
|
3011
|
+
};
|
|
3012
|
+
[_topOverlayHostView.layer insertSublayer:_topOverlayThemeBackgroundLayer atIndex:0];
|
|
3013
|
+
}
|
|
3014
|
+
_topOverlayThemeBackgroundLayer.frame = _topOverlayHostView.bounds;
|
|
3015
|
+
_topOverlayThemeBackgroundLayer.backgroundColor = color.CGColor;
|
|
3016
|
+
if (!geometryReady) {
|
|
3017
|
+
if (!_homeVisualThemeHolding) {
|
|
3018
|
+
_homeVisualThemeHolding = YES;
|
|
3019
|
+
#if DEBUG
|
|
3020
|
+
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
3021
|
+
@"[IOS-HOME-VISUAL] phase=theme-background-hold pagerTag=%ld generation=%lu pageIndex=%ld opacity=%.3f",
|
|
3022
|
+
(long)self.tag, (unsigned long)_generation, (long)_currentIndex,
|
|
3023
|
+
_topOverlayThemeBackgroundLayer.opacity]);
|
|
3024
|
+
#endif
|
|
3025
|
+
}
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
_homeVisualThemeHolding = NO;
|
|
3029
|
+
CGRect overlayWindow = [_topOverlayHostView convertRect:_topOverlayHostView.bounds
|
|
3030
|
+
toView:self.window];
|
|
3031
|
+
CGRect headerWindow = [_headerView convertRect:_headerView.bounds
|
|
3032
|
+
toView:self.window];
|
|
3033
|
+
CGFloat overlayBottom = CGRectGetMaxY(overlayWindow);
|
|
3034
|
+
CGFloat collapse = MIN(MAX(overlayBottom - CGRectGetMinY(headerWindow), 0),
|
|
3035
|
+
_headerHeight);
|
|
3036
|
+
CGFloat opacity = 1 - collapse / _headerHeight;
|
|
3037
|
+
_topOverlayThemeBackgroundLayer.opacity = opacity;
|
|
3038
|
+
#if DEBUG
|
|
3039
|
+
CFTimeInterval now = CACurrentMediaTime();
|
|
3040
|
+
if (created || fabs(opacity - _homeVisualLastThemeOpacity) >= 0.1 ||
|
|
3041
|
+
now - _homeVisualLastThemeLog >= 2.0) {
|
|
3042
|
+
_homeVisualLastThemeOpacity = opacity;
|
|
3043
|
+
_homeVisualLastThemeLog = now;
|
|
3044
|
+
CGFloat red = 0, green = 0, blue = 0, alpha = 0;
|
|
3045
|
+
[color getRed:&red green:&green blue:&blue alpha:&alpha];
|
|
3046
|
+
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
3047
|
+
@"[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",
|
|
3048
|
+
NSDate.date.timeIntervalSince1970 * 1000, now * 1000,
|
|
3049
|
+
(long)self.tag, (unsigned long)_generation, (long)_currentIndex,
|
|
3050
|
+
opacity, collapse, (CGFloat)_headerHeight, overlayBottom,
|
|
3051
|
+
CGRectGetMinY(headerWindow), overlayBottom + _headerHeight +
|
|
3052
|
+
self.currentStickyHeaderHeight - collapse, _topEdgeInteraction.scrollView == scrollView,
|
|
3053
|
+
red, green, blue, alpha]);
|
|
3054
|
+
}
|
|
3055
|
+
#endif
|
|
3056
|
+
}
|
|
2034
3057
|
}
|
|
2035
3058
|
|
|
2036
3059
|
- (void)updateEventEmitter:(const EventEmitter::Shared &)eventEmitter
|
|
@@ -2049,10 +3072,444 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2049
3072
|
emitter->onScrollEdgeCapability({.available = (bool)available});
|
|
2050
3073
|
}
|
|
2051
3074
|
|
|
3075
|
+
- (RNCCollapsiblePagerTransitionEdgeOwner *)borrowedPinnedStickyOwner
|
|
3076
|
+
{
|
|
3077
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
|
|
3078
|
+
if (owner.borrowsPinnedStickyHost) return owner;
|
|
3079
|
+
}
|
|
3080
|
+
return nil;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
- (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay
|
|
3084
|
+
{
|
|
3085
|
+
if (@available(iOS 27.0, *)) {
|
|
3086
|
+
if (!_directNativePagerEnabled || !_topScrollEdgeEnabled ||
|
|
3087
|
+
!_nativeSmoothHeaderScrollEnabled ||
|
|
3088
|
+
_topScrollEdgeEffect != RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard ||
|
|
3089
|
+
self.window == nil || _isBeingRecycled) return NO;
|
|
3090
|
+
if (_topOverlayView != nil && _externalTopOverlayTag <= 0) return YES;
|
|
3091
|
+
return allowExternalOverlay && _topOverlayView == nil && _externalTopOverlayTag > 0 &&
|
|
3092
|
+
_externalTopOverlayView.window == self.window && _externalTopOverlayHeight > 0 &&
|
|
3093
|
+
_topOverlayHostView.window == self.window && !_topOverlayHostView.hidden &&
|
|
3094
|
+
(_externalOuterPager == nil || (_externalOuterPageActive && !_externalOuterTransitioning));
|
|
3095
|
+
}
|
|
3096
|
+
return NO;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
- (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay
|
|
3100
|
+
{
|
|
3101
|
+
if (@available(iOS 27.0, *)) {
|
|
3102
|
+
UIScrollView *source = _observedScrollView;
|
|
3103
|
+
if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay] ||
|
|
3104
|
+
source == nil || source != _topEdgeScrollView ||
|
|
3105
|
+
_topEdgeInteraction == nil || _topEdgeInteraction.scrollView != source ||
|
|
3106
|
+
_currentIndex < 0 || _currentIndex >= _pageControllers.count) return;
|
|
3107
|
+
|
|
3108
|
+
RNCCollapsiblePagerTransitionEdgeOwner *existing =
|
|
3109
|
+
[_programmaticScrollEdges objectForKey:source];
|
|
3110
|
+
if (existing != nil && existing.topInteraction.scrollView == source) return;
|
|
3111
|
+
if (existing != nil) [self releaseProgrammaticScrollEdgeOwner:existing];
|
|
3112
|
+
if (_programmaticScrollEdges == nil) {
|
|
3113
|
+
_programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
|
|
3114
|
+
_programmaticScrollEdgeOwners = [NSMutableArray new];
|
|
3115
|
+
}
|
|
3116
|
+
RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
|
|
3117
|
+
owner.scrollView = source;
|
|
3118
|
+
owner.page = _pageControllers[_currentIndex].view;
|
|
3119
|
+
owner.originalStyle = _originalTopEdgeStyle;
|
|
3120
|
+
owner.topInteraction = _topEdgeInteraction;
|
|
3121
|
+
owner.topHost = _topEdgeInteractionHost;
|
|
3122
|
+
owner.topMarker = _topEdgeMarker;
|
|
3123
|
+
owner.stickyInteraction = _stickyEdgeInteraction;
|
|
3124
|
+
owner.stickyHost = _stickyEdgeInteractionHost;
|
|
3125
|
+
owner.stickyMarker = _stickyEdgeMarker;
|
|
3126
|
+
owner.borrowsPinnedStickyHost = _stickyHeaderIsPinned &&
|
|
3127
|
+
owner.stickyHost == _pinnedStickyHostView &&
|
|
3128
|
+
owner.stickyInteraction.scrollView == source;
|
|
3129
|
+
[_programmaticScrollEdges setObject:owner forKey:source];
|
|
3130
|
+
[_programmaticScrollEdgeOwners addObject:owner];
|
|
3131
|
+
|
|
3132
|
+
// Transfer ownership without detaching UIKit's existing edge resources.
|
|
3133
|
+
_topEdgeInteraction = nil;
|
|
3134
|
+
_stickyEdgeInteraction = nil;
|
|
3135
|
+
_topEdgeMarker = nil;
|
|
3136
|
+
_stickyEdgeMarker = nil;
|
|
3137
|
+
_topEdgeInteractionHost = nil;
|
|
3138
|
+
_stickyEdgeInteractionHost = nil;
|
|
3139
|
+
_topEdgeScrollView = nil;
|
|
3140
|
+
_originalTopEdgeStyle = nil;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
- (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay
|
|
3145
|
+
{
|
|
3146
|
+
if (@available(iOS 27.0, *)) {
|
|
3147
|
+
if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay]) return;
|
|
3148
|
+
if (_programmaticScrollEdges == nil) {
|
|
3149
|
+
_programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
|
|
3150
|
+
_programmaticScrollEdgeOwners = [NSMutableArray new];
|
|
3151
|
+
}
|
|
3152
|
+
NSInteger first = MIN(_currentIndex, index);
|
|
3153
|
+
NSInteger last = MAX(_currentIndex, index);
|
|
3154
|
+
for (NSInteger pageIndex = first; pageIndex <= last; pageIndex++) {
|
|
3155
|
+
[self preparePageForHorizontalTransitionAtIndex:pageIndex];
|
|
3156
|
+
UIScrollView *scrollView = [self verticalScrollViewForPageAtIndex:pageIndex];
|
|
3157
|
+
// A list that is not mounted yet, not laid out under the bars, or not
|
|
3158
|
+
// scrolled past its top cannot render the edge effect behind the bars.
|
|
3159
|
+
BOOL coversBars = scrollView != nil && scrollView.window == self.window &&
|
|
3160
|
+
[scrollView convertPoint:CGPointZero toView:_containerView].y <=
|
|
3161
|
+
[_pageControllers[pageIndex].view convertPoint:CGPointZero toView:_containerView].y + 0.5 &&
|
|
3162
|
+
scrollView.contentOffset.y + scrollView.adjustedContentInset.top > 0.5;
|
|
3163
|
+
// The stand-in applies only while the sticky header is pinned; otherwise
|
|
3164
|
+
// keep the temporary interaction on the page's own list.
|
|
3165
|
+
if (!coversBars && pageIndex != _currentIndex &&
|
|
3166
|
+
[self beginStandInScrollEdgeForPageAtIndex:pageIndex]) {
|
|
3167
|
+
continue;
|
|
3168
|
+
}
|
|
3169
|
+
if (scrollView == nil || scrollView.window != self.window) continue;
|
|
3170
|
+
if ([_programmaticScrollEdges objectForKey:scrollView] != nil) continue;
|
|
3171
|
+
RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
|
|
3172
|
+
owner.scrollView = scrollView;
|
|
3173
|
+
owner.page = _pageControllers[pageIndex].view;
|
|
3174
|
+
owner.originalStyle = scrollView.topEdgeEffect.style;
|
|
3175
|
+
scrollView.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle;
|
|
3176
|
+
UILabel *(^markerForHost)(UIView *) = ^UILabel *(UIView *host) {
|
|
3177
|
+
UILabel *marker = [UILabel new];
|
|
3178
|
+
marker.frame = host.bounds;
|
|
3179
|
+
marker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
3180
|
+
marker.text = @" ";
|
|
3181
|
+
marker.textColor = UIColor.clearColor;
|
|
3182
|
+
marker.backgroundColor = UIColor.clearColor;
|
|
3183
|
+
marker.userInteractionEnabled = NO;
|
|
3184
|
+
marker.isAccessibilityElement = NO;
|
|
3185
|
+
marker.accessibilityElementsHidden = YES;
|
|
3186
|
+
[host addSubview:marker];
|
|
3187
|
+
return marker;
|
|
3188
|
+
};
|
|
3189
|
+
owner.ownsTransitionHosts = pageIndex != _currentIndex;
|
|
3190
|
+
UIView *(^transitionHost)(UIView *) = ^UIView *(UIView *referenceHost) {
|
|
3191
|
+
CGRect frame = [referenceHost convertRect:referenceHost.bounds toView:owner.page];
|
|
3192
|
+
CGRect viewport = [scrollView convertRect:scrollView.bounds toView:owner.page];
|
|
3193
|
+
frame.origin.x = CGRectGetMinX(viewport);
|
|
3194
|
+
UIView *host = [[UIView alloc] initWithFrame:frame];
|
|
3195
|
+
host.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
|
3196
|
+
host.userInteractionEnabled = NO;
|
|
3197
|
+
host.accessibilityElementsHidden = YES;
|
|
3198
|
+
[owner.page addSubview:host];
|
|
3199
|
+
return host;
|
|
3200
|
+
};
|
|
3201
|
+
if (owner.ownsTransitionHosts) {
|
|
3202
|
+
owner.ownedTopHost = transitionHost(_topOverlayHostView);
|
|
3203
|
+
owner.topHost = owner.ownedTopHost;
|
|
3204
|
+
} else {
|
|
3205
|
+
owner.topHost = _topOverlayHostView;
|
|
3206
|
+
}
|
|
3207
|
+
owner.topMarker = markerForHost(owner.topHost);
|
|
3208
|
+
owner.topInteraction = [UIScrollEdgeElementContainerInteraction new];
|
|
3209
|
+
owner.topInteraction.edge = UIRectEdgeTop;
|
|
3210
|
+
owner.topInteraction.scrollView = scrollView;
|
|
3211
|
+
[owner.topHost addInteraction:owner.topInteraction];
|
|
3212
|
+
if (_stickyHeaderView != nil && _headerOffset >= _headerHeight - 0.5) {
|
|
3213
|
+
if (owner.ownsTransitionHosts) {
|
|
3214
|
+
owner.ownedStickyHost = transitionHost(_stickyHeaderView);
|
|
3215
|
+
owner.stickyHost = owner.ownedStickyHost;
|
|
3216
|
+
} else {
|
|
3217
|
+
owner.stickyHost = _stickyHeaderView;
|
|
3218
|
+
}
|
|
3219
|
+
owner.stickyMarker = markerForHost(owner.stickyHost);
|
|
3220
|
+
owner.stickyInteraction = [UIScrollEdgeElementContainerInteraction new];
|
|
3221
|
+
owner.stickyInteraction.edge = UIRectEdgeTop;
|
|
3222
|
+
owner.stickyInteraction.scrollView = scrollView;
|
|
3223
|
+
[owner.stickyHost addInteraction:owner.stickyInteraction];
|
|
3224
|
+
}
|
|
3225
|
+
[_programmaticScrollEdges setObject:owner forKey:scrollView];
|
|
3226
|
+
[_programmaticScrollEdgeOwners addObject:owner];
|
|
3227
|
+
}
|
|
3228
|
+
[self updateScrollEdgeContentMasks];
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
- (void)releaseProgrammaticScrollEdge:(UIScrollView *)scrollView
|
|
3233
|
+
{
|
|
3234
|
+
if (scrollView == nil) return;
|
|
3235
|
+
[self releaseProgrammaticScrollEdgeOwner:[_programmaticScrollEdges objectForKey:scrollView]];
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
- (void)releaseProgrammaticScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner
|
|
3239
|
+
{
|
|
3240
|
+
if (@available(iOS 26.0, *)) {
|
|
3241
|
+
if (owner == nil) return;
|
|
3242
|
+
UIScrollView *scrollView = owner.scrollView;
|
|
3243
|
+
[owner.topHost removeInteraction:owner.topInteraction];
|
|
3244
|
+
owner.topInteraction.scrollView = nil;
|
|
3245
|
+
[owner.stickyHost removeInteraction:owner.stickyInteraction];
|
|
3246
|
+
owner.stickyInteraction.scrollView = nil;
|
|
3247
|
+
[owner.topMarker removeFromSuperview];
|
|
3248
|
+
[owner.stickyMarker removeFromSuperview];
|
|
3249
|
+
[owner.standInScrollView removeFromSuperview];
|
|
3250
|
+
owner.standInScrollView = nil;
|
|
3251
|
+
if (owner.ownsTransitionHosts) {
|
|
3252
|
+
[owner.ownedTopHost removeFromSuperview];
|
|
3253
|
+
[owner.ownedStickyHost removeFromSuperview];
|
|
3254
|
+
owner.ownedTopHost = nil;
|
|
3255
|
+
owner.ownedStickyHost = nil;
|
|
3256
|
+
}
|
|
3257
|
+
scrollView.topEdgeEffect.style = owner.originalStyle;
|
|
3258
|
+
if (owner.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
|
|
3259
|
+
(_pinnedStickyHostView.superview == scrollView ||
|
|
3260
|
+
_pinnedStickyHostView.superview == nil)) {
|
|
3261
|
+
_pinnedStickyHostView.hidden = YES;
|
|
3262
|
+
_pinnedStickyHostView.layer.zPosition = 0;
|
|
3263
|
+
[_containerView addSubview:_pinnedStickyHostView];
|
|
3264
|
+
}
|
|
3265
|
+
if (scrollView != nil) [_programmaticScrollEdges removeObjectForKey:scrollView];
|
|
3266
|
+
[_programmaticScrollEdgeOwners removeObjectIdenticalTo:owner];
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
- (void)clearProgrammaticScrollEdges
|
|
3271
|
+
{
|
|
3272
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners.copy) {
|
|
3273
|
+
[self releaseProgrammaticScrollEdgeOwner:owner];
|
|
3274
|
+
}
|
|
3275
|
+
_programmaticScrollEdges = nil;
|
|
3276
|
+
_programmaticScrollEdgeOwners = nil;
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
- (void)finishProgrammaticScrollEdges
|
|
3280
|
+
{
|
|
3281
|
+
if (_programmaticScrollEdgeOwners.count == 0) return;
|
|
3282
|
+
// OneKey patch: keep the destination's transitional edge alive until the
|
|
3283
|
+
// settled interaction exists, so UIKit does not fade the edge effect back in.
|
|
3284
|
+
UIScrollView *settled = _observedScrollView;
|
|
3285
|
+
RNCCollapsiblePagerTransitionEdgeOwner *handoff =
|
|
3286
|
+
settled != nil ? [_programmaticScrollEdges objectForKey:settled] : nil;
|
|
3287
|
+
if (handoff != nil) {
|
|
3288
|
+
[_programmaticScrollEdges removeObjectForKey:settled];
|
|
3289
|
+
[_programmaticScrollEdgeOwners removeObjectIdenticalTo:handoff];
|
|
3290
|
+
}
|
|
3291
|
+
[self clearProgrammaticScrollEdges];
|
|
3292
|
+
if (@available(iOS 26.0, *)) {
|
|
3293
|
+
// A cancelled drag settles on the page whose settled edge was adopted.
|
|
3294
|
+
// Return that interaction as-is: a second container interaction for the
|
|
3295
|
+
// same scroll view and host would be torn down together with the old one.
|
|
3296
|
+
if (handoff != nil && !handoff.ownsTransitionHosts && _topEdgeInteraction == nil &&
|
|
3297
|
+
handoff.topHost == _topOverlayHostView &&
|
|
3298
|
+
handoff.topInteraction.scrollView == settled) {
|
|
3299
|
+
_topEdgeInteraction = handoff.topInteraction;
|
|
3300
|
+
_topEdgeInteractionHost = handoff.topHost;
|
|
3301
|
+
_topEdgeMarker = handoff.topMarker;
|
|
3302
|
+
_topEdgeScrollView = settled;
|
|
3303
|
+
_originalTopEdgeStyle = handoff.originalStyle;
|
|
3304
|
+
if (handoff.stickyInteraction != nil && handoff.stickyHost != nil &&
|
|
3305
|
+
handoff.stickyInteraction.scrollView == settled) {
|
|
3306
|
+
_stickyEdgeInteraction = handoff.stickyInteraction;
|
|
3307
|
+
_stickyEdgeInteractionHost = handoff.stickyHost;
|
|
3308
|
+
_stickyEdgeMarker = handoff.stickyMarker;
|
|
3309
|
+
} else {
|
|
3310
|
+
[handoff.stickyHost removeInteraction:handoff.stickyInteraction];
|
|
3311
|
+
handoff.stickyInteraction.scrollView = nil;
|
|
3312
|
+
[handoff.stickyMarker removeFromSuperview];
|
|
3313
|
+
}
|
|
3314
|
+
if (handoff.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
|
|
3315
|
+
(_pinnedStickyHostView.superview == settled ||
|
|
3316
|
+
_pinnedStickyHostView.superview == nil)) {
|
|
3317
|
+
_pinnedStickyHostView.hidden = YES;
|
|
3318
|
+
_pinnedStickyHostView.layer.zPosition = 0;
|
|
3319
|
+
[_containerView addSubview:_pinnedStickyHostView];
|
|
3320
|
+
}
|
|
3321
|
+
[self updateTopScrollEdgeForScrollView:settled];
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
[self updateTopScrollEdgeForScrollView:settled];
|
|
3326
|
+
if (handoff == nil) return;
|
|
3327
|
+
if (@available(iOS 26.0, *)) {
|
|
3328
|
+
if (_topEdgeScrollView == settled && settled != nil) {
|
|
3329
|
+
_originalTopEdgeStyle = handoff.originalStyle;
|
|
3330
|
+
handoff.originalStyle = settled.topEdgeEffect.style;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
if (handoff.borrowsPinnedStickyHost && !_stickyHeaderIsPinned &&
|
|
3334
|
+
(_pinnedStickyHostView.superview == settled ||
|
|
3335
|
+
_pinnedStickyHostView.superview == nil)) {
|
|
3336
|
+
_pinnedStickyHostView.hidden = YES;
|
|
3337
|
+
_pinnedStickyHostView.layer.zPosition = 0;
|
|
3338
|
+
[_containerView addSubview:_pinnedStickyHostView];
|
|
3339
|
+
}
|
|
3340
|
+
handoff.borrowsPinnedStickyHost = NO;
|
|
3341
|
+
// The caller reattaches the shared header in this run loop turn; drop the
|
|
3342
|
+
// transitional resources on the next one, after the header is rendered.
|
|
3343
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
3344
|
+
if (@available(iOS 26.0, *)) {
|
|
3345
|
+
[handoff.topHost removeInteraction:handoff.topInteraction];
|
|
3346
|
+
[handoff.stickyHost removeInteraction:handoff.stickyInteraction];
|
|
3347
|
+
if (handoff.topInteraction.scrollView == handoff.scrollView) {
|
|
3348
|
+
handoff.topInteraction.scrollView = nil;
|
|
3349
|
+
}
|
|
3350
|
+
if (handoff.stickyInteraction.scrollView == handoff.scrollView) {
|
|
3351
|
+
handoff.stickyInteraction.scrollView = nil;
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
[handoff.topMarker removeFromSuperview];
|
|
3355
|
+
[handoff.stickyMarker removeFromSuperview];
|
|
3356
|
+
if (handoff.ownsTransitionHosts) {
|
|
3357
|
+
[handoff.ownedTopHost removeFromSuperview];
|
|
3358
|
+
[handoff.ownedStickyHost removeFromSuperview];
|
|
3359
|
+
}
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
- (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex
|
|
3364
|
+
{
|
|
3365
|
+
// OneKey patch: a page whose list is not mounted yet has no scroll view to
|
|
3366
|
+
// own an edge effect, so its masked top shows the bare background. An empty
|
|
3367
|
+
// stand-in scroll view resting past its top edge renders the same Hard
|
|
3368
|
+
// material (the settled header is masked out under the overlay as well).
|
|
3369
|
+
if (@available(iOS 27.0, *)) {
|
|
3370
|
+
if (pageIndex == _currentIndex || pageIndex < 0 ||
|
|
3371
|
+
pageIndex >= (NSInteger)_pageControllers.count) return NO;
|
|
3372
|
+
UIView *page = _pageControllers[pageIndex].view;
|
|
3373
|
+
UIView *container = page.superview;
|
|
3374
|
+
if (page.window != self.window || container == nil ||
|
|
3375
|
+
_stickyHeaderView == nil || _headerHeight <= 0 ||
|
|
3376
|
+
_headerOffset < _headerHeight - 0.5) return NO;
|
|
3377
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *existing in _programmaticScrollEdgeOwners) {
|
|
3378
|
+
if (existing.page == page) return YES;
|
|
3379
|
+
}
|
|
3380
|
+
CGFloat boundary = self.effectiveTopOverlayHeight + self.currentStickyHeaderHeight;
|
|
3381
|
+
CGFloat pageTop = [page convertPoint:CGPointZero toView:_containerView].y;
|
|
3382
|
+
if (boundary - pageTop <= 0 || CGRectGetWidth(page.bounds) <= 0) return NO;
|
|
3383
|
+
UIScrollView *standIn = [UIScrollView new];
|
|
3384
|
+
standIn.userInteractionEnabled = NO;
|
|
3385
|
+
standIn.scrollsToTop = NO;
|
|
3386
|
+
standIn.showsVerticalScrollIndicator = NO;
|
|
3387
|
+
standIn.showsHorizontalScrollIndicator = NO;
|
|
3388
|
+
standIn.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
3389
|
+
standIn.backgroundColor = UIColor.clearColor;
|
|
3390
|
+
standIn.accessibilityElementsHidden = YES;
|
|
3391
|
+
standIn.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle;
|
|
3392
|
+
[container insertSubview:standIn aboveSubview:page];
|
|
3393
|
+
|
|
3394
|
+
RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new];
|
|
3395
|
+
owner.scrollView = standIn;
|
|
3396
|
+
owner.page = page;
|
|
3397
|
+
owner.standInScrollView = standIn;
|
|
3398
|
+
owner.originalStyle = UIScrollEdgeEffectStyle.hardStyle;
|
|
3399
|
+
owner.ownsTransitionHosts = YES;
|
|
3400
|
+
UIView *(^host)(void) = ^UIView *(void) {
|
|
3401
|
+
UIView *view = [UIView new];
|
|
3402
|
+
view.userInteractionEnabled = NO;
|
|
3403
|
+
view.accessibilityElementsHidden = YES;
|
|
3404
|
+
[container insertSubview:view aboveSubview:standIn];
|
|
3405
|
+
UILabel *marker = [UILabel new];
|
|
3406
|
+
marker.frame = view.bounds;
|
|
3407
|
+
marker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
3408
|
+
marker.text = @" ";
|
|
3409
|
+
marker.textColor = UIColor.clearColor;
|
|
3410
|
+
marker.backgroundColor = UIColor.clearColor;
|
|
3411
|
+
marker.isAccessibilityElement = NO;
|
|
3412
|
+
[view addSubview:marker];
|
|
3413
|
+
return view;
|
|
3414
|
+
};
|
|
3415
|
+
owner.ownedTopHost = host();
|
|
3416
|
+
owner.topHost = owner.ownedTopHost;
|
|
3417
|
+
owner.topInteraction = [UIScrollEdgeElementContainerInteraction new];
|
|
3418
|
+
owner.topInteraction.edge = UIRectEdgeTop;
|
|
3419
|
+
owner.topInteraction.scrollView = standIn;
|
|
3420
|
+
[owner.topHost addInteraction:owner.topInteraction];
|
|
3421
|
+
owner.ownedStickyHost = host();
|
|
3422
|
+
owner.stickyHost = owner.ownedStickyHost;
|
|
3423
|
+
owner.stickyInteraction = [UIScrollEdgeElementContainerInteraction new];
|
|
3424
|
+
owner.stickyInteraction.edge = UIRectEdgeTop;
|
|
3425
|
+
owner.stickyInteraction.scrollView = standIn;
|
|
3426
|
+
[owner.stickyHost addInteraction:owner.stickyInteraction];
|
|
3427
|
+
if (_programmaticScrollEdges == nil) {
|
|
3428
|
+
_programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable];
|
|
3429
|
+
_programmaticScrollEdgeOwners = [NSMutableArray new];
|
|
3430
|
+
}
|
|
3431
|
+
[self layoutStandInScrollEdgeOwner:owner];
|
|
3432
|
+
[_programmaticScrollEdges setObject:owner forKey:standIn];
|
|
3433
|
+
[_programmaticScrollEdgeOwners addObject:owner];
|
|
3434
|
+
return YES;
|
|
3435
|
+
}
|
|
3436
|
+
return NO;
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
// Stand-ins live in the pager container rather than inside their page, so they
|
|
3440
|
+
// do not follow page or header geometry on their own. Recompute them from the
|
|
3441
|
+
// current page origin and overlay + sticky boundary on every layout pass.
|
|
3442
|
+
- (BOOL)layoutStandInScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwner *)owner
|
|
3443
|
+
{
|
|
3444
|
+
UIScrollView *standIn = owner.standInScrollView;
|
|
3445
|
+
UIView *page = owner.page;
|
|
3446
|
+
UIView *container = standIn.superview;
|
|
3447
|
+
BOOL valid = standIn != nil && page != nil && container != nil &&
|
|
3448
|
+
page.superview == container && _containerView != nil;
|
|
3449
|
+
CGFloat width = valid ? CGRectGetWidth(page.bounds) : 0;
|
|
3450
|
+
CGFloat height = 0;
|
|
3451
|
+
CGPoint origin = CGPointZero;
|
|
3452
|
+
if (valid) {
|
|
3453
|
+
CGFloat boundary = self.effectiveTopOverlayHeight + self.currentStickyHeaderHeight;
|
|
3454
|
+
height = boundary - [page convertPoint:CGPointZero toView:_containerView].y;
|
|
3455
|
+
origin = [page convertPoint:CGPointZero toView:container];
|
|
3456
|
+
valid = width > 0 && height > 0;
|
|
3457
|
+
}
|
|
3458
|
+
standIn.hidden = !valid;
|
|
3459
|
+
owner.ownedTopHost.hidden = !valid;
|
|
3460
|
+
owner.ownedStickyHost.hidden = !valid;
|
|
3461
|
+
if (!valid) return NO;
|
|
3462
|
+
CGRect frame = CGRectMake(origin.x, origin.y, width, height);
|
|
3463
|
+
if (!CGRectEqualToRect(standIn.frame, frame)) standIn.frame = frame;
|
|
3464
|
+
// Rest past the top edge so UIKit draws the edge material.
|
|
3465
|
+
CGFloat scrolled = MAX(_headerHeight, 1);
|
|
3466
|
+
CGSize contentSize = CGSizeMake(width, scrolled + height + 1);
|
|
3467
|
+
if (!CGSizeEqualToSize(standIn.contentSize, contentSize)) standIn.contentSize = contentSize;
|
|
3468
|
+
if (standIn.contentOffset.y != scrolled) standIn.contentOffset = CGPointMake(0, scrolled);
|
|
3469
|
+
void (^place)(UIView *, UIView *) = ^(UIView *host, UIView *reference) {
|
|
3470
|
+
if (host == nil) return;
|
|
3471
|
+
CGRect hostFrame = reference != nil
|
|
3472
|
+
? [reference convertRect:reference.bounds toView:container] : CGRectZero;
|
|
3473
|
+
hostFrame.origin.x = origin.x;
|
|
3474
|
+
hostFrame.size.width = width;
|
|
3475
|
+
if (!CGRectEqualToRect(host.frame, hostFrame)) host.frame = hostFrame;
|
|
3476
|
+
};
|
|
3477
|
+
place(owner.ownedTopHost, _topOverlayHostView);
|
|
3478
|
+
place(owner.ownedStickyHost, _stickyHeaderView);
|
|
3479
|
+
return YES;
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
- (void)layoutStandInScrollEdges
|
|
3483
|
+
{
|
|
3484
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
|
|
3485
|
+
if (owner.standInScrollView != nil) [self layoutStandInScrollEdgeOwner:owner];
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
- (BOOL)hasProgrammaticScrollEdgeForPage:(UIView *)page
|
|
3490
|
+
{
|
|
3491
|
+
if (@available(iOS 26.0, *)) {
|
|
3492
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdges.objectEnumerator) {
|
|
3493
|
+
if (owner.page == page && owner.standInScrollView == nil &&
|
|
3494
|
+
owner.scrollView.window == self.window &&
|
|
3495
|
+
owner.topInteraction.scrollView == owner.scrollView) return YES;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
return NO;
|
|
3499
|
+
}
|
|
3500
|
+
|
|
2052
3501
|
- (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView
|
|
2053
3502
|
{
|
|
2054
3503
|
[self syncScrollEdgeAppearance];
|
|
2055
3504
|
if (@available(iOS 26.0, *)) {
|
|
3505
|
+
if (_programmaticScrollEdgeOwners.count > 0 &&
|
|
3506
|
+
![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:YES]) {
|
|
3507
|
+
[self clearProgrammaticScrollEdges];
|
|
3508
|
+
}
|
|
3509
|
+
if (scrollView != nil && [_programmaticScrollEdges objectForKey:scrollView] != nil) {
|
|
3510
|
+
[self updateScrollEdgeContentMasks];
|
|
3511
|
+
return;
|
|
3512
|
+
}
|
|
2056
3513
|
if (_pendingTopOverlayAppearanceCommit) scrollView = nil;
|
|
2057
3514
|
BOOL externalOwnerReady = _externalTopOverlayTag <= 0 ||
|
|
2058
3515
|
_externalOuterPager == nil ||
|
|
@@ -2147,10 +3604,22 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2147
3604
|
|
|
2148
3605
|
- (void)updateHardEdgeSeparatorCovers
|
|
2149
3606
|
{
|
|
3607
|
+
// OneKey patch: transitional edge owners draw the same Hard hairline while
|
|
3608
|
+
// the settled interaction is detached, so keep the covers during transitions.
|
|
3609
|
+
BOOL transitional = _programmaticScrollEdgeOwners.count > 0;
|
|
2150
3610
|
BOOL enabled = _topScrollEdgeEnabled &&
|
|
2151
3611
|
_topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
|
|
2152
|
-
_topEdgeScrollView != nil && self.window != nil && !_isBeingRecycled;
|
|
3612
|
+
(_topEdgeScrollView != nil || transitional) && self.window != nil && !_isBeingRecycled;
|
|
2153
3613
|
if (!enabled && _topEdgeSeparatorCover == nil && _stickyEdgeSeparatorCover == nil) return;
|
|
3614
|
+
BOOL transitionalSticky = NO;
|
|
3615
|
+
if (transitional && _topEdgeScrollView == nil) {
|
|
3616
|
+
for (RNCCollapsiblePagerTransitionEdgeOwner *owner in _programmaticScrollEdgeOwners) {
|
|
3617
|
+
if (owner.stickyInteraction != nil) {
|
|
3618
|
+
transitionalSticky = YES;
|
|
3619
|
+
break;
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
2154
3623
|
UIColor *color = nil;
|
|
2155
3624
|
for (UIView *view = self; view != nil; view = view.superview) {
|
|
2156
3625
|
UIColor *candidate = [view.backgroundColor resolvedColorWithTraitCollection:
|
|
@@ -2164,7 +3633,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2164
3633
|
_topOverlayHostView.traitCollection];
|
|
2165
3634
|
CGFloat scale = self.window.screen.scale ?: self.traitCollection.displayScale;
|
|
2166
3635
|
CGFloat pixel = 1.0 / MAX(1, scale);
|
|
2167
|
-
UIView *
|
|
3636
|
+
UIView *topHost = _topEdgeInteractionHost;
|
|
3637
|
+
UIView *stickyHost = _stickyEdgeInteractionHost;
|
|
3638
|
+
if (_topEdgeScrollView == nil && transitional) {
|
|
3639
|
+
topHost = _topOverlayHostView;
|
|
3640
|
+
stickyHost = transitionalSticky ? _stickyHeaderView : nil;
|
|
3641
|
+
}
|
|
3642
|
+
UIView *hosts[] = {topHost, stickyHost};
|
|
2168
3643
|
CALayer *covers[] = {_topEdgeSeparatorCover, _stickyEdgeSeparatorCover};
|
|
2169
3644
|
for (NSInteger index = 0; index < 2; index++) {
|
|
2170
3645
|
UIView *host = hosts[index];
|
|
@@ -2187,6 +3662,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2187
3662
|
CGRectGetWidth(_containerView.bounds), pixel);
|
|
2188
3663
|
cover.contentsScale = scale;
|
|
2189
3664
|
cover.backgroundColor = color.CGColor;
|
|
3665
|
+
cover.hidden = index == 0 && (_stickyHeaderIsPinned || transitionalSticky);
|
|
2190
3666
|
}
|
|
2191
3667
|
if (index == 0) _topEdgeSeparatorCover = cover;
|
|
2192
3668
|
else _stickyEdgeSeparatorCover = cover;
|
|
@@ -2195,9 +3671,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2195
3671
|
|
|
2196
3672
|
- (void)dealloc
|
|
2197
3673
|
{
|
|
3674
|
+
[self cancelNativeToolbarSettlement];
|
|
3675
|
+
[self stopProgrammaticTabProgress];
|
|
3676
|
+
[self clearProgrammaticScrollEdges];
|
|
2198
3677
|
[self updateTopScrollEdgeForScrollView:nil];
|
|
2199
3678
|
[self cancelHeaderSettledCheck];
|
|
2200
3679
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"OneKeyNativeListScrollCommandAccepted" object:nil];
|
|
3680
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"OneKeyNativeScrollViewDidBecomeReady" object:nil];
|
|
2201
3681
|
for (UIScrollView *scrollView in _originalInsets.keyEnumerator) {
|
|
2202
3682
|
[self updateNativeScrollerViewport:scrollView stickyHeight:0];
|
|
2203
3683
|
}
|
|
@@ -2247,6 +3727,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2247
3727
|
}
|
|
2248
3728
|
_hasPendingDirectNativePagerChange = NO;
|
|
2249
3729
|
if (_directNativePagerEnabled == enabled) return;
|
|
3730
|
+
[self cancelNativeToolbarSettlement];
|
|
3731
|
+
[self cancelPendingNativePagerScroll];
|
|
2250
3732
|
|
|
2251
3733
|
[self restoreScrollEdgeContentMasks];
|
|
2252
3734
|
[self detachScrollObserver];
|
|
@@ -2308,12 +3790,12 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2308
3790
|
return width * MAX(0, physicalIndex);
|
|
2309
3791
|
}
|
|
2310
3792
|
|
|
2311
|
-
- (CGFloat)
|
|
3793
|
+
- (CGFloat)directPagerProgressForOffset:(CGFloat)offset
|
|
2312
3794
|
{
|
|
2313
3795
|
CGFloat width = CGRectGetWidth(_pagerScrollView.bounds);
|
|
2314
3796
|
if (width <= 0 || _pageControllers.count == 0) return _currentIndex;
|
|
2315
3797
|
CGFloat physicalProgress = RNCClamp(
|
|
2316
|
-
|
|
3798
|
+
offset / width,
|
|
2317
3799
|
0,
|
|
2318
3800
|
_pageControllers.count - 1
|
|
2319
3801
|
);
|
|
@@ -2322,11 +3804,56 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2322
3804
|
: _pageControllers.count - 1 - physicalProgress;
|
|
2323
3805
|
}
|
|
2324
3806
|
|
|
3807
|
+
- (CGFloat)directPagerProgress {
|
|
3808
|
+
return [self directPagerProgressForOffset:_pagerScrollView.contentOffset.x];
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
- (void)stopProgrammaticTabProgress {
|
|
3812
|
+
if (_tabProgressDisplayLink != nil && _tabProgressWidth > 0 && fabs(CGRectGetWidth(_pagerScrollView.bounds) - _tabProgressWidth) < 0.5) {
|
|
3813
|
+
CALayer *presentation = _pagerScrollView.layer.presentationLayer;
|
|
3814
|
+
if (presentation && std::isfinite(presentation.bounds.origin.x)) {
|
|
3815
|
+
[_nativeTabBarView setProgress:[self directPagerProgressForOffset:presentation.bounds.origin.x]];
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
[_tabProgressDisplayLink invalidate];
|
|
3819
|
+
_tabProgressDisplayLink = nil;
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3822
|
+
- (void)updateNativeTabProgress:(CGFloat)progress {
|
|
3823
|
+
if (_tabProgressDisplayLink == nil) [_nativeTabBarView setProgress:progress];
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
- (void)sampleProgrammaticTabProgress:(CADisplayLink *)link {
|
|
3827
|
+
if (link != _tabProgressDisplayLink) { [link invalidate]; return; }
|
|
3828
|
+
if (self.window == nil || !_transitioning || ![_nativeTabBarView usesControlledTextProgress] ||
|
|
3829
|
+
_tabProgressGeneration != _generation || _tabProgressTransition != _transitionId ||
|
|
3830
|
+
!std::isfinite(CGRectGetWidth(_pagerScrollView.bounds)) || _tabProgressWidth <= 0 ||
|
|
3831
|
+
fabs(CGRectGetWidth(_pagerScrollView.bounds) - _tabProgressWidth) >= 0.5) {
|
|
3832
|
+
[self stopProgrammaticTabProgress];
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
CALayer *presentation = _pagerScrollView.layer.presentationLayer;
|
|
3836
|
+
if (presentation == nil || !std::isfinite(presentation.bounds.origin.x)) return;
|
|
3837
|
+
[_nativeTabBarView setProgress:[self directPagerProgressForOffset:presentation.bounds.origin.x]];
|
|
3838
|
+
}
|
|
3839
|
+
|
|
3840
|
+
- (void)startProgrammaticTabProgress {
|
|
3841
|
+
[self stopProgrammaticTabProgress];
|
|
3842
|
+
RNCPagerPresentationProgressProxy *proxy = [RNCPagerPresentationProgressProxy new];
|
|
3843
|
+
proxy.target = self;
|
|
3844
|
+
_tabProgressWidth = CGRectGetWidth(_pagerScrollView.bounds);
|
|
3845
|
+
_tabProgressGeneration = _generation;
|
|
3846
|
+
_tabProgressTransition = _transitionId;
|
|
3847
|
+
_tabProgressDisplayLink = [CADisplayLink displayLinkWithTarget:proxy selector:@selector(tick:)];
|
|
3848
|
+
[_tabProgressDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
|
|
3849
|
+
}
|
|
3850
|
+
|
|
2325
3851
|
#pragma mark - Smooth shared header ownership
|
|
2326
3852
|
|
|
2327
3853
|
- (void)restorePinnedStickyHeader
|
|
2328
3854
|
{
|
|
2329
3855
|
if (!_stickyHeaderIsPinned) return;
|
|
3856
|
+
BOOL borrowedHost = [self borrowedPinnedStickyOwner] != nil;
|
|
2330
3857
|
_stickyHeaderIsPinned = NO;
|
|
2331
3858
|
_stickyHeaderView.transform = CGAffineTransformIdentity;
|
|
2332
3859
|
_nativeTabBarView.transform = CGAffineTransformIdentity;
|
|
@@ -2337,14 +3864,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2337
3864
|
if (_stickyHeaderView != nil) [_sharedHeaderHostView addSubview:_stickyHeaderView];
|
|
2338
3865
|
[_sharedHeaderHostView addSubview:_nativeTabBarView];
|
|
2339
3866
|
[_sharedHeaderHostView addSubview:_nativeSubHeaderView];
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
3867
|
+
if (!borrowedHost) {
|
|
3868
|
+
_pinnedStickyHostView.hidden = YES;
|
|
3869
|
+
_pinnedStickyHostView.layer.zPosition = 0;
|
|
3870
|
+
[_containerView addSubview:_pinnedStickyHostView];
|
|
3871
|
+
}
|
|
2343
3872
|
if ([_pagerScrollView isKindOfClass:RNCCollapsiblePagerDirectScrollView.class]) {
|
|
2344
3873
|
((RNCCollapsiblePagerDirectScrollView *)_pagerScrollView).excludedHeaderView = _sharedHeaderHostView;
|
|
2345
3874
|
}
|
|
2346
3875
|
[_nativeTabBarView updateAncestorGesturePrecedence];
|
|
2347
3876
|
[_nativeSubHeaderView updateAncestorGesturePrecedence];
|
|
3877
|
+
[self bringReservedStickyControlToFront];
|
|
2348
3878
|
}
|
|
2349
3879
|
|
|
2350
3880
|
- (void)restoreSharedHeadersToContainer
|
|
@@ -2419,10 +3949,22 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2419
3949
|
reason ?: @"unknown"]);
|
|
2420
3950
|
}
|
|
2421
3951
|
|
|
3952
|
+
- (NSInteger)stickyHeaderHeightForPageIndex:(NSInteger)index
|
|
3953
|
+
{
|
|
3954
|
+
if (index < 0 || index >= (NSInteger)_stickyHeaderHeights.count) return _stickyHeaderHeight;
|
|
3955
|
+
id value = _stickyHeaderHeights[index];
|
|
3956
|
+
return [value isKindOfClass:NSNumber.class] ? MAX(0, [value integerValue]) : _stickyHeaderHeight;
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
- (NSInteger)currentStickyHeaderHeight
|
|
3960
|
+
{
|
|
3961
|
+
return [self stickyHeaderHeightForPageIndex:_currentIndex];
|
|
3962
|
+
}
|
|
3963
|
+
|
|
2422
3964
|
- (void)layoutSharedHeaders
|
|
2423
3965
|
{
|
|
2424
3966
|
CGFloat width = CGRectGetWidth(self.bounds);
|
|
2425
|
-
CGFloat totalHeight = _headerHeight +
|
|
3967
|
+
CGFloat totalHeight = _headerHeight + self.currentStickyHeaderHeight;
|
|
2426
3968
|
BOOL attachedToList = _nativeSmoothHeaderScrollEnabled &&
|
|
2427
3969
|
_sharedHeaderScrollView != nil && !_sharedHeadersLiftedForPagerTransition;
|
|
2428
3970
|
|
|
@@ -2440,20 +3982,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2440
3982
|
);
|
|
2441
3983
|
CGFloat stickyY = _headerHeight;
|
|
2442
3984
|
_headerView.frame = CGRectMake(0, 0, width, _headerHeight);
|
|
2443
|
-
|
|
2444
|
-
|
|
3985
|
+
RNCCollapsiblePagerTransitionEdgeOwner *borrowedOwner = [self borrowedPinnedStickyOwner];
|
|
3986
|
+
UIScrollView *pinnedScrollView = borrowedOwner.scrollView ?: _sharedHeaderScrollView;
|
|
3987
|
+
CGPoint pinnedOrigin = (borrowedOwner != nil || _stickyHeaderIsPinned) && pinnedScrollView != nil
|
|
3988
|
+
? [pinnedScrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
|
|
3989
|
+
fromView:_containerView]
|
|
2445
3990
|
: CGPointMake(0, self.effectiveTopOverlayHeight);
|
|
2446
3991
|
_pinnedStickyHostView.frame = CGRectMake(
|
|
2447
|
-
pinnedOrigin.x, pinnedOrigin.y, width,
|
|
3992
|
+
pinnedOrigin.x, pinnedOrigin.y, width, self.currentStickyHeaderHeight);
|
|
2448
3993
|
CGFloat stickyChildY = _stickyHeaderIsPinned ? 0 : stickyY;
|
|
2449
|
-
_stickyHeaderView.frame = CGRectMake(0, stickyChildY, width,
|
|
3994
|
+
_stickyHeaderView.frame = CGRectMake(0, stickyChildY, width, self.currentStickyHeaderHeight);
|
|
2450
3995
|
CGFloat nativeTabBarVisibleHeight = _nativeTabBarView.hidden
|
|
2451
3996
|
? 0
|
|
2452
|
-
: MIN(
|
|
3997
|
+
: MIN(self.currentStickyHeaderHeight, _nativeTabBarHeight);
|
|
3998
|
+
CGFloat tabReservedWidth = MIN(width, MAX(0, _nativeTabBarTrailingReservedWidth));
|
|
2453
3999
|
_nativeTabBarView.frame = CGRectMake(
|
|
2454
|
-
0,
|
|
4000
|
+
self.isLtrLayout ? 0 : tabReservedWidth,
|
|
2455
4001
|
stickyChildY,
|
|
2456
|
-
width,
|
|
4002
|
+
width - tabReservedWidth,
|
|
2457
4003
|
nativeTabBarVisibleHeight
|
|
2458
4004
|
);
|
|
2459
4005
|
_nativeSubHeaderView.frame = CGRectMake(
|
|
@@ -2461,15 +4007,32 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2461
4007
|
stickyChildY + nativeTabBarVisibleHeight,
|
|
2462
4008
|
width,
|
|
2463
4009
|
MIN(
|
|
2464
|
-
MAX(0,
|
|
4010
|
+
MAX(0, self.currentStickyHeaderHeight - nativeTabBarVisibleHeight),
|
|
2465
4011
|
_nativeSubHeaderHeight
|
|
2466
4012
|
)
|
|
2467
4013
|
);
|
|
2468
4014
|
_topOverlayHostView.frame = CGRectMake(0, 0, width, self.effectiveTopOverlayHeight);
|
|
2469
4015
|
_topOverlayView.frame = _topOverlayHostView.bounds;
|
|
4016
|
+
[self bringReservedStickyControlToFront];
|
|
2470
4017
|
[self applyHeaderOffset];
|
|
2471
4018
|
}
|
|
2472
4019
|
|
|
4020
|
+
- (void)bringReservedStickyControlToFront
|
|
4021
|
+
{
|
|
4022
|
+
if (_stickyHeaderView != nil &&
|
|
4023
|
+
_stickyHeaderView.superview == _nativeTabBarView.superview) {
|
|
4024
|
+
if (_nativeTabBarTrailingReservedWidth > 0) {
|
|
4025
|
+
[_stickyHeaderView.superview bringSubviewToFront:_stickyHeaderView];
|
|
4026
|
+
} else {
|
|
4027
|
+
[_nativeTabBarView.superview bringSubviewToFront:_nativeTabBarView];
|
|
4028
|
+
if (!_nativeSubHeaderView.hidden &&
|
|
4029
|
+
_nativeSubHeaderView.superview == _nativeTabBarView.superview) {
|
|
4030
|
+
[_nativeSubHeaderView.superview bringSubviewToFront:_nativeSubHeaderView];
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
|
|
2473
4036
|
- (void)updatePinnedStickyHeader
|
|
2474
4037
|
{
|
|
2475
4038
|
BOOL attachedToList = _nativeSmoothHeaderScrollEnabled &&
|
|
@@ -2497,7 +4060,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2497
4060
|
CGPoint origin = [scrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
|
|
2498
4061
|
fromView:_containerView];
|
|
2499
4062
|
_pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y,
|
|
2500
|
-
CGRectGetWidth(self.bounds),
|
|
4063
|
+
CGRectGetWidth(self.bounds), self.currentStickyHeaderHeight);
|
|
2501
4064
|
}
|
|
2502
4065
|
return;
|
|
2503
4066
|
}
|
|
@@ -2515,11 +4078,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2515
4078
|
[host addSubview:_nativeSubHeaderView];
|
|
2516
4079
|
CGFloat childY = shouldPin ? 0 : _headerHeight;
|
|
2517
4080
|
CGFloat width = CGRectGetWidth(self.bounds);
|
|
2518
|
-
CGFloat tabHeight = _nativeTabBarView.hidden ? 0 : MIN(
|
|
2519
|
-
|
|
2520
|
-
|
|
4081
|
+
CGFloat tabHeight = _nativeTabBarView.hidden ? 0 : MIN(self.currentStickyHeaderHeight, _nativeTabBarHeight);
|
|
4082
|
+
CGFloat tabReservedWidth = MIN(width, MAX(0, _nativeTabBarTrailingReservedWidth));
|
|
4083
|
+
_stickyHeaderView.frame = CGRectMake(0, childY, width, self.currentStickyHeaderHeight);
|
|
4084
|
+
_nativeTabBarView.frame = CGRectMake(self.isLtrLayout ? 0 : tabReservedWidth,
|
|
4085
|
+
childY, width - tabReservedWidth, tabHeight);
|
|
2521
4086
|
_nativeSubHeaderView.frame = CGRectMake(0, childY + tabHeight, width,
|
|
2522
|
-
MIN(MAX(0,
|
|
4087
|
+
MIN(MAX(0, self.currentStickyHeaderHeight - tabHeight), _nativeSubHeaderHeight));
|
|
2523
4088
|
_pinnedStickyHostView.hidden = !shouldPin;
|
|
2524
4089
|
if ([_pagerScrollView isKindOfClass:RNCCollapsiblePagerDirectScrollView.class]) {
|
|
2525
4090
|
((RNCCollapsiblePagerDirectScrollView *)_pagerScrollView).excludedHeaderView =
|
|
@@ -2530,14 +4095,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2530
4095
|
_pinnedStickyHostView.layer.zPosition = 1000;
|
|
2531
4096
|
CGPoint origin = [scrollView convertPoint:CGPointMake(0, self.effectiveTopOverlayHeight)
|
|
2532
4097
|
fromView:_containerView];
|
|
2533
|
-
_pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y, width,
|
|
4098
|
+
_pinnedStickyHostView.frame = CGRectMake(origin.x, origin.y, width, self.currentStickyHeaderHeight);
|
|
2534
4099
|
} else {
|
|
2535
4100
|
_pinnedStickyHostView.layer.zPosition = 0;
|
|
2536
4101
|
[_containerView addSubview:_pinnedStickyHostView];
|
|
2537
4102
|
}
|
|
2538
4103
|
[_nativeTabBarView updateAncestorGesturePrecedence];
|
|
2539
4104
|
[_nativeSubHeaderView updateAncestorGesturePrecedence];
|
|
4105
|
+
[self bringReservedStickyControlToFront];
|
|
2540
4106
|
[self updateTopScrollEdgeForScrollView:_observedScrollView];
|
|
4107
|
+
[self logHomeVisualGeometry:shouldPin ? @"pin" : @"unpin"
|
|
4108
|
+
scrollView:_observedScrollView];
|
|
2541
4109
|
}
|
|
2542
4110
|
|
|
2543
4111
|
- (void)preparePageForHorizontalTransitionAtIndex:(NSInteger)pageIndex
|
|
@@ -2550,8 +4118,81 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2550
4118
|
}
|
|
2551
4119
|
}
|
|
2552
4120
|
|
|
4121
|
+
- (void)cancelNativeToolbarSettlement {
|
|
4122
|
+
[_toolbarSettleDisplayLink invalidate];
|
|
4123
|
+
_toolbarSettleDisplayLink = nil;
|
|
4124
|
+
_toolbarSettleAttempted = NO;
|
|
4125
|
+
_toolbarSettleTicks = 0;
|
|
4126
|
+
}
|
|
4127
|
+
|
|
4128
|
+
- (void)scheduleNativeToolbarSettlement {
|
|
4129
|
+
CGFloat width = CGRectGetWidth(_pagerScrollView.bounds);
|
|
4130
|
+
BOOL sameAttempt = _toolbarSettleAttempted && _toolbarSettleGeneration == _generation &&
|
|
4131
|
+
_toolbarSettleTransition == _transitionId && _toolbarSettlePage == _currentIndex &&
|
|
4132
|
+
_toolbarSettleWidth == width;
|
|
4133
|
+
if (sameAttempt) return;
|
|
4134
|
+
[self cancelNativeToolbarSettlement];
|
|
4135
|
+
_toolbarSettleAttempted = YES;
|
|
4136
|
+
_toolbarSettleGeneration = _generation;
|
|
4137
|
+
_toolbarSettleTransition = _transitionId;
|
|
4138
|
+
_toolbarSettlePage = _currentIndex;
|
|
4139
|
+
_toolbarSettleWidth = width;
|
|
4140
|
+
RNCPagerPresentationProgressProxy *proxy = [RNCPagerPresentationProgressProxy new];
|
|
4141
|
+
proxy.target = self;
|
|
4142
|
+
proxy.toolbarSettlement = YES;
|
|
4143
|
+
_toolbarSettleDisplayLink = [CADisplayLink displayLinkWithTarget:proxy selector:@selector(tick:)];
|
|
4144
|
+
[_toolbarSettleDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
|
|
4145
|
+
}
|
|
4146
|
+
|
|
4147
|
+
- (void)sampleToolbarSettlement:(CADisplayLink *)link {
|
|
4148
|
+
if (link != _toolbarSettleDisplayLink) { [link invalidate]; return; }
|
|
4149
|
+
if (_toolbarSettleGeneration != _generation || _toolbarSettleTransition != _transitionId ||
|
|
4150
|
+
_toolbarSettlePage != _currentIndex ||
|
|
4151
|
+
_toolbarSettleWidth != CGRectGetWidth(_pagerScrollView.bounds) ||
|
|
4152
|
+
!self.window || _nativeTabBarView.window != self.window || ![_nativeTabBarView ownsSettledToolbar]) {
|
|
4153
|
+
[self cancelNativeToolbarSettlement];
|
|
4154
|
+
return;
|
|
4155
|
+
}
|
|
4156
|
+
++_toolbarSettleTicks;
|
|
4157
|
+
[self syncNativeToolbarState];
|
|
4158
|
+
if (link == _toolbarSettleDisplayLink && _toolbarSettleTicks >= 2) {
|
|
4159
|
+
[link invalidate];
|
|
4160
|
+
_toolbarSettleDisplayLink = nil;
|
|
4161
|
+
}
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
- (void)syncNativeToolbarState {
|
|
4165
|
+
BOOL logicalBusy = !self.window || _isBeingRecycled || !_hasAppliedInitialPage || _toolbarTransitionPending ||
|
|
4166
|
+
_transitioning || _isPagerDragging || _externalOuterTransitioning ||
|
|
4167
|
+
(_externalOuterPager != nil && !_externalOuterPageActive) || _needsSlotRebuild ||
|
|
4168
|
+
_pendingGoToIndex >= 0 || _transitionPageOffsets != nil || _pendingNativePagerScrollCompletion != nil ||
|
|
4169
|
+
_tabProgressDisplayLink != nil || _currentIndex < 0 || _currentIndex >= _pageControllers.count ||
|
|
4170
|
+
CGRectGetWidth(self.bounds) <= 0 || CGRectGetHeight(self.bounds) <= 0 ||
|
|
4171
|
+
_pagerScrollView.dragging || _pagerScrollView.decelerating;
|
|
4172
|
+
BOOL busy = logicalBusy || _pagerScrollView.tracking;
|
|
4173
|
+
if (!busy && _directNativePagerEnabled) {
|
|
4174
|
+
CALayer *presentation = _pagerScrollView.layer.presentationLayer;
|
|
4175
|
+
CGFloat offset = presentation ? presentation.bounds.origin.x : _pagerScrollView.contentOffset.x;
|
|
4176
|
+
busy = CGRectGetWidth(_pagerScrollView.bounds) <= 0 || !std::isfinite(offset) ||
|
|
4177
|
+
fabs(offset - [self directPagerOffsetForIndex:_currentIndex]) >= 0.5;
|
|
4178
|
+
} else if (!busy) {
|
|
4179
|
+
busy = _pageViewController.viewControllers.firstObject != _pageControllers[_currentIndex];
|
|
4180
|
+
}
|
|
4181
|
+
[_nativeTabBarView updateToolbarPagerIndex:_currentIndex busy:busy];
|
|
4182
|
+
if (busy && !logicalBusy && [_nativeTabBarView ownsSettledToolbar] &&
|
|
4183
|
+
_nativeTabBarView.window == self.window && !_nativeTabBarView.hidden &&
|
|
4184
|
+
CGRectGetWidth(_pagerScrollView.bounds) > 0) {
|
|
4185
|
+
[self scheduleNativeToolbarSettlement];
|
|
4186
|
+
} else {
|
|
4187
|
+
[self cancelNativeToolbarSettlement];
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
|
|
2553
4191
|
- (void)beginPageStateTransition
|
|
2554
4192
|
{
|
|
4193
|
+
[self cancelNativeToolbarSettlement];
|
|
4194
|
+
_toolbarTransitionPending = YES;
|
|
4195
|
+
[_nativeTabBarView updateToolbarPagerIndex:-1 busy:YES];
|
|
2555
4196
|
[self cancelPagerTop];
|
|
2556
4197
|
if (!_nativeSmoothHeaderScrollEnabled || _headerHeight <= 0 || _transitionPageOffsets != nil) return;
|
|
2557
4198
|
_transitionSourceDisplayBody = MAX(_observedScrollView.contentOffset.y + _observedScrollView.contentInset.top - _headerHeight, 0);
|
|
@@ -2689,6 +4330,15 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2689
4330
|
- (void)mountingTransactionDidMount:(const MountingTransaction &)transaction
|
|
2690
4331
|
withSurfaceTelemetry:(const SurfaceTelemetry &)surfaceTelemetry
|
|
2691
4332
|
{
|
|
4333
|
+
if (_needsSlotRebuild && _deferTopEdgeSlotRebuild &&
|
|
4334
|
+
_topScrollEdgeEnabled && _nativeSmoothHeaderScrollEnabled &&
|
|
4335
|
+
_topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
|
|
4336
|
+
_topOverlayHeight > 0 && _pageKeys.count > 0 &&
|
|
4337
|
+
_externalTopOverlayTag <= 0 &&
|
|
4338
|
+
_logicalChildren.count == _pageKeys.count + 3 &&
|
|
4339
|
+
!_transitioning && !_isPagerDragging && !_isBeingRecycled) {
|
|
4340
|
+
_deferTopEdgeSlotRebuild = NO;
|
|
4341
|
+
}
|
|
2692
4342
|
if (_needsSlotRebuild && !_deferTopEdgeSlotRebuild &&
|
|
2693
4343
|
!_transitioning && !_isPagerDragging) {
|
|
2694
4344
|
[self rebuildSlots];
|
|
@@ -2711,6 +4361,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2711
4361
|
}
|
|
2712
4362
|
[self updateScrollEdgeContentMasks];
|
|
2713
4363
|
[_mountingRemovedScrollViews removeAllObjects];
|
|
4364
|
+
[self logHomeVisualGeometry:@"did-mount" scrollView:_observedScrollView];
|
|
2714
4365
|
if (!_nativeSmoothHeaderScrollEnabled || _isBeingRecycled || self.window == nil ||
|
|
2715
4366
|
_currentIndex < 0 || _currentIndex >= _pageControllers.count) return;
|
|
2716
4367
|
// Prepare newly mounted owned scrollers before their first frame, even while
|
|
@@ -2728,6 +4379,23 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2728
4379
|
[self applyInsetsToScrollView:scrollView pageIndex:index restore:YES];
|
|
2729
4380
|
}
|
|
2730
4381
|
}
|
|
4382
|
+
UIView *page = _pageControllers[_currentIndex].view;
|
|
4383
|
+
if (_scrollResolveRetryAttempt >= 12 &&
|
|
4384
|
+
_releasedPageScrollStates[self.currentPageKey] != nil) {
|
|
4385
|
+
for (const auto &mutation : transaction.getMutations()) {
|
|
4386
|
+
if (mutation.type == ShadowViewMutation::Insert && mutation.parentTag > 0 &&
|
|
4387
|
+
[page viewWithTag:mutation.parentTag] != nil) {
|
|
4388
|
+
// A new current-page insertion starts a bounded recovery round after
|
|
4389
|
+
// the previous replacement search has scheduled its final retry.
|
|
4390
|
+
_scrollResolveRetryToken += 1;
|
|
4391
|
+
_scrollResolveRetryScheduled = NO;
|
|
4392
|
+
_scrollResolveRetryAttempt = 0;
|
|
4393
|
+
break;
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
|
|
4398
|
+
// Record recovery during transitions; ownership still waits for settlement.
|
|
2731
4399
|
if (_transitioning || _isPagerDragging) return;
|
|
2732
4400
|
|
|
2733
4401
|
// OneKey patch: a release must recover even when the changed parent is above
|
|
@@ -2736,7 +4404,6 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2736
4404
|
[self attachScrollObserverForCurrentPage];
|
|
2737
4405
|
return;
|
|
2738
4406
|
}
|
|
2739
|
-
UIView *page = _pageControllers[_currentIndex].view;
|
|
2740
4407
|
BOOL headerIsAttached = [_sharedHeaderHostView isDescendantOfView:self];
|
|
2741
4408
|
BOOL currentListIsAttached = _observedScrollView != nil &&
|
|
2742
4409
|
[_observedScrollView isDescendantOfView:page] && headerIsAttached;
|
|
@@ -2827,6 +4494,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2827
4494
|
}
|
|
2828
4495
|
_needsSlotRebuild = NO;
|
|
2829
4496
|
_deferTopEdgeSlotRebuild = NO;
|
|
4497
|
+
[self cancelPendingNativePagerScroll];
|
|
2830
4498
|
[self restoreScrollEdgeContentMasks];
|
|
2831
4499
|
[self detachScrollObserver];
|
|
2832
4500
|
[self restoreSharedHeadersToContainer];
|
|
@@ -2899,28 +4567,40 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2899
4567
|
animated:NO
|
|
2900
4568
|
completion:nil];
|
|
2901
4569
|
}
|
|
2902
|
-
[
|
|
4570
|
+
[self updateNativeTabProgress:_currentIndex];
|
|
2903
4571
|
}
|
|
2904
4572
|
if (_stickyHeaderView != nil) [_sharedHeaderHostView bringSubviewToFront:_stickyHeaderView];
|
|
2905
4573
|
if (!_nativeTabBarView.hidden) [_sharedHeaderHostView bringSubviewToFront:_nativeTabBarView];
|
|
2906
4574
|
if (!_nativeSubHeaderView.hidden) [_sharedHeaderHostView bringSubviewToFront:_nativeSubHeaderView];
|
|
4575
|
+
[self bringReservedStickyControlToFront];
|
|
2907
4576
|
[_containerView bringSubviewToFront:_sharedHeaderHostView];
|
|
2908
4577
|
if (_stickyHeaderIsPinned) {
|
|
2909
4578
|
[_pinnedStickyHostView.superview bringSubviewToFront:_pinnedStickyHostView];
|
|
2910
4579
|
}
|
|
2911
4580
|
if (self.hasFixedTopOverlay) [_containerView bringSubviewToFront:_topOverlayHostView];
|
|
2912
4581
|
[self setNeedsLayout];
|
|
2913
|
-
|
|
2914
|
-
if (!self->_isBeingRecycled) {
|
|
2915
|
-
[self prepareAdjacentPageInsets];
|
|
2916
|
-
[self attachScrollObserverForCurrentPage];
|
|
2917
|
-
}
|
|
2918
|
-
});
|
|
4582
|
+
[self scheduleCoalescedScrollReconcile];
|
|
2919
4583
|
}
|
|
2920
4584
|
|
|
2921
4585
|
- (void)layoutSubviews
|
|
2922
4586
|
{
|
|
2923
4587
|
[super layoutSubviews];
|
|
4588
|
+
if (_tabProgressDisplayLink != nil && fabs(CGRectGetWidth(self.bounds) - _tabProgressWidth) >= 0.5) {
|
|
4589
|
+
[self stopProgrammaticTabProgress];
|
|
4590
|
+
}
|
|
4591
|
+
void (^resizedPagerCompletion)(BOOL) = nil;
|
|
4592
|
+
NSInteger resizedPagerDestination = -1;
|
|
4593
|
+
NSUInteger resizedPagerGeneration = 0;
|
|
4594
|
+
NSUInteger resizedPagerTransition = 0;
|
|
4595
|
+
if (_directNativePagerEnabled && _pendingNativePagerScrollCompletion != nil &&
|
|
4596
|
+
CGRectGetWidth(_pagerScrollView.bounds) != CGRectGetWidth(self.bounds)) {
|
|
4597
|
+
resizedPagerCompletion = [_pendingNativePagerScrollCompletion copy];
|
|
4598
|
+
resizedPagerDestination = _destinationIndex;
|
|
4599
|
+
resizedPagerGeneration = _pendingNativePagerScrollGeneration;
|
|
4600
|
+
resizedPagerTransition = _pendingNativePagerScrollTransition;
|
|
4601
|
+
// Clear the old target before frame changes can deliver an animation end.
|
|
4602
|
+
[self cancelPendingNativePagerScroll];
|
|
4603
|
+
}
|
|
2924
4604
|
[self syncScrollEdgeAppearance];
|
|
2925
4605
|
_containerView.frame = self.bounds;
|
|
2926
4606
|
[self registerExternalOuterPager];
|
|
@@ -2950,7 +4630,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2950
4630
|
animated:NO
|
|
2951
4631
|
completion:nil];
|
|
2952
4632
|
}
|
|
2953
|
-
[
|
|
4633
|
+
[self updateNativeTabProgress:_currentIndex];
|
|
2954
4634
|
}
|
|
2955
4635
|
// UIKit frame assignment is undefined while a view has a non-identity transform.
|
|
2956
4636
|
// Restore transforms before settling page and shared-header frames.
|
|
@@ -2991,16 +4671,24 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
2991
4671
|
[self updateTopScrollEdgeForScrollView:_observedScrollView];
|
|
2992
4672
|
[self updateScrollEdgeContentMasks];
|
|
2993
4673
|
[self updateHeaderSettledStateForceBusy:NO];
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
4674
|
+
[self logHomeVisualGeometry:@"layout" scrollView:_observedScrollView];
|
|
4675
|
+
[self scheduleCoalescedScrollReconcile];
|
|
4676
|
+
if (resizedPagerCompletion != nil && _directNativePagerEnabled &&
|
|
4677
|
+
!_isBeingRecycled && !_isPagerDragging && _generation == resizedPagerGeneration &&
|
|
4678
|
+
_transitionId == resizedPagerTransition && resizedPagerDestination >= 0 &&
|
|
4679
|
+
resizedPagerDestination < _pageControllers.count) {
|
|
4680
|
+
[_pagerScrollView setContentOffset:CGPointMake(
|
|
4681
|
+
[self directPagerOffsetForIndex:resizedPagerDestination], 0
|
|
4682
|
+
) animated:NO];
|
|
4683
|
+
resizedPagerCompletion(YES);
|
|
4684
|
+
}
|
|
4685
|
+
[self syncNativeToolbarState];
|
|
3000
4686
|
}
|
|
3001
4687
|
|
|
3002
4688
|
- (void)prepareForRecycle
|
|
3003
4689
|
{
|
|
4690
|
+
[self cancelNativeToolbarSettlement];
|
|
4691
|
+
[self cancelPendingNativePagerScroll];
|
|
3004
4692
|
[_externalOuterPager removeNestedOverlayObserver:self];
|
|
3005
4693
|
_externalOuterPager = nil;
|
|
3006
4694
|
[self cancelTopInsetReboundCheck];
|
|
@@ -3009,11 +4697,15 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3009
4697
|
[self cancelHeaderSettledCheck];
|
|
3010
4698
|
[self publishHeaderSettledAtTop:NO identityChanged:NO];
|
|
3011
4699
|
_isBeingRecycled = YES;
|
|
4700
|
+
_toolbarTransitionPending = NO;
|
|
4701
|
+
[_nativeTabBarView updateToolbarPagerIndex:-1 busy:YES];
|
|
3012
4702
|
_pendingTopOverlayAppearanceCommit = NO;
|
|
3013
4703
|
[self syncScrollEdgeAppearance];
|
|
3014
4704
|
_generation++;
|
|
3015
4705
|
[_mountingRemovedScrollViews removeAllObjects];
|
|
3016
4706
|
_needsScrollObserverReattachAfterMount = NO;
|
|
4707
|
+
_awaitingScrollOwnerForCurrentPage = NO;
|
|
4708
|
+
_scrollReconcileScheduled = NO;
|
|
3017
4709
|
[_releasedPageScrollStates removeAllObjects];
|
|
3018
4710
|
[self detachSharedHeaderPressCancellationGesture];
|
|
3019
4711
|
[self detachScrollObserver];
|
|
@@ -3102,6 +4794,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3102
4794
|
_pendingInitialPage = 0;
|
|
3103
4795
|
_headerHeight = 0;
|
|
3104
4796
|
_stickyHeaderHeight = 0;
|
|
4797
|
+
_stickyHeaderHeights = nil;
|
|
3105
4798
|
_topOverlayHeight = 0;
|
|
3106
4799
|
_externalTopOverlayTag = 0;
|
|
3107
4800
|
_externalTopOverlayView = nil;
|
|
@@ -3110,7 +4803,12 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3110
4803
|
_externalOuterTransitioning = NO;
|
|
3111
4804
|
_topScrollEdgeEnabled = NO;
|
|
3112
4805
|
_topScrollEdgeEffect = RNCCollapsiblePagerViewTopScrollEdgeEffect::None;
|
|
4806
|
+
_homeVisualStartMono = 0;
|
|
4807
|
+
_homeVisualLastScrollLog = 0;
|
|
4808
|
+
_homeVisualLastLayoutLog = 0;
|
|
4809
|
+
_homeVisualLastGeometrySignature = nil;
|
|
3113
4810
|
_nativeTabBarHeight = 44;
|
|
4811
|
+
_nativeTabBarTrailingReservedWidth = 0;
|
|
3114
4812
|
_nativeSubHeaderHeight = 74;
|
|
3115
4813
|
_headerOffset = 0;
|
|
3116
4814
|
_currentLogicalOffset = 0;
|
|
@@ -3139,7 +4837,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3139
4837
|
_needsPropsReapply = YES;
|
|
3140
4838
|
_layoutDirection = @"ltr";
|
|
3141
4839
|
[_nativeTabBarView updateItemsJSON:@"[]"];
|
|
3142
|
-
[_nativeTabBarView
|
|
4840
|
+
[_nativeTabBarView updateConfigJSON:@"{}"];
|
|
4841
|
+
[self updateNativeTabProgress:0];
|
|
3143
4842
|
[_nativeSubHeaderView updateConfigJSON:@"{}"];
|
|
3144
4843
|
_isBeingRecycled = NO;
|
|
3145
4844
|
}
|
|
@@ -3192,6 +4891,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3192
4891
|
_layoutDirection = RCTNSStringFromString(toString(newViewProps.layoutDirection));
|
|
3193
4892
|
[_nativeTabBarView setLeftToRight:self.isLtrLayout];
|
|
3194
4893
|
[_nativeSubHeaderView setLeftToRight:self.isLtrLayout];
|
|
4894
|
+
[self setNeedsLayout];
|
|
4895
|
+
}
|
|
4896
|
+
if (_needsPropsReapply ||
|
|
4897
|
+
oldViewProps.nativeTabBarTrailingReservedWidth != newViewProps.nativeTabBarTrailingReservedWidth) {
|
|
4898
|
+
double reserved = newViewProps.nativeTabBarTrailingReservedWidth;
|
|
4899
|
+
_nativeTabBarTrailingReservedWidth = std::isfinite(reserved) && reserved >= 0 ? reserved : 0;
|
|
4900
|
+
[self setNeedsLayout];
|
|
3195
4901
|
}
|
|
3196
4902
|
BOOL insetsChanged = NO;
|
|
3197
4903
|
if (_needsPropsReapply || oldViewProps.headerHeight != newViewProps.headerHeight) {
|
|
@@ -3203,6 +4909,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3203
4909
|
_stickyHeaderHeight = MAX(0, newViewProps.stickyHeaderHeight);
|
|
3204
4910
|
insetsChanged = YES;
|
|
3205
4911
|
}
|
|
4912
|
+
if (_needsPropsReapply || oldViewProps.stickyHeaderHeights != newViewProps.stickyHeaderHeights) {
|
|
4913
|
+
NSString *json = RCTNSStringFromString(newViewProps.stickyHeaderHeights);
|
|
4914
|
+
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
|
4915
|
+
id parsed = data.length == 0 ? nil : [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
4916
|
+
_stickyHeaderHeights = [parsed isKindOfClass:NSArray.class] ? parsed : nil;
|
|
4917
|
+
insetsChanged = YES;
|
|
4918
|
+
}
|
|
3206
4919
|
if (_needsPropsReapply || oldViewProps.topScrollEdgeEffect != newViewProps.topScrollEdgeEffect) {
|
|
3207
4920
|
BOOL enabled = newViewProps.topScrollEdgeEffect != RNCCollapsiblePagerViewTopScrollEdgeEffect::None;
|
|
3208
4921
|
BOOL enabledChanged = _topScrollEdgeEnabled != enabled;
|
|
@@ -3239,6 +4952,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3239
4952
|
}
|
|
3240
4953
|
if (_needsPropsReapply ||
|
|
3241
4954
|
oldViewProps.externalTopOverlayTag != newViewProps.externalTopOverlayTag) {
|
|
4955
|
+
if (_topOverlayView == nil && _externalTopOverlayTag > 0 &&
|
|
4956
|
+
_externalTopOverlayTag != newViewProps.externalTopOverlayTag) {
|
|
4957
|
+
[self clearProgrammaticScrollEdges];
|
|
4958
|
+
}
|
|
3242
4959
|
_externalTopOverlayTag = newViewProps.externalTopOverlayTag;
|
|
3243
4960
|
[self registerExternalOuterPager];
|
|
3244
4961
|
insetsChanged = [self resolveExternalTopOverlay] || insetsChanged;
|
|
@@ -3257,6 +4974,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3257
4974
|
_retainedPages = RCTNSStringFromString(newViewProps.retainedPages);
|
|
3258
4975
|
[self setNeedsLayout];
|
|
3259
4976
|
}
|
|
4977
|
+
if (_needsPropsReapply || oldViewProps.nativeTabBarConfig != newViewProps.nativeTabBarConfig) {
|
|
4978
|
+
[_nativeTabBarView updateConfigJSON:RCTNSStringFromString(newViewProps.nativeTabBarConfig)];
|
|
4979
|
+
}
|
|
3260
4980
|
if (_needsPropsReapply || oldViewProps.nativeTabBarItems != newViewProps.nativeTabBarItems) {
|
|
3261
4981
|
NSString *itemsJSON = RCTNSStringFromString(newViewProps.nativeTabBarItems);
|
|
3262
4982
|
[_nativeTabBarView updateItemsJSON:itemsJSON];
|
|
@@ -3272,7 +4992,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3272
4992
|
}
|
|
3273
4993
|
if (_needsPropsReapply ||
|
|
3274
4994
|
oldViewProps.nativeTabBarHeight != newViewProps.nativeTabBarHeight ||
|
|
4995
|
+
oldViewProps.nativeTabBarVariant != newViewProps.nativeTabBarVariant ||
|
|
3275
4996
|
oldViewProps.nativeTabBarContentPaddingHorizontal != newViewProps.nativeTabBarContentPaddingHorizontal ||
|
|
4997
|
+
oldViewProps.nativeTabBarContentPaddingVertical != newViewProps.nativeTabBarContentPaddingVertical ||
|
|
3276
4998
|
oldViewProps.nativeTabBarItemSpacing != newViewProps.nativeTabBarItemSpacing ||
|
|
3277
4999
|
oldViewProps.nativeTabBarFontSize != newViewProps.nativeTabBarFontSize ||
|
|
3278
5000
|
oldViewProps.nativeTabBarFontFamily != newViewProps.nativeTabBarFontFamily ||
|
|
@@ -3289,7 +5011,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3289
5011
|
NSString *fontFamily = RCTNSStringFromString(newViewProps.nativeTabBarFontFamily);
|
|
3290
5012
|
[_nativeTabBarView
|
|
3291
5013
|
updateStyleWithHeight:_nativeTabBarHeight
|
|
5014
|
+
variant:RCTNSStringFromString(newViewProps.nativeTabBarVariant)
|
|
3292
5015
|
contentPaddingHorizontal:MAX(0, newViewProps.nativeTabBarContentPaddingHorizontal)
|
|
5016
|
+
contentPaddingVertical:MAX(0, newViewProps.nativeTabBarContentPaddingVertical)
|
|
3293
5017
|
itemSpacing:MAX(0, newViewProps.nativeTabBarItemSpacing)
|
|
3294
5018
|
fontSize:newViewProps.nativeTabBarFontSize > 0 ? newViewProps.nativeTabBarFontSize : 16
|
|
3295
5019
|
fontFamily:fontFamily
|
|
@@ -3314,14 +5038,17 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3314
5038
|
if (insetsChanged) {
|
|
3315
5039
|
[self reapplyInsetsToObservedScrollView];
|
|
3316
5040
|
[self setNeedsLayout];
|
|
5041
|
+
[self logHomeVisualGeometry:@"props-inset" scrollView:_observedScrollView];
|
|
3317
5042
|
}
|
|
3318
5043
|
_applyingTopOverlayInsetChange = NO;
|
|
5044
|
+
[self syncNativeToolbarState];
|
|
3319
5045
|
if (!_nativeTabBarView.hidden) {
|
|
3320
5046
|
[_nativeTabBarView.superview bringSubviewToFront:_nativeTabBarView];
|
|
3321
5047
|
}
|
|
3322
5048
|
if (!_nativeSubHeaderView.hidden) {
|
|
3323
5049
|
[_nativeSubHeaderView.superview bringSubviewToFront:_nativeSubHeaderView];
|
|
3324
5050
|
}
|
|
5051
|
+
[self bringReservedStickyControlToFront];
|
|
3325
5052
|
[_sharedHeaderHostView.superview bringSubviewToFront:_sharedHeaderHostView];
|
|
3326
5053
|
if (_stickyHeaderIsPinned) {
|
|
3327
5054
|
[_pinnedStickyHostView.superview bringSubviewToFront:_pinnedStickyHostView];
|
|
@@ -3349,12 +5076,107 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3349
5076
|
|
|
3350
5077
|
- (UIScrollView *)verticalScrollViewForPageAtIndex:(NSInteger)pageIndex
|
|
3351
5078
|
{
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
5079
|
+
return [self resolveScrollCandidateForPageAtIndex:pageIndex].scrollView;
|
|
5080
|
+
}
|
|
5081
|
+
|
|
5082
|
+
- (RNCScrollCandidateResolution)resolveScrollCandidateForPageAtIndex:(NSInteger)pageIndex
|
|
5083
|
+
{
|
|
5084
|
+
if (pageIndex < 0 || pageIndex >= _pageControllers.count) return {};
|
|
5085
|
+
return [self resolveScrollCandidateInView:_pageControllers[pageIndex].view];
|
|
5086
|
+
}
|
|
5087
|
+
|
|
5088
|
+
// Single-pass tiered resolution replaces three separate subtree walks while
|
|
5089
|
+
// distinguishing genuinely static pages from pages with unready scroll hosts.
|
|
5090
|
+
- (RNCScrollCandidateResolution)resolveScrollCandidateInView:(UIView *)view
|
|
5091
|
+
{
|
|
5092
|
+
RNCScrollCandidateResolution resolution;
|
|
5093
|
+
if (view == nil || view == _sharedHeaderHostView) return resolution;
|
|
5094
|
+
if (view != self &&
|
|
5095
|
+
[view isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
|
|
5096
|
+
UIScrollView *nested = [(RNCCollapsiblePagerViewComponentView *)view
|
|
5097
|
+
currentVerticalScrollViewForParentPager];
|
|
5098
|
+
if (nested != nil) {
|
|
5099
|
+
resolution.scrollView = nested;
|
|
5100
|
+
resolution.tier = RNCScrollCandidateTierExplicitScroller;
|
|
5101
|
+
} else {
|
|
5102
|
+
resolution.hasUnreadyScrollHost = YES;
|
|
5103
|
+
}
|
|
5104
|
+
return resolution;
|
|
5105
|
+
}
|
|
5106
|
+
|
|
5107
|
+
Class nativeListClass = NSClassFromString(@"HybridNativeListComponent");
|
|
5108
|
+
if (nativeListClass != Nil && [view isKindOfClass:nativeListClass]) {
|
|
5109
|
+
resolution.hasUnreadyScrollHost = YES;
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
if ([view isKindOfClass:RNCNativeScrollerComponentView.class]) {
|
|
5113
|
+
UIScrollView *scrollView = ((RNCNativeScrollerComponentView *)view).scrollView;
|
|
5114
|
+
if (![_mountingRemovedScrollViews containsObject:scrollView]) {
|
|
5115
|
+
resolution.scrollView = scrollView;
|
|
5116
|
+
resolution.tier = RNCScrollCandidateTierExplicitScroller;
|
|
5117
|
+
return resolution;
|
|
5118
|
+
}
|
|
5119
|
+
} else if ([view isKindOfClass:RCTScrollViewComponentView.class]) {
|
|
5120
|
+
RCTScrollViewComponentView *componentView = (RCTScrollViewComponentView *)view;
|
|
5121
|
+
UIScrollView *scrollView = componentView.scrollView;
|
|
5122
|
+
if (![_mountingRemovedScrollViews containsObject:scrollView]) {
|
|
5123
|
+
if ([componentView.nativeId hasPrefix:RNCCollapsiblePagerNativeScrollerIDPrefix]) {
|
|
5124
|
+
resolution.scrollView = scrollView;
|
|
5125
|
+
resolution.tier = RNCScrollCandidateTierExplicitScroller;
|
|
5126
|
+
return resolution;
|
|
5127
|
+
}
|
|
5128
|
+
if (!scrollView.alwaysBounceHorizontal) {
|
|
5129
|
+
resolution.scrollView = scrollView;
|
|
5130
|
+
resolution.tier = RNCScrollCandidateTierFabricScrollView;
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
} else if ([view isKindOfClass:UICollectionView.class]) {
|
|
5134
|
+
UICollectionView *collectionView = (UICollectionView *)view;
|
|
5135
|
+
if (![_mountingRemovedScrollViews containsObject:collectionView]) {
|
|
5136
|
+
UICollectionViewLayout *layout = collectionView.collectionViewLayout;
|
|
5137
|
+
BOOL isVerticalLayout = ![layout isKindOfClass:UICollectionViewFlowLayout.class] ||
|
|
5138
|
+
((UICollectionViewFlowLayout *)layout).scrollDirection == UICollectionViewScrollDirectionVertical;
|
|
5139
|
+
if (isVerticalLayout) {
|
|
5140
|
+
BOOL hasNativeListHost = RNCNativeListComponentForScrollView(collectionView) != nil;
|
|
5141
|
+
BOOL isMountedNativeList = hasNativeListHost && RNCIsMountedNativeListScrollView(collectionView);
|
|
5142
|
+
BOOL hasUsableBounds = CGRectGetWidth(collectionView.bounds) > 0 &&
|
|
5143
|
+
CGRectGetHeight(collectionView.bounds) > 0;
|
|
5144
|
+
if (hasNativeListHost && !isMountedNativeList) {
|
|
5145
|
+
resolution.hasUnreadyScrollHost = YES;
|
|
5146
|
+
} else if (!hasUsableBounds) {
|
|
5147
|
+
resolution.hasUnreadyScrollHost = YES;
|
|
5148
|
+
} else {
|
|
5149
|
+
resolution.scrollView = collectionView;
|
|
5150
|
+
resolution.tier = isMountedNativeList
|
|
5151
|
+
? RNCScrollCandidateTierVerifiedNativeList
|
|
5152
|
+
: RNCScrollCandidateTierGenericFallback;
|
|
5153
|
+
// React slots inside a verified list may own independent scroll views.
|
|
5154
|
+
if (isMountedNativeList) return resolution;
|
|
5155
|
+
}
|
|
5156
|
+
}
|
|
5157
|
+
}
|
|
5158
|
+
} else if ([view isKindOfClass:UIScrollView.class]) {
|
|
5159
|
+
UIScrollView *scrollView = (UIScrollView *)view;
|
|
5160
|
+
if (![_mountingRemovedScrollViews containsObject:scrollView] &&
|
|
5161
|
+
!scrollView.alwaysBounceHorizontal &&
|
|
5162
|
+
scrollView.contentSize.width <= scrollView.bounds.size.width + 1) {
|
|
5163
|
+
resolution.scrollView = scrollView;
|
|
5164
|
+
resolution.tier = RNCScrollCandidateTierGenericFallback;
|
|
5165
|
+
}
|
|
5166
|
+
}
|
|
5167
|
+
|
|
5168
|
+
for (UIView *subview in view.subviews) {
|
|
5169
|
+
RNCScrollCandidateResolution child = [self resolveScrollCandidateInView:subview];
|
|
5170
|
+
resolution.hasUnreadyScrollHost |= child.hasUnreadyScrollHost;
|
|
5171
|
+
if (child.tier > resolution.tier) {
|
|
5172
|
+
resolution.scrollView = child.scrollView;
|
|
5173
|
+
resolution.tier = child.tier;
|
|
5174
|
+
if (resolution.tier == RNCScrollCandidateTierExplicitScroller) {
|
|
5175
|
+
return resolution;
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
return resolution;
|
|
3358
5180
|
}
|
|
3359
5181
|
|
|
3360
5182
|
- (UIScrollView *)findExplicitNativeScrollerInView:(UIView *)view
|
|
@@ -3450,6 +5272,19 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3450
5272
|
return nil;
|
|
3451
5273
|
}
|
|
3452
5274
|
|
|
5275
|
+
- (void)scheduleCoalescedScrollReconcile
|
|
5276
|
+
{
|
|
5277
|
+
if (_isBeingRecycled || _scrollReconcileScheduled) return;
|
|
5278
|
+
_scrollReconcileScheduled = YES;
|
|
5279
|
+
NSUInteger generation = _generation;
|
|
5280
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
5281
|
+
self->_scrollReconcileScheduled = NO;
|
|
5282
|
+
if (self->_isBeingRecycled || self->_generation != generation) return;
|
|
5283
|
+
[self prepareAdjacentPageInsets];
|
|
5284
|
+
[self attachScrollObserverForCurrentPage];
|
|
5285
|
+
});
|
|
5286
|
+
}
|
|
5287
|
+
|
|
3453
5288
|
- (void)scheduleScrollObserverRetryForCurrentPage
|
|
3454
5289
|
{
|
|
3455
5290
|
if (_scrollResolveRetryScheduled || _scrollResolveRetryAttempt >= 12 ||
|
|
@@ -3502,29 +5337,35 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3502
5337
|
_pendingFallbackScrollView = nil;
|
|
3503
5338
|
_pendingFallbackScrollViewDetectedAt = 0;
|
|
3504
5339
|
}
|
|
3505
|
-
|
|
5340
|
+
RNCScrollCandidateResolution resolution = [self resolveScrollCandidateForPageAtIndex:_currentIndex];
|
|
5341
|
+
UIScrollView *candidate = resolution.scrollView;
|
|
3506
5342
|
if (_nativeSmoothHeaderScrollEnabled && _currentIndex >= 0 && _currentIndex < _pageControllers.count) {
|
|
3507
5343
|
RNCGuardNestedHorizontalPans(_pageControllers[_currentIndex].view, _verticalPagerGesture);
|
|
3508
5344
|
}
|
|
3509
5345
|
if (candidate == nil) {
|
|
3510
5346
|
[self detachScrollObserver];
|
|
3511
5347
|
[self restoreSharedHeadersToContainer];
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
5348
|
+
_needsScrollObserverReattachAfterMount = NO;
|
|
5349
|
+
_pendingFallbackScrollView = nil;
|
|
5350
|
+
_pendingFallbackScrollViewDetectedAt = 0;
|
|
5351
|
+
_awaitingScrollOwnerForCurrentPage = YES;
|
|
5352
|
+
// Only schedule bounded retry when the page has an unready scroll host in
|
|
5353
|
+
// its subtree or a released scroll owner awaiting replacement. Static pages
|
|
5354
|
+
// without a scroll host do not spin retry timers, and late replacements on
|
|
5355
|
+
// any page also attach deterministically via readiness notifications.
|
|
5356
|
+
BOOL hasReleasedOwnerAwaitingReplacement = _releasedPageScrollStates[self.currentPageKey] != nil;
|
|
5357
|
+
if (resolution.hasUnreadyScrollHost || hasReleasedOwnerAwaitingReplacement) {
|
|
5358
|
+
[self scheduleScrollObserverRetryForCurrentPage];
|
|
5359
|
+
} else {
|
|
3516
5360
|
_scrollResolveRetryToken += 1;
|
|
3517
5361
|
_scrollResolveRetryScheduled = NO;
|
|
3518
5362
|
_scrollResolveRetryAttempt = 0;
|
|
3519
|
-
_pendingFallbackScrollView = nil;
|
|
3520
|
-
_pendingFallbackScrollViewDetectedAt = 0;
|
|
3521
|
-
} else {
|
|
3522
|
-
[self scheduleScrollObserverRetryForCurrentPage];
|
|
3523
5363
|
}
|
|
3524
5364
|
return;
|
|
3525
5365
|
}
|
|
3526
5366
|
if ([candidate isKindOfClass:UICollectionView.class] &&
|
|
3527
5367
|
candidate != _observedScrollView && !RNCIsMountedNativeListScrollView(candidate)) {
|
|
5368
|
+
_awaitingScrollOwnerForCurrentPage = YES;
|
|
3528
5369
|
if (_pendingFallbackScrollView != candidate) {
|
|
3529
5370
|
_pendingFallbackScrollView = candidate;
|
|
3530
5371
|
_pendingFallbackScrollViewDetectedAt = CACurrentMediaTime();
|
|
@@ -3536,6 +5377,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3536
5377
|
return;
|
|
3537
5378
|
}
|
|
3538
5379
|
}
|
|
5380
|
+
_awaitingScrollOwnerForCurrentPage = NO;
|
|
3539
5381
|
_scrollResolveRetryAttempt = 0;
|
|
3540
5382
|
_scrollResolveRetryPageIndex = _currentIndex;
|
|
3541
5383
|
_scrollResolveRetryToken += 1;
|
|
@@ -3894,8 +5736,105 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3894
5736
|
[_managedRefreshControls removeObjectForKey:scrollView];
|
|
3895
5737
|
if (current != nil) [_managedRefreshControls setObject:current forKey:scrollView];
|
|
3896
5738
|
}
|
|
3897
|
-
[RNCRefreshControlOffsetState setOffset:
|
|
5739
|
+
[RNCRefreshControlOffsetState setOffset:_headerHeight + self.currentStickyHeaderHeight
|
|
3898
5740
|
forControl:current owner:self];
|
|
5741
|
+
if (previous != current) [self logHomeVisualGeometry:@"refresh-bind" scrollView:scrollView];
|
|
5742
|
+
}
|
|
5743
|
+
|
|
5744
|
+
- (void)logHomeVisualGeometry:(NSString *)phase scrollView:(UIScrollView *)scrollView
|
|
5745
|
+
{
|
|
5746
|
+
#if DEBUG
|
|
5747
|
+
if (self.window == nil || _isBeingRecycled) return;
|
|
5748
|
+
CFTimeInterval now = CACurrentMediaTime();
|
|
5749
|
+
if (_homeVisualStartMono == 0) _homeVisualStartMono = now;
|
|
5750
|
+
if ([phase isEqualToString:@"pull"] && now - _homeVisualLastScrollLog < 0.2) return;
|
|
5751
|
+
if ([phase isEqualToString:@"pull"]) _homeVisualLastScrollLog = now;
|
|
5752
|
+
UIRefreshControl *control = scrollView.refreshControl;
|
|
5753
|
+
CGRect controlWindow = control != nil
|
|
5754
|
+
? [control convertRect:control.bounds toView:self.window] : CGRectZero;
|
|
5755
|
+
CGRect overlayWindow = [_topOverlayHostView convertRect:_topOverlayHostView.bounds
|
|
5756
|
+
toView:self.window];
|
|
5757
|
+
CGRect stickyWindow = [_stickyHeaderView convertRect:_stickyHeaderView.bounds
|
|
5758
|
+
toView:self.window];
|
|
5759
|
+
CGRect maskWindow = _sharedHeaderMaskView != nil
|
|
5760
|
+
? [_sharedHeaderHostView convertRect:_sharedHeaderMaskView.frame toView:self.window]
|
|
5761
|
+
: CGRectZero;
|
|
5762
|
+
CGFloat pageMaskWindowY = [_containerView convertPoint:
|
|
5763
|
+
CGPointMake(0, _pageMaskBoundary) toView:self.window].y;
|
|
5764
|
+
BOOL layoutPhase = [phase isEqualToString:@"layout"] ||
|
|
5765
|
+
[phase isEqualToString:@"did-mount"];
|
|
5766
|
+
NSString *signature = [NSString stringWithFormat:
|
|
5767
|
+
@"%.1f:%ld:%ld:%.1f:%d:%.1f:%.1f:%.1f:%d:%d",
|
|
5768
|
+
self.effectiveTopOverlayHeight, (long)_headerHeight,
|
|
5769
|
+
(long)self.currentStickyHeaderHeight, scrollView.contentInset.top, control != nil,
|
|
5770
|
+
CGRectGetMinY(maskWindow), CGRectGetHeight(maskWindow), _pageMaskBoundary,
|
|
5771
|
+
_stickyHeaderIsPinned, _topScrollEdgeEnabled];
|
|
5772
|
+
if (layoutPhase && now - _homeVisualStartMono >= 2.0 &&
|
|
5773
|
+
[_homeVisualLastGeometrySignature isEqualToString:signature] &&
|
|
5774
|
+
now - _homeVisualLastLayoutLog < 2.0) return;
|
|
5775
|
+
if (layoutPhase) {
|
|
5776
|
+
_homeVisualLastLayoutLog = now;
|
|
5777
|
+
_homeVisualLastGeometrySignature = signature;
|
|
5778
|
+
}
|
|
5779
|
+
CGFloat visualYEstimate = CGRectGetMinY(controlWindow) +
|
|
5780
|
+
(control != nil ? control.layer.sublayerTransform.m42 : 0);
|
|
5781
|
+
CALayer *firstChild = control.layer.sublayers.firstObject;
|
|
5782
|
+
BOOL childAttached = firstChild != nil && control.window == self.window;
|
|
5783
|
+
CGRect firstChildWindow = childAttached
|
|
5784
|
+
? [firstChild convertRect:firstChild.bounds toLayer:self.window.layer]
|
|
5785
|
+
: CGRectZero;
|
|
5786
|
+
CGFloat overscroll = scrollView != nil
|
|
5787
|
+
? -(scrollView.contentOffset.y + scrollView.contentInset.top) : 0;
|
|
5788
|
+
double epochMs = [NSDate.date timeIntervalSince1970] * 1000;
|
|
5789
|
+
double monoMs = now * 1000;
|
|
5790
|
+
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
5791
|
+
@"[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",
|
|
5792
|
+
epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
|
|
5793
|
+
(long)_currentIndex, self.window != nil, _topScrollEdgeEnabled,
|
|
5794
|
+
self.effectiveTopOverlayHeight, (long)_headerHeight, (long)self.currentStickyHeaderHeight,
|
|
5795
|
+
_headerOffset, scrollView.contentOffset.y, scrollView.contentInset.top,
|
|
5796
|
+
overscroll, control != nil, control.isRefreshing,
|
|
5797
|
+
CGRectGetMinY(controlWindow), CGRectGetHeight(controlWindow),
|
|
5798
|
+
control != nil ? control.layer.sublayerTransform.m42 : 0, visualYEstimate,
|
|
5799
|
+
CGRectGetMinY(overlayWindow), CGRectGetMaxY(overlayWindow),
|
|
5800
|
+
CGRectGetMinY(stickyWindow), CGRectGetMaxY(stickyWindow),
|
|
5801
|
+
CGRectGetMinY(maskWindow), CGRectGetHeight(maskWindow), pageMaskWindowY]);
|
|
5802
|
+
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
5803
|
+
@"[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",
|
|
5804
|
+
epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
|
|
5805
|
+
(long)_currentIndex, control.bounds.origin.y, control.bounds.size.height,
|
|
5806
|
+
control.center.y, control.transform.ty, control.layer.position.y,
|
|
5807
|
+
control.layer.transform.m42, (unsigned long)control.layer.sublayers.count,
|
|
5808
|
+
childAttached, CGRectGetMinY(firstChildWindow), CGRectGetHeight(firstChildWindow)]);
|
|
5809
|
+
if (![phase isEqualToString:@"pull"]) {
|
|
5810
|
+
CALayer *topCover = _topEdgeSeparatorCover;
|
|
5811
|
+
CALayer *stickyCover = _stickyEdgeSeparatorCover;
|
|
5812
|
+
UIColor *color = topCover.backgroundColor != nil
|
|
5813
|
+
? [UIColor colorWithCGColor:topCover.backgroundColor] : nil;
|
|
5814
|
+
CGFloat red = 0, green = 0, blue = 0, alpha = 0;
|
|
5815
|
+
[color getRed:&red green:&green blue:&blue alpha:&alpha];
|
|
5816
|
+
CGRect topCoverWindow = topCover.superlayer != nil
|
|
5817
|
+
? [topCover convertRect:topCover.bounds toLayer:self.window.layer] : CGRectZero;
|
|
5818
|
+
CGRect stickyCoverWindow = stickyCover.superlayer != nil
|
|
5819
|
+
? [stickyCover convertRect:stickyCover.bounds toLayer:self.window.layer] : CGRectZero;
|
|
5820
|
+
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
5821
|
+
@"[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",
|
|
5822
|
+
epochMs, monoMs, phase, (long)self.tag, (unsigned long)_generation,
|
|
5823
|
+
(long)_currentIndex, (long)self.traitCollection.userInterfaceStyle,
|
|
5824
|
+
(long)_topOverlayHostView.overrideUserInterfaceStyle,
|
|
5825
|
+
(long)_topScrollEdgeEffect, _stickyHeaderIsPinned,
|
|
5826
|
+
CGRectGetMinY(overlayWindow), CGRectGetMaxY(overlayWindow),
|
|
5827
|
+
CGRectGetMinY(stickyWindow), CGRectGetMaxY(stickyWindow),
|
|
5828
|
+
_topEdgeInteraction.scrollView == scrollView,
|
|
5829
|
+
_stickyEdgeInteraction.scrollView == scrollView,
|
|
5830
|
+
topCover != nil, topCover.hidden, CGRectGetMinY(topCoverWindow),
|
|
5831
|
+
CGRectGetHeight(topCoverWindow), stickyCover != nil,
|
|
5832
|
+
stickyCover.hidden,
|
|
5833
|
+
CGRectGetMinY(stickyCoverWindow),
|
|
5834
|
+
CGRectGetHeight(stickyCoverWindow), red, green, blue, alpha,
|
|
5835
|
+
self.window.screen.scale]);
|
|
5836
|
+
}
|
|
5837
|
+
#endif
|
|
3899
5838
|
}
|
|
3900
5839
|
|
|
3901
5840
|
- (void)releaseRefreshControlForScrollView:(UIScrollView *)scrollView
|
|
@@ -3959,6 +5898,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
3959
5898
|
// still represents the old list, before Fabric applies its next owner's props.
|
|
3960
5899
|
- (void)restoreScrollViewState:(UIScrollView *)scrollView resetSavedOffset:(BOOL)resetSavedOffset
|
|
3961
5900
|
{
|
|
5901
|
+
[self releaseProgrammaticScrollEdge:scrollView];
|
|
3962
5902
|
[self updateNativeScrollerViewport:scrollView stickyHeight:0];
|
|
3963
5903
|
[self releaseRefreshControlForScrollView:scrollView];
|
|
3964
5904
|
if (scrollView == _observedScrollView) {
|
|
@@ -4086,7 +6026,8 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4086
6026
|
// suppress its later vertical movement while the pager is still pending.
|
|
4087
6027
|
scrollView.directionalLockEnabled = _nativeSmoothHeaderScrollEnabled
|
|
4088
6028
|
? NO : [_originalDirectionalLockEnabled objectForKey:scrollView].boolValue;
|
|
4089
|
-
|
|
6029
|
+
CGFloat stickyHeight = [self stickyHeaderHeightForPageIndex:pageIndex];
|
|
6030
|
+
[self updateNativeScrollerViewport:scrollView stickyHeight:stickyHeight + self.effectiveTopOverlayHeight];
|
|
4090
6031
|
[self updateRefreshControlForScrollView:scrollView];
|
|
4091
6032
|
CGFloat previousTopInset = scrollView.contentInset.top;
|
|
4092
6033
|
CGFloat previousLogicalOffset = scrollView.contentOffset.y + previousTopInset;
|
|
@@ -4097,13 +6038,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4097
6038
|
CGFloat refreshInset = appliedTop != nil && scrollView.refreshControl != nil
|
|
4098
6039
|
? MAX(0, previousTopInset - appliedTop.doubleValue) : 0;
|
|
4099
6040
|
UIEdgeInsets next = original;
|
|
4100
|
-
next.top += self.effectiveTopOverlayHeight + _headerHeight +
|
|
6041
|
+
next.top += self.effectiveTopOverlayHeight + _headerHeight + stickyHeight;
|
|
4101
6042
|
CGFloat pagerTopInset = next.top;
|
|
4102
6043
|
next.top += refreshInset;
|
|
4103
6044
|
[_appliedTopInsets setObject:@(pagerTopInset) forKey:scrollView];
|
|
4104
6045
|
// Short pages still need enough range to collapse the header; long pages
|
|
4105
6046
|
// must end at the last row rather than leave a header-sized blank footer.
|
|
4106
|
-
next.bottom += MAX(0, scrollView.bounds.size.height -
|
|
6047
|
+
next.bottom += MAX(0, scrollView.bounds.size.height - stickyHeight - self.effectiveTopOverlayHeight
|
|
4107
6048
|
- original.top - original.bottom - scrollView.contentSize.height);
|
|
4108
6049
|
if (UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, next) && !restore) {
|
|
4109
6050
|
// UICollectionView may report contentSize during a bounce without changing
|
|
@@ -4189,8 +6130,9 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4189
6130
|
|
|
4190
6131
|
- (void)updateNativeScrollerViewport:(UIScrollView *)scrollView stickyHeight:(CGFloat)height
|
|
4191
6132
|
{
|
|
4192
|
-
|
|
4193
|
-
|
|
6133
|
+
id host = scrollView.superview;
|
|
6134
|
+
if ([host respondsToSelector:@selector(setPagerStickyHeight:forOwner:)]) {
|
|
6135
|
+
[host setPagerStickyHeight:height forOwner:self];
|
|
4194
6136
|
}
|
|
4195
6137
|
}
|
|
4196
6138
|
|
|
@@ -4262,6 +6204,66 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4262
6204
|
}
|
|
4263
6205
|
|
|
4264
6206
|
|
|
6207
|
+
- (void)nativeScrollViewDidBecomeReadyNotification:(NSNotification *)notification
|
|
6208
|
+
{
|
|
6209
|
+
if ([notification.object isKindOfClass:UIScrollView.class]) {
|
|
6210
|
+
[self nativeScrollViewDidBecomeReady:(UIScrollView *)notification.object];
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
|
|
6214
|
+
- (void)nativeScrollViewDidBecomeReady:(UIScrollView *)scrollView
|
|
6215
|
+
{
|
|
6216
|
+
if (_isBeingRecycled || self.window == nil || scrollView == nil ||
|
|
6217
|
+
[_mountingRemovedScrollViews containsObject:scrollView]) return;
|
|
6218
|
+
for (UIView *ancestor = scrollView.superview;
|
|
6219
|
+
ancestor != nil && ancestor != self;
|
|
6220
|
+
ancestor = ancestor.superview) {
|
|
6221
|
+
if ([ancestor isKindOfClass:RNCCollapsiblePagerViewComponentView.class]) {
|
|
6222
|
+
RNCCollapsiblePagerViewComponentView *nestedPager =
|
|
6223
|
+
(RNCCollapsiblePagerViewComponentView *)ancestor;
|
|
6224
|
+
if ([nestedPager currentVerticalScrollViewForParentPager] != scrollView) return;
|
|
6225
|
+
break;
|
|
6226
|
+
}
|
|
6227
|
+
}
|
|
6228
|
+
NSInteger pageIndex = NSNotFound;
|
|
6229
|
+
for (NSInteger index = 0; index < _pageControllers.count; index++) {
|
|
6230
|
+
if ([scrollView isDescendantOfView:_pageControllers[index].view]) {
|
|
6231
|
+
pageIndex = index;
|
|
6232
|
+
break;
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
if (pageIndex == NSNotFound) return;
|
|
6236
|
+
|
|
6237
|
+
NSString *pageKey = [self pageKeyForIndex:pageIndex];
|
|
6238
|
+
BOOL hasReleasedStateForPage = _releasedPageScrollStates[pageKey] != nil;
|
|
6239
|
+
BOOL currentPageNeedsOwner = pageIndex == _currentIndex &&
|
|
6240
|
+
(_awaitingScrollOwnerForCurrentPage || _needsScrollObserverReattachAfterMount ||
|
|
6241
|
+
hasReleasedStateForPage ||
|
|
6242
|
+
(_observedScrollView != nil &&
|
|
6243
|
+
[_observedScrollView isKindOfClass:UICollectionView.class] &&
|
|
6244
|
+
!RNCIsMountedNativeListScrollView(_observedScrollView) &&
|
|
6245
|
+
_observedScrollView != scrollView));
|
|
6246
|
+
|
|
6247
|
+
if (!hasReleasedStateForPage && !currentPageNeedsOwner &&
|
|
6248
|
+
!_needsScrollObserverReattachAfterMount) return;
|
|
6249
|
+
|
|
6250
|
+
if (_nativeSmoothHeaderScrollEnabled) {
|
|
6251
|
+
NSInteger first = MAX(0, _currentIndex - 1);
|
|
6252
|
+
NSInteger last = MIN((NSInteger)_pageControllers.count - 1, _currentIndex + 1);
|
|
6253
|
+
BOOL isOwnedScroller = [scrollView.superview isKindOfClass:RNCNativeScrollerComponentView.class] &&
|
|
6254
|
+
((RNCNativeScrollerComponentView *)scrollView.superview).scrollView == scrollView;
|
|
6255
|
+
if ((pageIndex >= first && pageIndex <= last || pageIndex == _destinationIndex) &&
|
|
6256
|
+
(RNCIsMountedNativeListScrollView(scrollView) || isOwnedScroller) &&
|
|
6257
|
+
[_originalInsets objectForKey:scrollView] == nil) {
|
|
6258
|
+
[self applyInsetsToScrollView:scrollView pageIndex:pageIndex restore:YES];
|
|
6259
|
+
}
|
|
6260
|
+
}
|
|
6261
|
+
|
|
6262
|
+
if (currentPageNeedsOwner && !_transitioning && !_isPagerDragging) {
|
|
6263
|
+
[self attachScrollObserverForCurrentPage];
|
|
6264
|
+
}
|
|
6265
|
+
}
|
|
6266
|
+
|
|
4265
6267
|
- (void)nativeScroller:(RNCNativeScrollerComponentView *)scroller
|
|
4266
6268
|
callerInsetChangedFrom:(UIEdgeInsets)previous to:(UIEdgeInsets)next
|
|
4267
6269
|
{
|
|
@@ -4313,6 +6315,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4313
6315
|
if (context == RNCScrollRefreshControlContext) {
|
|
4314
6316
|
UIScrollView *scrollView = (UIScrollView *)object;
|
|
4315
6317
|
[self updateRefreshControlForScrollView:scrollView];
|
|
6318
|
+
[self logHomeVisualGeometry:@"refresh-control-change" scrollView:scrollView];
|
|
4316
6319
|
if (scrollView == _observedScrollView && !_syntheticPageRestore &&
|
|
4317
6320
|
(!_nativeSmoothHeaderScrollEnabled || (!_transitioning && _transitionPageOffsets == nil))) {
|
|
4318
6321
|
[self updateHeaderForScrollView:scrollView];
|
|
@@ -4320,6 +6323,11 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4320
6323
|
return;
|
|
4321
6324
|
}
|
|
4322
6325
|
if (context == RNCCollapsiblePagerContentOffsetContext && object == _observedScrollView) {
|
|
6326
|
+
if ([keyPath isEqualToString:@"contentOffset"] &&
|
|
6327
|
+
-(((UIScrollView *)object).contentOffset.y +
|
|
6328
|
+
((UIScrollView *)object).contentInset.top) > 5) {
|
|
6329
|
+
[self logHomeVisualGeometry:@"pull" scrollView:(UIScrollView *)object];
|
|
6330
|
+
}
|
|
4323
6331
|
if (_pendingTopInsetReboundScrollView == object &&
|
|
4324
6332
|
([keyPath isEqualToString:@"contentOffset"] || [keyPath isEqualToString:@"contentInset"])) {
|
|
4325
6333
|
if (((UIScrollView *)object).panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
|
|
@@ -4458,6 +6466,18 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4458
6466
|
|
|
4459
6467
|
#pragma mark - Pager navigation
|
|
4460
6468
|
|
|
6469
|
+
- (void)cancelPendingNativePagerScroll
|
|
6470
|
+
{
|
|
6471
|
+
[self stopProgrammaticTabProgress];
|
|
6472
|
+
if (_pendingNativePagerScrollCompletion == nil) return;
|
|
6473
|
+
_pendingNativePagerScrollCompletion = nil;
|
|
6474
|
+
_pendingNativePagerScrollGeneration = 0;
|
|
6475
|
+
_pendingNativePagerScrollTransition = 0;
|
|
6476
|
+
_pendingNativePagerScrollTarget = 0;
|
|
6477
|
+
CGPoint offset = _pagerScrollView.contentOffset;
|
|
6478
|
+
[_pagerScrollView setContentOffset:offset animated:NO];
|
|
6479
|
+
}
|
|
6480
|
+
|
|
4461
6481
|
- (BOOL)isLtrLayout
|
|
4462
6482
|
{
|
|
4463
6483
|
return [_layoutDirection isEqualToString:@"ltr"];
|
|
@@ -4467,6 +6487,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4467
6487
|
{
|
|
4468
6488
|
[self cancelTopInsetReboundCheck];
|
|
4469
6489
|
if (_isBeingRecycled || index < 0 || index >= _pageControllers.count) return;
|
|
6490
|
+
[self cancelNativeToolbarSettlement];
|
|
4470
6491
|
_hasReceivedPageCommand = YES;
|
|
4471
6492
|
_hasAppliedInitialPage = YES;
|
|
4472
6493
|
if (_transitioning || _isPagerDragging) {
|
|
@@ -4488,14 +6509,21 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4488
6509
|
[self attachScrollObserverForCurrentPage];
|
|
4489
6510
|
[self emitPageSelected:index];
|
|
4490
6511
|
[self emitDiagnostics:@"page-selected"];
|
|
6512
|
+
[self syncNativeToolbarState];
|
|
4491
6513
|
return;
|
|
4492
6514
|
}
|
|
4493
6515
|
|
|
6516
|
+
if (_directNativePagerEnabled && animated && index != _currentIndex) {
|
|
6517
|
+
[self adoptCurrentScrollEdgeForProgrammaticTransition:NO];
|
|
6518
|
+
}
|
|
4494
6519
|
[self beginPageStateTransition];
|
|
4495
6520
|
[self preparePageForHorizontalTransitionAtIndex:index];
|
|
4496
6521
|
_destinationIndex = index;
|
|
4497
6522
|
[self liftSharedHeadersForPagerTransition:@"programmatic"];
|
|
4498
6523
|
[self detachScrollObserver];
|
|
6524
|
+
if (_directNativePagerEnabled && animated && index != _currentIndex) {
|
|
6525
|
+
[self beginProgrammaticScrollEdgesToIndex:index allowExternalOverlay:NO];
|
|
6526
|
+
}
|
|
4499
6527
|
BOOL forward = (index > _currentIndex && self.isLtrLayout) ||
|
|
4500
6528
|
(index < _currentIndex && !self.isLtrLayout);
|
|
4501
6529
|
UIPageViewControllerNavigationDirection direction = forward
|
|
@@ -4510,13 +6538,14 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4510
6538
|
CGFloat targetOffset = [self directPagerOffsetForIndex:index];
|
|
4511
6539
|
void (^animations)(void) = ^{
|
|
4512
6540
|
[self->_pagerScrollView setContentOffset:CGPointMake(targetOffset, 0)];
|
|
4513
|
-
[self->_nativeTabBarView setProgress:index];
|
|
6541
|
+
if (self->_tabProgressDisplayLink == nil) [self->_nativeTabBarView setProgress:index];
|
|
4514
6542
|
[self updatePageStateTransitionProgress:index];
|
|
4515
6543
|
};
|
|
4516
6544
|
void (^completion)(BOOL) = ^(BOOL finished) {
|
|
4517
6545
|
__strong __typeof__(weakSelf) self = weakSelf;
|
|
4518
6546
|
if (self == nil || self->_generation != capturedGeneration ||
|
|
4519
6547
|
self->_transitionId != capturedTransition || self->_isBeingRecycled) return;
|
|
6548
|
+
[self stopProgrammaticTabProgress];
|
|
4520
6549
|
self->_pagerScrollView.scrollEnabled = self->_scrollEnabled;
|
|
4521
6550
|
if (finished) {
|
|
4522
6551
|
[self detachScrollObserver];
|
|
@@ -4535,13 +6564,42 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4535
6564
|
};
|
|
4536
6565
|
|
|
4537
6566
|
if (animated && index != _currentIndex) {
|
|
6567
|
+
BOOL useNativeAnimatedScroll = NO;
|
|
6568
|
+
if (@available(iOS 27.0, *)) {
|
|
6569
|
+
useNativeAnimatedScroll = _nativeSmoothHeaderScrollEnabled && _topScrollEdgeEnabled &&
|
|
6570
|
+
_topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard &&
|
|
6571
|
+
_topOverlayView != nil && _externalTopOverlayTag <= 0 && self.window != nil;
|
|
6572
|
+
}
|
|
6573
|
+
if (useNativeAnimatedScroll) {
|
|
6574
|
+
// Keep the traversed pages owned until UIKit finishes scrolling.
|
|
6575
|
+
NSInteger first = MIN(_currentIndex, index);
|
|
6576
|
+
NSInteger last = MAX(_currentIndex, index);
|
|
6577
|
+
_programmaticPageMaskIndexes = [NSIndexSet indexSetWithIndexesInRange:
|
|
6578
|
+
NSMakeRange(first, last - first + 1)];
|
|
6579
|
+
[self updateScrollEdgeContentMasks];
|
|
6580
|
+
}
|
|
4538
6581
|
_pagerScrollView.scrollEnabled = NO;
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
6582
|
+
if (useNativeAnimatedScroll) {
|
|
6583
|
+
if (fabs(_pagerScrollView.contentOffset.x - targetOffset) <= 0.5) {
|
|
6584
|
+
[self updateNativeTabProgress:index];
|
|
6585
|
+
[self updatePageStateTransitionProgress:index];
|
|
6586
|
+
completion(YES);
|
|
6587
|
+
} else {
|
|
6588
|
+
_pendingNativePagerScrollCompletion = [completion copy];
|
|
6589
|
+
_pendingNativePagerScrollGeneration = capturedGeneration;
|
|
6590
|
+
_pendingNativePagerScrollTransition = capturedTransition;
|
|
6591
|
+
_pendingNativePagerScrollTarget = targetOffset;
|
|
6592
|
+
[_pagerScrollView setContentOffset:CGPointMake(targetOffset, 0) animated:YES];
|
|
6593
|
+
}
|
|
6594
|
+
} else {
|
|
6595
|
+
if ([_nativeTabBarView usesControlledTextProgress]) [self startProgrammaticTabProgress];
|
|
6596
|
+
[UIView animateWithDuration:0.28
|
|
6597
|
+
delay:0
|
|
6598
|
+
options:UIViewAnimationOptionCurveEaseInOut |
|
|
6599
|
+
UIViewAnimationOptionAllowUserInteraction
|
|
6600
|
+
animations:animations
|
|
6601
|
+
completion:completion];
|
|
6602
|
+
}
|
|
4545
6603
|
} else {
|
|
4546
6604
|
[UIView performWithoutAnimation:animations];
|
|
4547
6605
|
completion(YES);
|
|
@@ -4583,7 +6641,10 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4583
6641
|
if (self->_generation != generation || self->_transitionId != transition ||
|
|
4584
6642
|
self->_isBeingRecycled) return;
|
|
4585
6643
|
[self finishPageStateTransition];
|
|
6644
|
+
self->_programmaticPageMaskIndexes = nil;
|
|
4586
6645
|
self->_transitioning = NO;
|
|
6646
|
+
BOOL hadProgrammaticScrollEdges = self->_programmaticScrollEdgeOwners.count > 0;
|
|
6647
|
+
[self finishProgrammaticScrollEdges];
|
|
4587
6648
|
if (self->_hasPendingDirectNativePagerChange) {
|
|
4588
6649
|
BOOL enabled = self->_pendingDirectNativePagerEnabled;
|
|
4589
6650
|
self->_hasPendingDirectNativePagerChange = NO;
|
|
@@ -4592,11 +6653,16 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4592
6653
|
[self rebuildSlots];
|
|
4593
6654
|
}
|
|
4594
6655
|
if (!self->_hasAppliedInitialPage) [self setNeedsLayout];
|
|
6656
|
+
if (hadProgrammaticScrollEdges && !self->_transitioning && !self->_needsSlotRebuild) {
|
|
6657
|
+
[self attachScrollObserverForCurrentPage];
|
|
6658
|
+
}
|
|
4595
6659
|
[self drainPendingGoTo];
|
|
4596
|
-
if (!self->_transitioning && !self->
|
|
6660
|
+
if (!self->_transitioning && !self->_isPagerDragging && self->_pendingGoToIndex < 0) self->_toolbarTransitionPending = NO;
|
|
6661
|
+
if (!hadProgrammaticScrollEdges && !self->_transitioning && !self->_needsSlotRebuild) {
|
|
4597
6662
|
[self attachScrollObserverForCurrentPage];
|
|
4598
6663
|
}
|
|
4599
6664
|
[self updateScrollEdgeContentMasks];
|
|
6665
|
+
[self syncNativeToolbarState];
|
|
4600
6666
|
});
|
|
4601
6667
|
}
|
|
4602
6668
|
|
|
@@ -4647,21 +6713,30 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4647
6713
|
|
|
4648
6714
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
|
4649
6715
|
{
|
|
6716
|
+
if (scrollView == _pagerScrollView) [self cancelPendingNativePagerScroll];
|
|
6717
|
+
++_transitionId;
|
|
4650
6718
|
[self updateHeaderSettledStateForceBusy:YES];
|
|
4651
6719
|
if (_nativeSmoothHeaderScrollEnabled && scrollView == _pagerScrollView) {
|
|
4652
6720
|
[_contentPressCancellationGesture cancelPressForPan:scrollView.panGestureRecognizer];
|
|
4653
6721
|
}
|
|
6722
|
+
if (_directNativePagerEnabled) [self adoptCurrentScrollEdgeForProgrammaticTransition:YES];
|
|
4654
6723
|
[self beginPageStateTransition];
|
|
4655
6724
|
if (_directNativePagerEnabled) {
|
|
4656
6725
|
[self preparePageForHorizontalTransitionAtIndex:_currentIndex - 1];
|
|
4657
6726
|
[self preparePageForHorizontalTransitionAtIndex:_currentIndex + 1];
|
|
4658
6727
|
}
|
|
4659
6728
|
// A user drag owns the result even if UIKit later completes the old animation.
|
|
4660
|
-
|
|
6729
|
+
_programmaticPageMaskIndexes = nil;
|
|
4661
6730
|
[self liftSharedHeadersForPagerTransition:@"interactive"];
|
|
4662
6731
|
[self detachScrollObserver];
|
|
4663
6732
|
_isPagerDragging = YES;
|
|
4664
6733
|
_transitioning = YES;
|
|
6734
|
+
if (_directNativePagerEnabled) {
|
|
6735
|
+
if (_currentIndex > 0) [self beginProgrammaticScrollEdgesToIndex:_currentIndex - 1 allowExternalOverlay:YES];
|
|
6736
|
+
if (_currentIndex + 1 < _pageControllers.count) {
|
|
6737
|
+
[self beginProgrammaticScrollEdgesToIndex:_currentIndex + 1 allowExternalOverlay:YES];
|
|
6738
|
+
}
|
|
6739
|
+
}
|
|
4665
6740
|
if (_nativeSmoothHeaderScrollEnabled) {
|
|
4666
6741
|
RNCCollapsiblePagerLog([NSString stringWithFormat:
|
|
4667
6742
|
@"gesture-owner=pager page=%ld",
|
|
@@ -4707,7 +6782,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4707
6782
|
[self directPagerOffsetForIndex:index],
|
|
4708
6783
|
0
|
|
4709
6784
|
) animated:NO];
|
|
4710
|
-
[
|
|
6785
|
+
[self updateNativeTabProgress:index];
|
|
4711
6786
|
[self attachScrollObserverForCurrentPageAfterTransition:YES];
|
|
4712
6787
|
if (emitSelection &&
|
|
4713
6788
|
(_pendingGoToIndex < 0 || _pendingGoToIndex == index)) {
|
|
@@ -4758,7 +6833,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4758
6833
|
[self detachScrollObserver];
|
|
4759
6834
|
_currentIndex = index;
|
|
4760
6835
|
_destinationIndex = index;
|
|
4761
|
-
[
|
|
6836
|
+
[self updateNativeTabProgress:index];
|
|
4762
6837
|
[self attachScrollObserverForCurrentPageAfterTransition:YES];
|
|
4763
6838
|
// A newer tab tap remains authoritative while its queued command runs.
|
|
4764
6839
|
if (emitSelection &&
|
|
@@ -4794,6 +6869,20 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4794
6869
|
[self finishPagerScrollEmittingSelection:YES];
|
|
4795
6870
|
}
|
|
4796
6871
|
|
|
6872
|
+
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
|
|
6873
|
+
{
|
|
6874
|
+
if (scrollView != _pagerScrollView || _pendingNativePagerScrollCompletion == nil ||
|
|
6875
|
+
scrollView.isDragging || _generation != _pendingNativePagerScrollGeneration ||
|
|
6876
|
+
_transitionId != _pendingNativePagerScrollTransition ||
|
|
6877
|
+
fabs(scrollView.contentOffset.x - _pendingNativePagerScrollTarget) > 0.5) return;
|
|
6878
|
+
void (^completion)(BOOL) = _pendingNativePagerScrollCompletion;
|
|
6879
|
+
_pendingNativePagerScrollCompletion = nil;
|
|
6880
|
+
_pendingNativePagerScrollGeneration = 0;
|
|
6881
|
+
_pendingNativePagerScrollTransition = 0;
|
|
6882
|
+
_pendingNativePagerScrollTarget = 0;
|
|
6883
|
+
completion(YES);
|
|
6884
|
+
}
|
|
6885
|
+
|
|
4797
6886
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
|
4798
6887
|
{
|
|
4799
6888
|
CGFloat width = scrollView.bounds.size.width;
|
|
@@ -4805,7 +6894,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4805
6894
|
position = MAX(0, MIN(position, (NSInteger)_pageControllers.count - 1));
|
|
4806
6895
|
[self updatePageStateTransitionProgress:progress];
|
|
4807
6896
|
[self updateScrollEdgeContentMasks];
|
|
4808
|
-
[
|
|
6897
|
+
if (_tabProgressDisplayLink == nil) [self updateNativeTabProgress:progress];
|
|
4809
6898
|
const auto emitter = [self eventEmitter];
|
|
4810
6899
|
if (emitter) {
|
|
4811
6900
|
emitter->onPageScroll({.position = (double)position, .offset = (double)offset});
|
|
@@ -4824,7 +6913,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4824
6913
|
}
|
|
4825
6914
|
[self updatePageStateTransitionProgress:tabProgress];
|
|
4826
6915
|
[self updateScrollEdgeContentMasks];
|
|
4827
|
-
[
|
|
6916
|
+
[self updateNativeTabProgress:tabProgress];
|
|
4828
6917
|
const auto emitter = [self eventEmitter];
|
|
4829
6918
|
if (emitter) {
|
|
4830
6919
|
emitter->onPageScroll({.position = (double)position, .offset = (double)offset});
|
|
@@ -4895,7 +6984,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4895
6984
|
UIEdgeInsets adjustedInset = owner.adjustedContentInset;
|
|
4896
6985
|
NSString *geometry = [NSString stringWithFormat:
|
|
4897
6986
|
@"%.4f:%ld:%ld:%@:%@:%@:%@:%@:%@:%@",
|
|
4898
|
-
_headerOffset, (long)_headerHeight, (long)
|
|
6987
|
+
_headerOffset, (long)_headerHeight, (long)self.currentStickyHeaderHeight,
|
|
4899
6988
|
NSStringFromCGPoint(owner.contentOffset), NSStringFromCGSize(owner.contentSize),
|
|
4900
6989
|
NSStringFromCGRect(owner.bounds), NSStringFromUIEdgeInsets(inset),
|
|
4901
6990
|
NSStringFromUIEdgeInsets(adjustedInset), NSStringFromCGRect(headerRect), NSStringFromCGRect(ownerRect)];
|
|
@@ -4978,6 +7067,13 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4978
7067
|
{
|
|
4979
7068
|
UIScrollView *scrollView = _pagerTopScrollView;
|
|
4980
7069
|
if (_dispatchingPagerTop || ![self matchesPagerTop:scrollView]) return;
|
|
7070
|
+
CGFloat clampedTarget = MIN(MAX(_pagerTopLogicalTarget, 0), _headerHeight);
|
|
7071
|
+
if (clampedTarget != _pagerTopLogicalTarget) {
|
|
7072
|
+
_pagerTopLogicalTarget = clampedTarget;
|
|
7073
|
+
CGFloat physicalTarget = RNCLimitRestoredScrollOffset(clampedTarget - scrollView.contentInset.top,
|
|
7074
|
+
scrollView.contentSize.height, scrollView.bounds.size.height, scrollView.contentInset.top, scrollView.contentInset.bottom);
|
|
7075
|
+
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, physicalTarget) animated:NO];
|
|
7076
|
+
}
|
|
4981
7077
|
CGFloat logical = scrollView.contentOffset.y + scrollView.contentInset.top;
|
|
4982
7078
|
if (fabs(logical - _pagerTopLogicalTarget) > 0.5) return;
|
|
4983
7079
|
_pageOffsets[_pagerTopPageKey] = @(_nativeSmoothHeaderScrollEnabled ? 0 : _pagerTopLogicalTarget);
|
|
@@ -4989,14 +7085,44 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
4989
7085
|
}
|
|
4990
7086
|
|
|
4991
7087
|
- (void)scrollToTop:(NSInteger)target animated:(BOOL)animated
|
|
7088
|
+
{
|
|
7089
|
+
[self tryScrollToTop:target animated:animated];
|
|
7090
|
+
}
|
|
7091
|
+
|
|
7092
|
+
- (BOOL)tryScrollToTop:(NSInteger)target animated:(BOOL)animated
|
|
7093
|
+
{
|
|
7094
|
+
if (target != 0 && target != 1) return NO;
|
|
7095
|
+
return [self scrollHeaderToOffset:(target == 1 ? _headerHeight : 0) animated:animated];
|
|
7096
|
+
}
|
|
7097
|
+
|
|
7098
|
+
// The header offset is stored apart from the body, so a collapsed header can sit
|
|
7099
|
+
// above a body that is already at its top.
|
|
7100
|
+
- (BOOL)isAwayFromPageTop
|
|
7101
|
+
{
|
|
7102
|
+
return _headerOffset > 0.5;
|
|
7103
|
+
}
|
|
7104
|
+
|
|
7105
|
+
- (void)scrollHeaderBy:(double)delta
|
|
7106
|
+
{
|
|
7107
|
+
if (!std::isfinite(delta)) return;
|
|
7108
|
+
[self scrollHeaderToOffset:MIN(MAX(_headerOffset + delta, 0), _headerHeight) animated:NO];
|
|
7109
|
+
}
|
|
7110
|
+
|
|
7111
|
+
- (void)scrollHeaderToOffset:(double)offset
|
|
7112
|
+
{
|
|
7113
|
+
if (!std::isfinite(offset)) return;
|
|
7114
|
+
[self scrollHeaderToOffset:MIN(MAX(offset, 0), _headerHeight) animated:NO];
|
|
7115
|
+
}
|
|
7116
|
+
|
|
7117
|
+
- (BOOL)scrollHeaderToOffset:(CGFloat)logicalTarget animated:(BOOL)animated
|
|
4992
7118
|
{
|
|
4993
7119
|
[self cancelTopInsetReboundCheck];
|
|
4994
7120
|
UIScrollView *scrollView = _observedScrollView;
|
|
4995
7121
|
NSString *key = _observedPageKey;
|
|
4996
|
-
if (
|
|
7122
|
+
if (_isBeingRecycled || _transitioning || _isPagerDragging ||
|
|
4997
7123
|
_transitionPageOffsets != nil || _syntheticPageRestore || scrollView == nil || scrollView.window == nil ||
|
|
4998
7124
|
key == nil || ![key isEqualToString:self.currentPageKey] || _observedPageIndex != _currentIndex ||
|
|
4999
|
-
_observedPageGeneration != _generation || self.window == nil) return;
|
|
7125
|
+
_observedPageGeneration != _generation || self.window == nil) return NO;
|
|
5000
7126
|
[self cancelPagerTop];
|
|
5001
7127
|
// Old List phase2 notifications must run before the new target owns this page.
|
|
5002
7128
|
[NSNotificationCenter.defaultCenter postNotificationName:@"OneKeyNativeListCancelScrollCommand" object:scrollView];
|
|
@@ -5009,7 +7135,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
5009
7135
|
[_alignedBodyKeys removeObject:key];
|
|
5010
7136
|
[_suspendedBodyKeys removeObject:key];
|
|
5011
7137
|
[_displayBodyOverrides removeObjectForKey:key];
|
|
5012
|
-
|
|
7138
|
+
logicalTarget = MIN(MAX(logicalTarget, 0), _headerHeight);
|
|
5013
7139
|
_pageOffsets[key] = @(_nativeSmoothHeaderScrollEnabled ? 0 : logicalTarget);
|
|
5014
7140
|
_pagerTopScrollView = scrollView;
|
|
5015
7141
|
_pagerTopPageKey = [key copy];
|
|
@@ -5026,6 +7152,7 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
5026
7152
|
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, physicalTarget) animated:animated];
|
|
5027
7153
|
_dispatchingPagerTop = NO;
|
|
5028
7154
|
[self finishPagerTopIfReached];
|
|
7155
|
+
return YES;
|
|
5029
7156
|
}
|
|
5030
7157
|
|
|
5031
7158
|
- (void)setPage:(NSInteger)index
|