Skip to content

[iOS] react-native-screens v4.19.0 breaks the global back swipe gesture on pager views #1050

Closed

Description

@mozzius

Environment

  • iOS 26
  • react-native-screens v4.19.0
  • Any react-native-pager-view version (tested 6.8.0, 6.8.1, 8.0.0)

Description

I have filed the same issue with react-native-screens here: software-mansion/react-native-screens#3512
Since this is an issue with the interaction between these two libraries, I thought it was worth opening one here too.

After upgrading to react-native-screens v4.19.0, the global back gesture does not work if it's on top of a pager view. I would speculate it's due to software-mansion/react-native-screens#3420

Screen.Recording.2026-01-01.at.21.19.54_compressed.mp4

Expected behaviour: I am able to swipe back to the previous screen.

This is exactly the same problem as I have with #1006, except now it's happening on all versions

Reproducible Demo

https://github.com/mozzius/pagerswipe-repro

Activity

  1. mozzius commented on Jan 8, 2026

    @mozzius
    ContributorAuthor

    Dug into it a bit, and it needs to respond to the new iOS26 system back gesture. This patch (for v6.8.0) fixes it

    diff --git a/node_modules/react-native-pager-view/ios/RNCPagerView.m b/node_modules/react-native-pager-view/ios/RNCPagerView.m
    index adfc7c6..366df60 100644
    --- a/node_modules/react-native-pager-view/ios/RNCPagerView.m
    +++ b/node_modules/react-native-pager-view/ios/RNCPagerView.m
    @@ -498,6 +498,25 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
             return YES;
         }
     
    +    // iOS 26+ full-screen back gesture (interactiveContentPopGestureRecognizer)
    +    if (@available(iOS 26, *)) {
    +        if (gestureRecognizer == self.panGestureRecognizer &&
    +            otherGestureRecognizer == self.reactViewController.navigationController.interactiveContentPopGestureRecognizer) {
    +            UIPanGestureRecognizer* panGestureRecognizer = (UIPanGestureRecognizer*) gestureRecognizer;
    +            CGPoint velocity = [panGestureRecognizer velocityInView:self];
    +            BOOL isLTR = [self isLtrLayout];
    +            BOOL isBackGesture = (isLTR && velocity.x > 0) || (!isLTR && velocity.x < 0);
    +
    +            if (self.currentIndex == 0 && isBackGesture) {
    +                self.scrollView.panGestureRecognizer.enabled = false;
    +            } else {
    +                self.scrollView.panGestureRecognizer.enabled = self.scrollEnabled;
    +            }
    +
    +            return YES;
    +        }
    +    }
    +
         self.scrollView.panGestureRecognizer.enabled = self.scrollEnabled;
         return NO;
     }
    
  2. mozzius commented on Jan 8, 2026

    @mozzius
    ContributorAuthor

    cc @okwasniewski - I think the same issue affects v8.0.0

  3. nickbvr commented on Aug 12, 2026

    @nickbvr

    Still reproduces on 8.0.2 + react-native-screens 4.26.2, iOS 26. This patch (for v8.0.2) fixes it.

    diff --git a/ios/PagerGestureObserver.swift b/ios/PagerGestureObserver.swift
    new file mode 100644
    index 0000000000000000000000000000000000000000..9a5d38903e42af859a88abee26054725e34b2717
    --- /dev/null
    +++ b/ios/PagerGestureObserver.swift
    @@ -0,0 +1,123 @@
    +import ObjectiveC
    +import UIKit
    +
    +/**
    + Keeps the pager's pan from swallowing the navigation controller's back gesture.
    +
    + On iOS 26 that gesture spans the whole screen instead of its edge, so a pager on
    + top of it takes every horizontal drag (callstack/react-native-pager-view#1050).
    + Allowing the two to run simultaneously does not help — UIKit still hands the
    + touch to the scroll view — so the pan has to be refused before it begins. That
    + answer belongs to `gestureRecognizerShouldBegin`, which the pan asks its
    + delegate, and UIKit insists that delegate is the scroll view itself. Hence the
    + runtime subclass, the same trick `disableSafeArea()` uses in `Extensions.swift`.
    +
    + Only the first page yields, and only while there is somewhere to go back to;
    + there a back-swipe has nothing to scroll to anyway. Every other drag reaches the
    + original implementation untouched.
    + */
    +final class PagerGestureObserver: NSObject {
    +  var currentPage = 0
    +  var layoutDirection: PagerLayoutDirection = .ltr
    +
    +  private weak var collectionView: UICollectionView?
    +
    +  func attach(to collectionView: UICollectionView) {
    +    guard self.collectionView !== collectionView else { return }
    +
    +    self.collectionView = collectionView
    +    objc_setAssociatedObject(
    +      collectionView,
    +      &PagerGestureObserver.associationKey,
    +      self,
    +      .OBJC_ASSOCIATION_RETAIN_NONATOMIC
    +    )
    +    PagerGestureObserver.installGestureArbitration(on: collectionView)
    +  }
    +
    +  fileprivate func yieldsToBackGesture(in scrollView: UIScrollView) -> Bool {
    +    guard currentPage == 0, canNavigateBack(from: scrollView) else { return false }
    +
    +    let velocity = scrollView.panGestureRecognizer.velocity(in: scrollView)
    +
    +    return layoutDirection == .ltr ? velocity.x > 0 : velocity.x < 0
    +  }
    +
    +  /// Walks the responder chain because the pod does not import React's `UIView`
    +  /// category, so `reactViewController()` is unavailable here.
    +  private func canNavigateBack(from view: UIView) -> Bool {
    +    var responder: UIResponder? = view.next
    +
    +    while let current = responder {
    +      if let navigationController = current as? UINavigationController {
    +        return navigationController.viewControllers.count > 1
    +      }
    +
    +      responder = current.next
    +    }
    +
    +    return false
    +  }
    +}
    +
    +private extension PagerGestureObserver {
    +  static var associationKey: UInt8 = 0
    +  static let subclassSuffix = "_PagerBackGesture"
    +
    +  static func installGestureArbitration(on collectionView: UICollectionView) {
    +    guard let currentClass = object_getClass(collectionView) else { return }
    +
    +    let currentName = String(cString: class_getName(currentClass))
    +
    +    // Already wearing the subclass, e.g. after a recycle.
    +    guard !currentName.hasSuffix(subclassSuffix) else { return }
    +
    +    let subclassName = currentName.appending(subclassSuffix)
    +
    +    if let existing = NSClassFromString(subclassName) {
    +      object_setClass(collectionView, existing)
    +      return
    +    }
    +
    +    let selector = #selector(UIGestureRecognizerDelegate.gestureRecognizerShouldBegin(_:))
    +
    +    guard
    +      let subclassNameUtf8 = (subclassName as NSString).utf8String,
    +      let subclass = objc_allocateClassPair(currentClass, subclassNameUtf8, 0),
    +      let method = class_getInstanceMethod(currentClass, selector)
    +    else { return }
    +
    +    typealias Implementation = @convention(c) (AnyObject, Selector, UIGestureRecognizer) -> Bool
    +
    +    let superImplementation = unsafeBitCast(
    +      method_getImplementation(method),
    +      to: Implementation.self
    +    )
    +
    +    let override: @convention(block) (AnyObject, UIGestureRecognizer) -> Bool = {
    +      object, gestureRecognizer in
    +      if
    +        let scrollView = object as? UIScrollView,
    +        gestureRecognizer === scrollView.panGestureRecognizer,
    +        let observer = objc_getAssociatedObject(
    +          scrollView, &PagerGestureObserver.associationKey
    +        ) as? PagerGestureObserver,
    +        observer.yieldsToBackGesture(in: scrollView)
    +      {
    +        return false
    +      }
    +
    +      return superImplementation(object, selector, gestureRecognizer)
    +    }
    +
    +    class_addMethod(
    +      subclass,
    +      selector,
    +      imp_implementationWithBlock(override),
    +      method_getTypeEncoding(method)
    +    )
    +
    +    objc_registerClassPair(subclass)
    +    object_setClass(collectionView, subclass)
    +  }
    +}
    diff --git a/ios/PagerView.swift b/ios/PagerView.swift
    index 7b296a0ecef30ea331edf97573270c6f9d1541ea..0e800a0d9747c1c9c956782c38c6a799552a559c 100644
    --- a/ios/PagerView.swift
    +++ b/ios/PagerView.swift
    @@ -4,6 +4,7 @@ import SwiftUI
     struct PagerView: View {
       @ObservedObject var props: PagerViewProps
       @State private var scrollDelegate = PagerScrollDelegate()
    +  @State private var gestureObserver = PagerGestureObserver()
       weak var delegate: PagerViewProviderDelegate?
     
       @Weak var collectionView: UICollectionView?
    @@ -39,6 +40,10 @@ struct PagerView: View {
             scrollDelegate.orientation = props.orientation
             collectionView.delegate = scrollDelegate
           }
    +
    +      gestureObserver.attach(to: collectionView)
    +      gestureObserver.currentPage = props.currentPage
    +      gestureObserver.layoutDirection = props.layoutDirection
         }
         .onAppear {
           // Apply initial prop values that .onChange won't catch
    @@ -54,6 +59,7 @@ struct PagerView: View {
           }
         }
         .onChange(of: props.currentPage) { newValue in
    +      gestureObserver.currentPage = newValue
           delegate?.onPageSelected(position: newValue)
         }
         .onChange(of: props.scrollEnabled) { newValue in
  4. added a commit that references this issue on Oct 23, 2026
    c77322a
  5. added a commit that references this issue on Oct 26, 2026
    f24ec8b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions