diff --git a/native-views/react-native-pager-view/docs/SPEC.md b/native-views/react-native-pager-view/docs/SPEC.md index 7f13af100..d18b1c558 100644 --- a/native-views/react-native-pager-view/docs/SPEC.md +++ b/native-views/react-native-pager-view/docs/SPEC.md @@ -59,6 +59,63 @@ cleanup path. A new drag invalidates an older pending settlement before it can release the new transition's owners. If the direct pager viewport width changes while a native animated page command is pending, stop the old-coordinate animation before resizing its viewport. After the normal layout completes, settle the captured logical destination at its new physical offset through the original generation/transition-guarded completion path. This restores scrolling, releases temporary edge ownership and drains queued commands. Any width change, including a fractional-point change, is significant. Zero width completes the logical destination without retaining a disabled pending animation; a later positive-width idle layout realigns the current page. Height-only layout and horizontal user drags retain their existing paths. Late animation-end callbacks must not complete a newer command before its own current target has been reached. +Implemented: iOS 26 local fixed-overlay smooth Hard +direct pagers use the existing source-edge ownership transfer and incoming-page +hosts during horizontal user drags and animated page commands. The source's actual top/pinned interactions +remain attached until settlement or cancellation; unmounted incoming pages use +the existing noninteractive stand-in only while the sticky header is pinned. +Returning to the source, recycling or window detachment releases temporary +resources and restores the current settled owner. External-overlay transitions +remain restricted to iOS 27 and newer. The native programmatic-animation choice +and the overlay theme-background layer also retain their iOS 27 gates. There is +no new public prop, page identity, inset, child reparenting or JavaScript work. +Native regressions exercise local source ownership, interrupted/returning drags, +animated page-command settlement, missing-list stand-in cleanup and the iOS 26 +external-overlay exclusion. + +Implemented: on iOS 26 only, a current local smooth +Hard direct-pager list may take over saved body alignment when a real vertical +`contentOffset` change arrives with `isDragging == true` after its pan recognizer +has ended or reset to Possible. Current-page identity, attachment, transition +and synthetic-restore guards still apply. Pager-top and active native header/body +commands, plus inset-rebound correction, retain ownership. This narrow takeover +clears temporary alignment/display-body state and advances the shared header; +a matching offset change without active dragging must keep that state. Other +platforms, external overlays, refresh/inset/size handling and explicit gesture +interruption of pager-top retain their existing rules. Focused native tests cover +Possible/Ended dragging takeover and non-dragging, synthetic and command guards. + +Implemented: iOS 26 local smooth Hard direct-pager +scroll owners with an original nil or fully transparent background temporarily +use the resolved opaque Pager/ancestor background as their native scroll backing. +Custom opaque or translucent backgrounds remain caller-owned. The exact original +nil-versus-clear value is retained. UIKit can return a new equivalent UIColor +on each read, so ownership uses nil-safe color value equality. An observably +different caller color makes the pager relinquish that lease; an equal-color +replacement is indistinguishable from UIKit rebuilding the same color. Theme +changes update only a still-owned backing. +The same lease spans settled/transition ownership and pending theme commits, +including incoming pages and stand-ins, without a transparent handoff frame. +Disabling the effect, detaching, recycling or releasing the last owner restores +the original value only while the current value is still the pager's applied +color. The native Hard effect, Glass views, opacity and React children are not +replaced. iOS 27 and newer retain their existing backgrounds and timing. + +Runtime verified with the same Pager source and native object in consumer Debug +simulators: iPhone SE (3rd generation) on iOS 26.0 and iPhone 17 Pro on iOS 27.0 +completed natural vertical scrolling, pinned half-drag returns, full page +switches, light/dark changes and opening/returning from Search and Action Center. +The iOS 26 active-list lease captured the original clear value and applied +white/dark backing from its actual opaque ancestor; iOS 27 retained clear scroll +backgrounds with no backing leases. The final iOS 26 repair has recordings; +the final iOS 27 check used captured frame sequences. The App debug dylibs have +different UUIDs despite identical Pager objects. Focused native XCTest selected +14 cases on each OS: iOS 26 passed 11 and skipped 3 iOS-27 controls; iOS 27 +passed 6 and skipped 8 iOS-26-only cases, with no failures. These checks cover +actual owner identity/geometry and cleanup, nil/clear/custom color ownership, +equivalent UIColor getter instances, theme changes, drag takeover and command +guards. Physical-device and Release behavior remain unverified. + Other pager modes retain their prior command and observer ordering. Recycling, window detachment, slot replacement and disabling the style also release the temporary resources. Conformance requires preserving the source interaction @@ -87,6 +144,33 @@ transition gates apply only while an outer PagerView is registered. `topOverlayColorScheme` is optional (`"light" | "dark"`) and coordinates the fixed overlay's effective appearance with React theme commits. It does not change the requested style, scroll owner, content inset or page identity. + +Implemented: on iOS 26, changing an existing overlay color scheme detaches its +scroll-edge interaction until a single main-run-loop callback after the Fabric +mount transaction. The callback runs in common modes so tracking does not defer +reattachment until the gesture ends. Layout and further mount work cannot +reattach the interaction while this appearance commit is pending. A newer scheme +cancels the queued callback and schedules from its own completed mount, using the +latest scheme and currently observed scroll view. Window detachment, recycling +and disabling the edge cancel pending work. Reattachment requires an enabled +edge, a current window and a local or resolved external overlay still mounted in +that window; stale work cannot attach to a recycled owner. The existing attach +path restores the requested edge style and preserves React child identities, +order, geometry and hit targets. Initial mount retains its existing timing; +iOS 27 and newer retain synchronous appearance reattachment in the mount +transaction. Android, Web and iOS before 26 are unchanged. + +Runtime verified in consumer iOS Simulator Debug builds: iOS 26.0 completed +two light/dark cycles with Home mounted and consecutive system-theme commands +with the final appearance checked. iOS 27.0 completed light-to-dark-to-light +against its existing light and dark appearance baselines. Both platforms verified +actual edge ownership and mounted child order, plus opening/returning from Search and +Action Center. Both builds compiled the identical Pager native object and +source. The App debug-dylib UUIDs differed; this is source/object parity, not +byte-identical App binaries. Same-mount rapid scheme races and cancellation +guards were source reviewed. Physical devices and Release builds remain +unverified. + When a smooth shared header reaches the overlay boundary, the existing sticky React and native tab views move together into a view pinned to the active scroll view. Their identities, scroll-view gesture ancestry and hit targets diff --git a/native-views/react-native-pager-view/ios/RNCCollapsiblePagerViewComponentView.mm b/native-views/react-native-pager-view/ios/RNCCollapsiblePagerViewComponentView.mm index 6ca0f11c6..24e90fc35 100644 --- a/native-views/react-native-pager-view/ios/RNCCollapsiblePagerViewComponentView.mm +++ b/native-views/react-native-pager-view/ios/RNCCollapsiblePagerViewComponentView.mm @@ -187,6 +187,15 @@ @interface RNCCollapsiblePagerReleasedScrollState : NSObject @implementation RNCCollapsiblePagerReleasedScrollState @end +@interface RNCCollapsiblePagerScrollEdgeBackgroundState : NSObject +@property (nonatomic, strong) UIColor *originalColor; +@property (nonatomic, strong) UIColor *appliedColor; +@property (nonatomic, assign) BOOL relinquished; +@end + +@implementation RNCCollapsiblePagerScrollEdgeBackgroundState +@end + @interface RNCCollapsiblePagerTransitionEdgeOwner : NSObject @property (nonatomic, weak) UIScrollView *scrollView; @property (nonatomic, weak) UIView *page; @@ -2292,8 +2301,13 @@ - (void)logHomeVisualGeometry:(NSString *)phase scrollView:(UIScrollView *)scrol - (void)cancelTopInsetReboundCheck; - (void)scheduleTopInsetReboundCheck; - (void)syncScrollEdgeAppearance; +- (void)applyScrollEdgeBackgroundToScrollView:(UIScrollView *)scrollView; +- (void)restoreScrollEdgeBackgroundForScrollView:(UIScrollView *)scrollView; +- (void)restoreUnusedScrollEdgeBackgroundForScrollView:(UIScrollView *)scrollView; - (void)updateHardEdgeSeparatorCovers; - (void)updateTopOverlayThemeBackground; +- (void)commitTopOverlayAppearance; +- (void)cancelTopOverlayAppearanceCommit; - (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay; - (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay; - (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay; @@ -2349,6 +2363,7 @@ @implementation RNCCollapsiblePagerViewComponentView { __weak UIView *_stickyEdgeInteractionHost; __weak UIScrollView *_topEdgeScrollView; UIScrollEdgeEffectStyle *_originalTopEdgeStyle; + NSMapTable *_scrollEdgeBackgroundStates; RNCCollapsiblePagerNativeTabBarView *_nativeTabBarView; RNCCollapsiblePagerNativeSubHeaderView *_nativeSubHeaderView; NSInteger _currentIndex; @@ -2368,6 +2383,7 @@ @implementation RNCCollapsiblePagerViewComponentView { RNCCollapsiblePagerViewTopScrollEdgeEffect _topScrollEdgeEffect; NSString *_topOverlayColorScheme; BOOL _pendingTopOverlayAppearanceCommit; + BOOL _topOverlayAppearanceCommitScheduled; BOOL _applyingTopOverlayInsetChange; BOOL _correctingTopInsetRebound; __weak UIScrollView *_pendingTopInsetReboundScrollView; @@ -2687,6 +2703,9 @@ - (void)didMoveToWindow { [super didMoveToWindow]; [self cancelNativeToolbarSettlement]; + if (self.window == nil && _pendingTopOverlayAppearanceCommit) { + [self cancelTopOverlayAppearanceCommit]; + } if (self.window == nil) [self stopProgrammaticTabProgress]; if (self.window == nil && _pendingNativePagerScrollCompletion != nil) { [self cancelPendingNativePagerScroll]; @@ -2831,6 +2850,78 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection } } +- (void)restoreScrollEdgeBackgroundForScrollView:(UIScrollView *)scrollView +{ + RNCCollapsiblePagerScrollEdgeBackgroundState *state = [_scrollEdgeBackgroundStates objectForKey:scrollView]; + if (state == nil) return; + UIColor *current = scrollView.backgroundColor; + if (!state.relinquished && state.appliedColor != nil && + (current == state.appliedColor || [current isEqual:state.appliedColor])) { + scrollView.backgroundColor = state.originalColor; + } + [_scrollEdgeBackgroundStates removeObjectForKey:scrollView]; +} + +- (void)restoreUnusedScrollEdgeBackgroundForScrollView:(UIScrollView *)scrollView +{ + if (scrollView == nil || scrollView == _topEdgeScrollView || + [_programmaticScrollEdges objectForKey:scrollView] != nil || + (_pendingTopOverlayAppearanceCommit && scrollView == _observedScrollView && + [self canPreserveHorizontalScrollEdgesAllowExternalOverlay:NO])) return; + [self restoreScrollEdgeBackgroundForScrollView:scrollView]; +} + +- (void)applyScrollEdgeBackgroundToScrollView:(UIScrollView *)scrollView +{ + if (scrollView == nil) return; + BOOL eligible = NO; + if (@available(iOS 27.0, *)) { + // iOS 27 passed the transparent-backing checks without this workaround. + } else if (@available(iOS 26.0, *)) { + eligible = [self canPreserveHorizontalScrollEdgesAllowExternalOverlay:NO]; + } + if (!eligible) { + [self restoreScrollEdgeBackgroundForScrollView:scrollView]; + return; + } + RNCCollapsiblePagerScrollEdgeBackgroundState *state = [_scrollEdgeBackgroundStates objectForKey:scrollView]; + UIColor *current = scrollView.backgroundColor; + if (state == nil) { + state = [RNCCollapsiblePagerScrollEdgeBackgroundState new]; + state.originalColor = current; + UIColor *resolved = [current resolvedColorWithTraitCollection:_topOverlayHostView.traitCollection]; + state.relinquished = resolved != nil && CGColorGetAlpha(resolved.CGColor) > 0; + if (_scrollEdgeBackgroundStates == nil) _scrollEdgeBackgroundStates = [NSMapTable weakToStrongObjectsMapTable]; + [_scrollEdgeBackgroundStates setObject:state forKey:scrollView]; + } else if (current != (state.appliedColor ?: state.originalColor) && + ![current isEqual:(state.appliedColor ?: state.originalColor)]) { + // UIKit may return equivalent UIColor instances from consecutive getter reads. + // Preserve a caller's replacement rather than reclaiming its color on later updates. + state.relinquished = YES; + } + if (state.relinquished) return; + UIColor *color = nil; + for (UIView *view = self; view != nil; view = view.superview) { + UIColor *candidate = [view.backgroundColor resolvedColorWithTraitCollection:_topOverlayHostView.traitCollection]; + if (candidate != nil && CGColorGetAlpha(candidate.CGColor) >= 1) { + color = candidate; + break; + } + } + if (color == nil) { + if (state.appliedColor != nil) { + scrollView.backgroundColor = state.originalColor; + state.appliedColor = nil; + } + return; + } + if ([state.appliedColor isEqual:color]) return; + // iOS 26 Hard edges with transparent scroll backing reproduced stale pale Glass + // in a pure UIKit probe. Match the actual opaque ancestor; keep the native effect. + scrollView.backgroundColor = color; + state.appliedColor = scrollView.backgroundColor; +} + - (void)syncScrollEdgeAppearance { BOOL active = _topScrollEdgeEnabled && @@ -2846,9 +2937,13 @@ - (void)syncScrollEdgeAppearance style = self.traitCollection.userInterfaceStyle; } } - if (_topOverlayHostView.overrideUserInterfaceStyle == style) return; - _topOverlayHostView.overrideUserInterfaceStyle = style; - _pinnedStickyHostView.overrideUserInterfaceStyle = style; + if (_topOverlayHostView.overrideUserInterfaceStyle != style) { + _topOverlayHostView.overrideUserInterfaceStyle = style; + _pinnedStickyHostView.overrideUserInterfaceStyle = style; + } + for (UIScrollView *scrollView in _scrollEdgeBackgroundStates.keyEnumerator.allObjects) { + [self applyScrollEdgeBackgroundToScrollView:scrollView]; + } } - (void)restoreScrollEdgeContentMasks @@ -3082,23 +3177,27 @@ - (RNCCollapsiblePagerTransitionEdgeOwner *)borrowedPinnedStickyOwner - (BOOL)canPreserveHorizontalScrollEdgesAllowExternalOverlay:(BOOL)allowExternalOverlay { - if (@available(iOS 27.0, *)) { + // The edge APIs exist on iOS 26, but the former iOS 27 gate skipped local Hard + // transition ownership there. External-overlay handoff keeps its iOS 27 boundary. + if (@available(iOS 26.0, *)) { if (!_directNativePagerEnabled || !_topScrollEdgeEnabled || !_nativeSmoothHeaderScrollEnabled || _topScrollEdgeEffect != RNCCollapsiblePagerViewTopScrollEdgeEffect::Hard || self.window == nil || _isBeingRecycled) return NO; if (_topOverlayView != nil && _externalTopOverlayTag <= 0) return YES; - return allowExternalOverlay && _topOverlayView == nil && _externalTopOverlayTag > 0 && - _externalTopOverlayView.window == self.window && _externalTopOverlayHeight > 0 && - _topOverlayHostView.window == self.window && !_topOverlayHostView.hidden && - (_externalOuterPager == nil || (_externalOuterPageActive && !_externalOuterTransitioning)); + if (@available(iOS 27.0, *)) { + return allowExternalOverlay && _topOverlayView == nil && _externalTopOverlayTag > 0 && + _externalTopOverlayView.window == self.window && _externalTopOverlayHeight > 0 && + _topOverlayHostView.window == self.window && !_topOverlayHostView.hidden && + (_externalOuterPager == nil || (_externalOuterPageActive && !_externalOuterTransitioning)); + } } return NO; } - (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverlay { - if (@available(iOS 27.0, *)) { + if (@available(iOS 26.0, *)) { UIScrollView *source = _observedScrollView; if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay] || source == nil || source != _topEdgeScrollView || @@ -3143,7 +3242,7 @@ - (void)adoptCurrentScrollEdgeForProgrammaticTransition:(BOOL)allowExternalOverl - (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverlay:(BOOL)allowExternalOverlay { - if (@available(iOS 27.0, *)) { + if (@available(iOS 26.0, *)) { if (![self canPreserveHorizontalScrollEdgesAllowExternalOverlay:allowExternalOverlay]) return; if (_programmaticScrollEdges == nil) { _programmaticScrollEdges = [NSMapTable weakToStrongObjectsMapTable]; @@ -3172,6 +3271,7 @@ - (void)beginProgrammaticScrollEdgesToIndex:(NSInteger)index allowExternalOverla owner.scrollView = scrollView; owner.page = _pageControllers[pageIndex].view; owner.originalStyle = scrollView.topEdgeEffect.style; + [self applyScrollEdgeBackgroundToScrollView:scrollView]; scrollView.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle; UILabel *(^markerForHost)(UIView *) = ^UILabel *(UIView *host) { UILabel *marker = [UILabel new]; @@ -3264,6 +3364,7 @@ - (void)releaseProgrammaticScrollEdgeOwner:(RNCCollapsiblePagerTransitionEdgeOwn } if (scrollView != nil) [_programmaticScrollEdges removeObjectForKey:scrollView]; [_programmaticScrollEdgeOwners removeObjectIdenticalTo:owner]; + [self restoreUnusedScrollEdgeBackgroundForScrollView:scrollView]; } } @@ -3340,6 +3441,7 @@ - (void)finishProgrammaticScrollEdges handoff.borrowsPinnedStickyHost = NO; // The caller reattaches the shared header in this run loop turn; drop the // transitional resources on the next one, after the header is rendered. + __weak __typeof__(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ if (@available(iOS 26.0, *)) { [handoff.topHost removeInteraction:handoff.topInteraction]; @@ -3357,6 +3459,7 @@ - (void)finishProgrammaticScrollEdges [handoff.ownedTopHost removeFromSuperview]; [handoff.ownedStickyHost removeFromSuperview]; } + [weakSelf restoreUnusedScrollEdgeBackgroundForScrollView:handoff.scrollView]; }); } @@ -3366,7 +3469,7 @@ - (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex // own an edge effect, so its masked top shows the bare background. An empty // stand-in scroll view resting past its top edge renders the same Hard // material (the settled header is masked out under the overlay as well). - if (@available(iOS 27.0, *)) { + if (@available(iOS 26.0, *)) { if (pageIndex == _currentIndex || pageIndex < 0 || pageIndex >= (NSInteger)_pageControllers.count) return NO; UIView *page = _pageControllers[pageIndex].view; @@ -3390,6 +3493,7 @@ - (BOOL)beginStandInScrollEdgeForPageAtIndex:(NSInteger)pageIndex standIn.accessibilityElementsHidden = YES; standIn.topEdgeEffect.style = UIScrollEdgeEffectStyle.hardStyle; [container insertSubview:standIn aboveSubview:page]; + [self applyScrollEdgeBackgroundToScrollView:standIn]; RNCCollapsiblePagerTransitionEdgeOwner *owner = [RNCCollapsiblePagerTransitionEdgeOwner new]; owner.scrollView = standIn; @@ -3498,6 +3602,30 @@ - (BOOL)hasProgrammaticScrollEdgeForPage:(UIView *)page return NO; } +- (void)cancelTopOverlayAppearanceCommit +{ + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(commitTopOverlayAppearance) + object:nil]; + _topOverlayAppearanceCommitScheduled = NO; + _pendingTopOverlayAppearanceCommit = NO; +} + +- (void)commitTopOverlayAppearance +{ + _topOverlayAppearanceCommitScheduled = NO; + if (!_pendingTopOverlayAppearanceCommit) return; + _pendingTopOverlayAppearanceCommit = NO; + BOOL localOverlayReady = _topOverlayView.superview == _topOverlayHostView && + _topOverlayView.window == self.window; + BOOL externalOverlayReady = _externalTopOverlayTag > 0 && + _externalTopOverlayView.window == self.window; + if (!_isBeingRecycled && _topScrollEdgeEnabled && self.window != nil && + (localOverlayReady || externalOverlayReady)) { + [self updateTopScrollEdgeForScrollView:_observedScrollView]; + } +} + - (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView { [self syncScrollEdgeAppearance]; @@ -3523,6 +3651,7 @@ - (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView (hasOverlay && _topEdgeInteractionHost != _topOverlayHostView); if (_topEdgeScrollView != nil && (!enabled || _topEdgeScrollView != scrollView || topHostChanged)) { + UIScrollView *previousScrollView = _topEdgeScrollView; [_topEdgeInteractionHost removeInteraction:_topEdgeInteraction]; _topEdgeInteraction.scrollView = nil; [_stickyEdgeInteractionHost removeInteraction:_stickyEdgeInteraction]; @@ -3538,12 +3667,14 @@ - (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView _stickyEdgeInteractionHost = nil; _topEdgeScrollView = nil; _originalTopEdgeStyle = nil; + [self restoreUnusedScrollEdgeBackgroundForScrollView:previousScrollView]; } if (enabled && _topEdgeScrollView == nil) { _originalTopEdgeStyle = scrollView.topEdgeEffect.style; _topEdgeScrollView = scrollView; } if (enabled) { + [self applyScrollEdgeBackgroundToScrollView:scrollView]; UIScrollEdgeEffectStyle *style = _topScrollEdgeEffect == RNCCollapsiblePagerViewTopScrollEdgeEffect::Soft ? UIScrollEdgeEffectStyle.softStyle : UIScrollEdgeEffectStyle.hardStyle; @@ -3671,6 +3802,10 @@ - (void)updateHardEdgeSeparatorCovers - (void)dealloc { + for (UIScrollView *scrollView in _scrollEdgeBackgroundStates.keyEnumerator.allObjects) { + [self restoreScrollEdgeBackgroundForScrollView:scrollView]; + } + [self cancelTopOverlayAppearanceCommit]; [self cancelNativeToolbarSettlement]; [self stopProgrammaticTabProgress]; [self clearProgrammaticScrollEdges]; @@ -4349,14 +4484,21 @@ - (void)mountingTransactionDidMount:(const MountingTransaction &)transaction [self setNeedsLayout]; } if (_pendingTopOverlayAppearanceCommit) { - _pendingTopOverlayAppearanceCommit = NO; - BOOL localOverlayReady = _topOverlayView.superview == _topOverlayHostView && - _topOverlayView.window == self.window; - BOOL externalOverlayReady = _externalTopOverlayTag > 0 && - _externalTopOverlayView.window == self.window; - if (!_isBeingRecycled && _topScrollEdgeEnabled && self.window != nil && - (localOverlayReady || externalOverlayReady)) { - [self updateTopScrollEdgeForScrollView:_observedScrollView]; + if (@available(iOS 27.0, *)) { + [self commitTopOverlayAppearance]; + } else if (@available(iOS 26.0, *)) { + // On iOS 26, same-mount edge reattachment was observed to leave stale pale glass. + // One main-run-loop turn with the edge detached restores the current appearance. + // iOS 27 passed the same theme-switch checks with the synchronous path above. + if (!_topOverlayAppearanceCommitScheduled) { + _topOverlayAppearanceCommitScheduled = YES; + [self performSelector:@selector(commitTopOverlayAppearance) + withObject:nil + afterDelay:0 + inModes:@[NSRunLoopCommonModes]]; + } + } else { + [self commitTopOverlayAppearance]; } } [self updateScrollEdgeContentMasks]; @@ -4687,6 +4829,7 @@ - (void)layoutSubviews - (void)prepareForRecycle { + [self cancelTopOverlayAppearanceCommit]; [self cancelNativeToolbarSettlement]; [self cancelPendingNativePagerScroll]; [_externalOuterPager removeNestedOverlayObserver:self]; @@ -4697,6 +4840,9 @@ - (void)prepareForRecycle [self cancelHeaderSettledCheck]; [self publishHeaderSettledAtTop:NO identityChanged:NO]; _isBeingRecycled = YES; + for (UIScrollView *scrollView in _scrollEdgeBackgroundStates.keyEnumerator.allObjects) { + [self restoreScrollEdgeBackgroundForScrollView:scrollView]; + } _toolbarTransitionPending = NO; [_nativeTabBarView updateToolbarPagerIndex:-1 busy:YES]; _pendingTopOverlayAppearanceCommit = NO; @@ -4921,6 +5067,9 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & BOOL enabledChanged = _topScrollEdgeEnabled != enabled; _topScrollEdgeEnabled = enabled; _topScrollEdgeEffect = newViewProps.topScrollEdgeEffect; + if (!enabled && _pendingTopOverlayAppearanceCommit) { + [self cancelTopOverlayAppearanceCommit]; + } if (enabledChanged) { _deferTopEdgeSlotRebuild = YES; [self rebuildSlots]; @@ -4940,6 +5089,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & if (self.hasFixedTopOverlay && _topScrollEdgeEnabled && _topOverlayColorScheme != nil && ![_topOverlayColorScheme isEqualToString:nextScheme]) { + // A newer scheme must wait for its own mount before scheduling the edge again. + [self cancelTopOverlayAppearanceCommit]; _pendingTopOverlayAppearanceCommit = YES; [self updateTopScrollEdgeForScrollView:nil]; } @@ -6354,6 +6505,23 @@ - (void)observeValueForKeyPath:(NSString *)keyPath UIScrollView *ownedScroll = (UIScrollView *)object; NSValue *oldPoint = change[NSKeyValueChangeOldKey]; NSValue *newPoint = change[NSKeyValueChangeNewKey]; + BOOL hasVerticalOffsetDelta = [keyPath isEqualToString:@"contentOffset"] && + [oldPoint isKindOfClass:NSValue.class] && [newPoint isKindOfClass:NSValue.class] && + oldPoint.CGPointValue.y != newPoint.CGPointValue.y; + BOOL ownsScrollDrag = ownedScroll.panGestureRecognizer.state == UIGestureRecognizerStateChanged; + if (@available(iOS 27.0, *)) { + // Keep the existing iOS 27 gesture ownership rule. + } else if (@available(iOS 26.0, *)) { + // Observed iOS 26 drag offsets can arrive after the pan has ended or reset. + // Only the active local list may use isDragging to take over saved alignment. + if (hasVerticalOffsetDelta && ownedScroll.isDragging && + ownedScroll.window == self.window && + [self canPreserveHorizontalScrollEdgesAllowExternalOverlay:NO] && + !_correctingTopInsetRebound && ![self matchesPagerTop:ownedScroll] && + ![_commandBodyKeys containsObject:_observedPageKey] && _headerCommandOwner == nil) { + ownsScrollDrag = YES; + } + } if ([keyPath isEqualToString:@"contentOffset"] && [self matchesPagerTop:ownedScroll] && ownedScroll.panGestureRecognizer.state == UIGestureRecognizerStateChanged && [oldPoint isKindOfClass:NSValue.class] && [newPoint isKindOfClass:NSValue.class] && oldPoint.CGPointValue.y != newPoint.CGPointValue.y) { @@ -6361,16 +6529,10 @@ - (void)observeValueForKeyPath:(NSString *)keyPath [self cancelPagerTop]; [ownedScroll setContentOffset:interruptedOffset animated:NO]; } - if ([keyPath isEqualToString:@"contentOffset"] && - ownedScroll.panGestureRecognizer.state == UIGestureRecognizerStateChanged && - [oldPoint isKindOfClass:NSValue.class] && [newPoint isKindOfClass:NSValue.class] && - oldPoint.CGPointValue.y != newPoint.CGPointValue.y) { + if (hasVerticalOffsetDelta && ownsScrollDrag) { [_alignedBodyKeys removeObject:_observedPageKey]; } - if (_nativeSmoothHeaderScrollEnabled && [keyPath isEqualToString:@"contentOffset"] && - ownedScroll.panGestureRecognizer.state == UIGestureRecognizerStateChanged && - [oldPoint isKindOfClass:NSValue.class] && [newPoint isKindOfClass:NSValue.class] && - oldPoint.CGPointValue.y != newPoint.CGPointValue.y) { + if (_nativeSmoothHeaderScrollEnabled && hasVerticalOffsetDelta && ownsScrollDrag) { [self cancelPagerTop]; [_commandBodyKeys removeObject:_observedPageKey]; [_pendingPageRestoreKeys removeObject:_observedPageKey]; @@ -6409,7 +6571,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath _currentLogicalOffset = scrollView.contentOffset.y + scrollView.contentInset.top; if (_correctingTopInsetRebound) return; if ([_alignedBodyKeys containsObject:_observedPageKey] || - (_nativeSmoothHeaderScrollEnabled && scrollView.panGestureRecognizer.state != UIGestureRecognizerStateChanged && + (_nativeSmoothHeaderScrollEnabled && !ownsScrollDrag && !scrollView.isDecelerating && ![_commandBodyKeys containsObject:_observedPageKey])) return; _pageOffsets[_nativeSmoothHeaderScrollEnabled ? _observedPageKey : self.currentPageKey] = @(_nativeSmoothHeaderScrollEnabled ? MAX(_currentLogicalOffset - _headerHeight, 0) : _currentLogicalOffset); diff --git a/native-views/react-native-pager-view/ios/tests/RNCCollapsiblePagerHitTestTests.mm b/native-views/react-native-pager-view/ios/tests/RNCCollapsiblePagerHitTestTests.mm index 10e2aae68..73685c647 100644 --- a/native-views/react-native-pager-view/ios/tests/RNCCollapsiblePagerHitTestTests.mm +++ b/native-views/react-native-pager-view/ios/tests/RNCCollapsiblePagerHitTestTests.mm @@ -25,6 +25,8 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; - (void)goTo:(NSInteger)index animated:(BOOL)animated; - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; - (void)emitPageSelected:(NSInteger)position; +- (void)attachScrollObserverForCurrentPage; +- (void)syncScrollEdgeAppearance; @end @interface UIView (NativeTabReservationTesting) @@ -59,6 +61,39 @@ - (void)emitPageSelected:(NSInteger)position } @end +// Model the equivalent fresh UIColor instances observed on NativeListCollectionView. +@interface RNCEquivalentBackgroundScrollView : UIScrollView +@end + +@implementation RNCEquivalentBackgroundScrollView +- (UIColor *)backgroundColor +{ + UIColor *color = super.backgroundColor; + return color == nil ? nil : [[UIColor alloc] initWithCGColor:color.CGColor]; +} +@end + +@interface RNCAlignedTakeoverPan : UIPanGestureRecognizer +@property (nonatomic) UIGestureRecognizerState observedState; +@end + +@implementation RNCAlignedTakeoverPan +- (UIGestureRecognizerState)state { return _observedState; } +@end + +@interface RNCAlignedTakeoverScrollView : UIScrollView +@property (nonatomic) BOOL observedDragging; +@property (nonatomic, strong) RNCAlignedTakeoverPan *observedPan; +@end + +@implementation RNCAlignedTakeoverScrollView +- (BOOL)isDragging { return _observedDragging; } +- (UIPanGestureRecognizer *)panGestureRecognizer +{ + return _observedPan ?: super.panGestureRecognizer; +} +@end + @interface RNCCollapsiblePagerHitTestTests : XCTestCase @property (nonatomic, strong) UIView *root; @property (nonatomic, strong) UIButton *toolbar; @@ -497,6 +532,17 @@ - (UIScrollView *)prepareDirectDragWithSource:(UIScrollView **)sourceOut return horizontal; } +- (void)prepareIncomingListsScrolledBeyondBars +{ + NSMutableDictionary *offsets = [self.pager valueForKey:@"pageOffsets"]; + NSArray *pages = [self.pager valueForKey:@"pageControllers"]; + for (NSNumber *index in @[@0, @2]) { + offsets[[NSString stringWithFormat:@"page-%ld", (long)index.integerValue]] = @200; + UIScrollView *list = (UIScrollView *)pages[index.integerValue].view.subviews.firstObject; + list.contentOffset = CGPointMake(0, 200); + } +} + - (UIScrollView *)prepareExternalDirectDragWithSource:(UIScrollView **)sourceOut overlay:(UIView **)overlayOut { @@ -681,6 +727,7 @@ - (void)testExternalDirectDragPreservesProxyIdentityAndSettles UIScrollView *source = nil; UIView *overlay = nil; UIScrollView *horizontal = [self prepareExternalDirectDragWithSource:&source overlay:&overlay]; + [self prepareIncomingListsScrolledBeyondBars]; UIView *proxy = [self.pager valueForKey:@"topOverlayHostView"]; UIView *pinned = [self.pager valueForKey:@"pinnedStickyHostView"]; UIScrollEdgeElementContainerInteraction *top = [self.pager valueForKey:@"topEdgeInteraction"]; @@ -729,6 +776,8 @@ - (void)testExternalDirectDragPreservesProxyIdentityAndSettles XCTAssertTrue([[owner valueForKey:@"ownsTransitionHosts"] boolValue]); UIView *page = [owner valueForKey:@"page"]; UIScrollView *list = [owner valueForKey:@"scrollView"]; + XCTAssertNil([owner valueForKey:@"standInScrollView"]); + XCTAssertEqual(list, page.subviews.firstObject); UIView *ownedTop = [owner valueForKey:@"ownedTopHost"]; UIView *ownedSticky = [owner valueForKey:@"ownedStickyHost"]; XCTAssertNotNil(ownedTop); @@ -796,15 +845,23 @@ - (void)testExternalDirectDragPreservesProxyIdentityAndSettles horizontal.contentOffset = CGPointMake(640, 0); [self.pager scrollViewDidEndDragging:horizontal willDecelerate:NO]; - XCTestExpectation *settled = [self expectationWithDescription:@"external drag settles"]; - dispatch_async(dispatch_get_main_queue(), ^{ [settled fulfill]; }); + NSPredicate *released = [NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) { + for (UIView *host in ownedHosts) { + if (host.superview != nil || host.interactions.count != 0) return NO; + } + for (UIView *edgeMarker in ownedMarkers) { + if (edgeMarker.superview != nil) return NO; + } + for (UIScrollEdgeElementContainerInteraction *edge in ownedEdges) { + if (edge.scrollView != nil) return NO; + } + return YES; + }]; + XCTNSPredicateExpectation *settled = [[XCTNSPredicateExpectation alloc] + initWithPredicate:released object:self.pager]; [self waitForExpectations:@[settled] timeout:2]; XCTAssertEqual([[self.pager valueForKey:@"currentIndex"] integerValue], 2); XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 0); - for (id owner in incomingOwners) { - XCTAssertNil([owner valueForKey:@"ownedTopHost"]); - XCTAssertNil([owner valueForKey:@"ownedStickyHost"]); - } for (UIView *host in ownedHosts) { XCTAssertNil(host.superview); XCTAssertEqual(host.interactions.count, 0); @@ -979,9 +1036,10 @@ - (void)testExternalOuterTransitionReleasesBorrowedEdges - (void)testDirectDragAdoptsSourceBeforeDetachAndOwnsBothNeighbours { - if (@available(iOS 27.0, *)) { + if (@available(iOS 26.0, *)) { UIScrollView *source = nil; UIScrollView *horizontal = [self prepareDirectDragWithSource:&source]; + [self prepareIncomingListsScrolledBeyondBars]; UIView *topHost = [self.pager valueForKey:@"topEdgeInteractionHost"]; UIView *pinnedHost = [self.pager valueForKey:@"pinnedStickyHostView"]; UIScrollEdgeElementContainerInteraction *top = [self.pager valueForKey:@"topEdgeInteraction"]; @@ -1015,8 +1073,10 @@ - (void)testDirectDragAdoptsSourceBeforeDetachAndOwnsBothNeighbours XCTAssertNotNil([[owner valueForKey:@"topInteraction"] scrollView]); if (owner == sourceOwner) continue; XCTAssertTrue([[owner valueForKey:@"ownsTransitionHosts"] boolValue]); + XCTAssertNil([owner valueForKey:@"standInScrollView"]); UIView *page = [owner valueForKey:@"page"]; UIScrollView *list = [owner valueForKey:@"scrollView"]; + XCTAssertEqual(list, page.subviews.firstObject); UIView *incomingTop = [owner valueForKey:@"ownedTopHost"]; UIView *incomingSticky = [owner valueForKey:@"ownedStickyHost"]; XCTAssertEqual(incomingTop.superview, page); @@ -1029,15 +1089,16 @@ - (void)testDirectDragAdoptsSourceBeforeDetachAndOwnsBothNeighbours CGRectGetMinX([list convertRect:list.bounds toView:page]), 0.001); } } else { - XCTSkip(@"Direct local Hard drag handoff requires iOS 27 or newer"); + XCTSkip(@"Direct local Hard drag handoff requires iOS 26 or newer"); } } - (void)testDirectDragTakeoverIgnoresOldSettlementAndReleasesOnReturn { - if (@available(iOS 27.0, *)) { + if (@available(iOS 26.0, *)) { UIScrollView *source = nil; UIScrollView *horizontal = [self prepareDirectDragWithSource:&source]; + [self prepareIncomingListsScrolledBeyondBars]; UIScrollEdgeElementContainerInteraction *top = [self.pager valueForKey:@"topEdgeInteraction"]; UIView *topHost = [self.pager valueForKey:@"topEdgeInteractionHost"]; NSUInteger originalTransition = [[self.pager valueForKey:@"transitionId"] unsignedIntegerValue]; @@ -1073,13 +1134,13 @@ - (void)testDirectDragTakeoverIgnoresOldSettlementAndReleasesOnReturn XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 0); XCTAssertEqual(incomingHosts.count, 4); for (UIView *host in incomingHosts) XCTAssertNil(host.superview); - XCTAssertFalse([topHost.interactions containsObject:top]); - XCTAssertNil(top.scrollView); + XCTAssertTrue([topHost.interactions containsObject:top]); + XCTAssertEqual(top.scrollView, source); XCTAssertEqual([[self.pager valueForKey:@"currentIndex"] integerValue], 1); XCTAssertEqual([self.pager valueForKey:@"topEdgeScrollView"], source); XCTAssertEqual([self.pager valueForKey:@"originalTopEdgeStyle"], UIScrollEdgeEffectStyle.softStyle); UIScrollEdgeElementContainerInteraction *normal = [self.pager valueForKey:@"topEdgeInteraction"]; - XCTAssertNotNil(normal); + XCTAssertEqual(normal, top); XCTAssertEqual(normal.scrollView, source); XCTAssertEqual(source.topEdgeEffect.style, UIScrollEdgeEffectStyle.hardStyle); NSArray *pages = [self.pager valueForKey:@"pageControllers"]; @@ -1088,7 +1149,363 @@ - (void)testDirectDragTakeoverIgnoresOldSettlementAndReleasesOnReturn XCTAssertEqual(neighbor.topEdgeEffect.style, UIScrollEdgeEffectStyle.softStyle); } } else { - XCTSkip(@"Direct local Hard drag handoff requires iOS 27 or newer"); + XCTSkip(@"Direct local Hard drag handoff requires iOS 26 or newer"); + } +} + +- (void)testLocalDragMissingIncomingListReleasesStandInOnRecycle +{ + if (@available(iOS 26.0, *)) { + self.root.backgroundColor = UIColor.blackColor; + UIScrollView *horizontal = [self prepareDirectDragWithSource:NULL]; + NSArray *pages = [self.pager valueForKey:@"pageControllers"]; + UIView *incomingPage = pages[2].view; + for (UIView *child in incomingPage.subviews.copy) [child removeFromSuperview]; + [self.pager scrollViewWillBeginDragging:horizontal]; + id incomingOwner = nil; + for (id owner in [self.pager valueForKey:@"programmaticScrollEdgeOwners"]) { + if ([owner valueForKey:@"page"] == incomingPage) incomingOwner = owner; + } + XCTAssertNotNil(incomingOwner); + UIScrollView *standIn = [incomingOwner valueForKey:@"standInScrollView"]; + UIView *topHost = [incomingOwner valueForKey:@"ownedTopHost"]; + UIView *stickyHost = [incomingOwner valueForKey:@"ownedStickyHost"]; + UIScrollEdgeElementContainerInteraction *top = [incomingOwner valueForKey:@"topInteraction"]; + UIScrollEdgeElementContainerInteraction *sticky = [incomingOwner valueForKey:@"stickyInteraction"]; + XCTAssertNotNil(standIn); + XCTAssertEqual(standIn.superview, incomingPage.superview); + XCTAssertEqual(topHost.superview, incomingPage.superview); + XCTAssertEqual(stickyHost.superview, incomingPage.superview); + XCTAssertEqualWithAccuracy(standIn.frame.origin.x, + [incomingPage convertPoint:CGPointZero toView:incomingPage.superview].x, 0.001); + XCTAssertEqualWithAccuracy(topHost.frame.origin.x, standIn.frame.origin.x, 0.001); + XCTAssertEqualWithAccuracy(stickyHost.frame.origin.x, standIn.frame.origin.x, 0.001); + if (@available(iOS 27.0, *)) { + XCTAssertEqualObjects(standIn.backgroundColor, UIColor.clearColor); + } else { + XCTAssertEqualObjects(standIn.backgroundColor, UIColor.blackColor); + } + XCTAssertEqual(top.scrollView, standIn); + XCTAssertEqual(sticky.scrollView, standIn); + XCTAssertFalse(standIn.userInteractionEnabled); + [self.pager prepareForRecycle]; + XCTAssertNil(standIn.superview); + XCTAssertEqualObjects(standIn.backgroundColor, UIColor.clearColor); + XCTAssertNil(topHost.superview); + XCTAssertNil(stickyHost.superview); + XCTAssertNil(top.scrollView); + XCTAssertNil(sticky.scrollView); + XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 0); + } else { + XCTSkip(@"Local Hard stand-in edges require iOS 26 or newer"); + } +} + +- (void)testIOS26TransparentBackingRestoresExactOriginalAndUpdatesTheme +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"Opaque backing is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *source = [self preparePinnedLocalHardSource]; + UIColor *dark = [UIColor colorWithWhite:0.06 alpha:1]; + UIColor *light = [UIColor colorWithWhite:0.98 alpha:1]; + for (id value in @[NSNull.null, UIColor.clearColor]) { + UIColor *original = value == NSNull.null ? nil : value; + source.backgroundColor = original; + self.root.backgroundColor = dark; + [self.pager updateTopScrollEdgeForScrollView:source]; + UIColor *applied = source.backgroundColor; + XCTAssertEqualObjects(applied, dark); + XCTAssertEqualObjects(source.backgroundColor, applied); + self.root.backgroundColor = light; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, light); + self.root.backgroundColor = nil; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, original); + self.root.backgroundColor = dark; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, dark); + [self.pager setValue:@NO forKey:@"topScrollEdgeEnabled"]; + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertEqualObjects(source.backgroundColor, original); + [self.pager setValue:@YES forKey:@"topScrollEdgeEnabled"]; + [self.pager updateTopScrollEdgeForScrollView:source]; + XCTAssertEqualObjects(source.backgroundColor, dark); + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertEqualObjects(source.backgroundColor, original); + } + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26BackingPreservesCallerColorsAndReleasesOnWindowExit +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"Opaque backing is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *source = [self preparePinnedLocalHardSource]; + self.root.backgroundColor = UIColor.blackColor; + for (UIColor *custom in @[UIColor.redColor, [UIColor colorWithWhite:0.5 alpha:0.5]]) { + source.backgroundColor = custom; + [self.pager updateTopScrollEdgeForScrollView:source]; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, custom); + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertEqualObjects(source.backgroundColor, custom); + } + source.backgroundColor = nil; + [self.pager updateTopScrollEdgeForScrollView:source]; + XCTAssertEqualObjects(source.backgroundColor, UIColor.blackColor); + UIColor *replacement = UIColor.blueColor; + source.backgroundColor = replacement; + self.root.backgroundColor = UIColor.whiteColor; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, replacement); + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertEqualObjects(source.backgroundColor, replacement); + source.backgroundColor = UIColor.clearColor; + [self.pager updateTopScrollEdgeForScrollView:source]; + XCTAssertEqualObjects(source.backgroundColor, UIColor.whiteColor); + [self.pager setValue:@YES forKey:@"pendingTopOverlayAppearanceCommit"]; + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertNil([self.pager valueForKey:@"topEdgeScrollView"]); + XCTAssertEqualObjects(source.backgroundColor, UIColor.whiteColor); + [self.root removeFromSuperview]; + XCTAssertEqualObjects(source.backgroundColor, UIColor.clearColor); + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26BackingSurvivesBorrowedOwnerAndRestoresOnRecycle +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"Opaque backing is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *source = nil; + UIScrollView *horizontal = [self prepareDirectDragWithSource:&source]; + self.root.backgroundColor = UIColor.blackColor; + [self.pager updateTopScrollEdgeForScrollView:source]; + UIColor *applied = source.backgroundColor; + XCTAssertEqualObjects(applied, UIColor.blackColor); + [self.pager scrollViewWillBeginDragging:horizontal]; + XCTAssertEqualObjects(source.backgroundColor, applied); + NSArray *pages = [self.pager valueForKey:@"pageControllers"]; + NSArray *owners = [[self.pager valueForKey:@"programmaticScrollEdgeOwners"] copy]; + XCTAssertEqual(owners.count, 3); + NSMutableArray *standIns = [NSMutableArray new]; + for (id owner in owners) { + UIScrollView *list = [owner valueForKey:@"scrollView"]; + XCTAssertEqualObjects(list.backgroundColor, UIColor.blackColor); + if (list != source) { + XCTAssertEqual([owner valueForKey:@"standInScrollView"], list); + [standIns addObject:list]; + } + } + XCTAssertEqual(standIns.count, 2); + for (UIViewController *page in pages) { + UIScrollView *list = (UIScrollView *)page.view.subviews.firstObject; + if (list != source) XCTAssertNil(list.backgroundColor); + } + [self.pager scrollViewDidEndDragging:horizontal willDecelerate:NO]; + XCTestExpectation *settled = [self expectationWithDescription:@"background handoff cleanup"]; + dispatch_async(dispatch_get_main_queue(), ^{ [settled fulfill]; }); + [self waitForExpectations:@[settled] timeout:2]; + XCTAssertEqualObjects(source.backgroundColor, UIColor.blackColor); + [self.pager prepareForRecycle]; + for (UIScrollView *standIn in standIns) { + XCTAssertEqualObjects(standIn.backgroundColor, UIColor.clearColor); + XCTAssertNil(standIn.superview); + } + for (UIViewController *page in pages) { + UIScrollView *list = (UIScrollView *)page.view.subviews.firstObject; + XCTAssertNil(list.backgroundColor); + } + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26EquivalentGetterColorsKeepLeaseThroughThemeAndReacquisition +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"Opaque backing is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *previous = [self preparePinnedLocalHardSource]; + [self.pager updateTopScrollEdgeForScrollView:nil]; + RNCEquivalentBackgroundScrollView *source = [[RNCEquivalentBackgroundScrollView alloc] + initWithFrame:previous.frame]; + source.contentSize = previous.contentSize; + [previous.superview insertSubview:source belowSubview:previous]; + for (UIView *child in previous.subviews.copy) [source addSubview:child]; + [previous removeFromSuperview]; + [self.pager setValue:source forKey:@"observedScrollView"]; + [self.pager setValue:source forKey:@"sharedHeaderScrollView"]; + self.root.backgroundColor = [UIColor colorWithRed:0.06 green:0.06 blue:0.06 alpha:1]; + [self.pager updateTopScrollEdgeForScrollView:source]; + UIColor *first = source.backgroundColor; + UIColor *second = source.backgroundColor; + XCTAssertNotEqual(first, second); + XCTAssertEqualObjects(first, second); + XCTAssertEqualObjects(first, self.root.backgroundColor); + self.root.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, self.root.backgroundColor); + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertNil(source.backgroundColor); + [self.pager updateTopScrollEdgeForScrollView:source]; + XCTAssertEqualObjects(source.backgroundColor, self.root.backgroundColor); + UIColor *replacement = [UIColor colorWithRed:0.8 green:0.1 blue:0.2 alpha:1]; + source.backgroundColor = replacement; + [self.pager syncScrollEdgeAppearance]; + XCTAssertEqualObjects(source.backgroundColor, replacement); + [self.pager updateTopScrollEdgeForScrollView:nil]; + XCTAssertEqualObjects(source.backgroundColor, replacement); + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS27HardEdgesKeepTransparentCallerBacking +{ + if (@available(iOS 27.0, *)) { + UIScrollView *source = nil; + UIScrollView *horizontal = [self prepareDirectDragWithSource:&source]; + self.root.backgroundColor = UIColor.blackColor; + [self.pager updateTopScrollEdgeForScrollView:source]; + XCTAssertNil(source.backgroundColor); + [self.pager scrollViewWillBeginDragging:horizontal]; + XCTAssertNil(source.backgroundColor); + [self.pager prepareForRecycle]; + XCTAssertNil(source.backgroundColor); + } else { + XCTSkip(@"The unchanged transparent-backing control requires iOS 27"); + } +} + +- (RNCAlignedTakeoverScrollView *)prepareAlignedLocalListForDragTakeover +{ + UIScrollView *previous = [self preparePinnedLocalHardSource]; + RNCAlignedTakeoverScrollView *scroll = [[RNCAlignedTakeoverScrollView alloc] initWithFrame:previous.frame]; + scroll.observedPan = [RNCAlignedTakeoverPan new]; + scroll.contentSize = previous.contentSize; + [previous.superview insertSubview:scroll belowSubview:previous]; + [previous removeFromSuperview]; + [self.pager setValue:nil forKey:@"observedScrollView"]; + [self.pager setValue:nil forKey:@"sharedHeaderScrollView"]; + [self.pager setValue:@[@"portfolio"] forKey:@"pageKeys"]; + [self.pager setValue:@0 forKey:@"headerOffset"]; + [self.pager attachScrollObserverForCurrentPage]; + XCTAssertEqual([self.pager valueForKey:@"observedScrollView"], scroll); + XCTAssertTrue([[self.pager valueForKey:@"observingContentOffset"] boolValue]); + [[self.pager valueForKey:@"pendingPageRestoreKeys"] removeAllObjects]; + return scroll; +} + +- (void)testIOS26DraggingAfterPanResetTakesOverAlignedBody +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"The isDragging fallback is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + RNCAlignedTakeoverScrollView *scroll = [self prepareAlignedLocalListForDragTakeover]; + NSMutableSet *aligned = [self.pager valueForKey:@"alignedBodyKeys"]; + NSMutableDictionary *display = [self.pager valueForKey:@"displayBodyOverrides"]; + NSInteger step = 0; + for (NSNumber *state in @[@(UIGestureRecognizerStatePossible), @(UIGestureRecognizerStateEnded)]) { + scroll.observedDragging = NO; + scroll.contentOffset = CGPointMake(0, -scroll.contentInset.top); + [self.pager setValue:@0 forKey:@"headerOffset"]; + [aligned addObject:@"portfolio"]; + display[@"portfolio"] = @94; + scroll.observedPan.observedState = static_cast(state.integerValue); + scroll.observedDragging = YES; + scroll.contentOffset = CGPointMake(0, 140 + step++ * 20 - scroll.contentInset.top); + XCTAssertFalse([aligned containsObject:@"portfolio"]); + XCTAssertNil(display[@"portfolio"]); + XCTAssertEqualWithAccuracy([[self.pager valueForKey:@"headerOffset"] doubleValue], 100, 0.001); + } + scroll.observedDragging = NO; + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26NonDraggingSyntheticAndCommandOffsetsKeepAlignedBody +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"The isDragging fallback is restricted to iOS 26"); + } else if (@available(iOS 26.0, *)) { + RNCAlignedTakeoverScrollView *scroll = [self prepareAlignedLocalListForDragTakeover]; + NSMutableSet *aligned = [self.pager valueForKey:@"alignedBodyKeys"]; + NSMutableSet *commands = [self.pager valueForKey:@"commandBodyKeys"]; + NSMutableDictionary *display = [self.pager valueForKey:@"displayBodyOverrides"]; + NSArray *guards = @[@"not-dragging", @"syntheticPageRestore", @"transitioning", + @"commandBodyKeys", @"headerCommandOwner", @"correctingTopInsetRebound"]; + NSInteger step = 0; + for (NSString *guard in guards) { + scroll.observedDragging = NO; + [self.pager setValue:@NO forKey:@"syntheticPageRestore"]; + [self.pager setValue:@NO forKey:@"transitioning"]; + [self.pager setValue:@NO forKey:@"correctingTopInsetRebound"]; + [self.pager setValue:nil forKey:@"headerCommandOwner"]; + [commands removeAllObjects]; + scroll.contentOffset = CGPointMake(0, -scroll.contentInset.top); + [self.pager setValue:@0 forKey:@"headerOffset"]; + [aligned addObject:@"portfolio"]; + display[@"portfolio"] = @94; + if ([guard isEqualToString:@"commandBodyKeys"]) [commands addObject:@"portfolio"]; + else if ([guard isEqualToString:@"headerCommandOwner"]) [self.pager setValue:scroll forKey:guard]; + else if (![guard isEqualToString:@"not-dragging"]) [self.pager setValue:@YES forKey:guard]; + scroll.observedDragging = ![guard isEqualToString:@"not-dragging"]; + scroll.contentOffset = CGPointMake(0, 140 + step++ * 20 - scroll.contentInset.top); + XCTAssertTrue([aligned containsObject:@"portfolio"], @"%@", guard); + XCTAssertEqualObjects(display[@"portfolio"], @94, @"%@", guard); + XCTAssertEqualWithAccuracy([[self.pager valueForKey:@"headerOffset"] doubleValue], 0, 0.001, @"%@", guard); + } + scroll.observedDragging = NO; + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26ExternalDragDoesNotBorrowTransitionEdges +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"iOS 27 external edge ownership is covered separately"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *horizontal = [self prepareExternalDirectDragWithSource:NULL overlay:NULL]; + [self.pager scrollViewWillBeginDragging:horizontal]; + XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 0); + } else { + XCTSkip(@"External scroll edges require iOS 26 or newer"); + } +} + +- (void)testIOS26AnimatedLocalHardPageCommandSettlesWithBorrowedEdges +{ + if (@available(iOS 27.0, *)) { + XCTSkip(@"iOS 27 native animated-scroll ownership is covered separately"); + } else if (@available(iOS 26.0, *)) { + UIScrollView *source = nil; + UIScrollView *horizontal = [self prepareDirectDragWithSource:&source]; + UIScrollEdgeElementContainerInteraction *top = [self.pager valueForKey:@"topEdgeInteraction"]; + [self.pager goTo:2 animated:YES]; + XCTAssertNil([self.pager valueForKey:@"pendingNativePagerScrollCompletion"]); + XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 2); + XCTAssertEqual(top.scrollView, source); + [self waitForNativeResizeCommandsToSettle]; + XCTAssertEqual([[self.pager valueForKey:@"currentIndex"] integerValue], 2); + XCTAssertEqualWithAccuracy(horizontal.contentOffset.x, 640, 0.001); + XCTAssertEqual([[self.pager valueForKey:@"programmaticScrollEdgeOwners"] count], 0); + XCTAssertNil(top.scrollView); + XCTAssertEqual(source.topEdgeEffect.style, UIScrollEdgeEffectStyle.softStyle); + UIScrollEdgeElementContainerInteraction *settled = [self.pager valueForKey:@"topEdgeInteraction"]; + XCTAssertNotNil(settled); + XCTAssertEqual(settled.scrollView, [self.pager valueForKey:@"observedScrollView"]); + } else { + XCTSkip(@"Local Hard scroll edges require iOS 26 or newer"); } }