From 5fc8eade00d35ff4f0611f98dc4095a50286bdd7 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Thu, 22 Oct 2026 15:37:17 +0200 Subject: [PATCH] Split the react-native patch into one file per change (#12143) Co-authored-by: Claude Opus 5.5 --- AGENTS.md | 8 + package.json | 1 + patches/react-native/README.md | 31 ++ .../find-shadow-node-by-tag-race.patch | 37 ++ .../find-shadow-node-by-tag-race.patch.md | 14 + .../hairline-border-contents-center.patch | 23 ++ .../hairline-border-contents-center.patch.md | 18 + .../react-native/pr-54260-581d643a9e.patch | 16 + .../react-native/pr-54260-581d643a9e.patch.md | 4 + .../react-native/pr-56747-efcab20908.patch | 13 + .../react-native/pr-56747-efcab20908.patch.md | 19 + .../react-native/pr-58364-f20f857241.patch | 19 + .../react-native/pr-58364-f20f857241.patch.md | 15 + .../react-native/prepared-text-layout.patch | 334 ++++++++++++++++++ .../prepared-text-layout.patch.md | 37 ++ .../refresh-control-defer-props.patch | 174 +++++++++ .../refresh-control-defer-props.patch.md | 56 +++ .../refresh-control-paper-haptic.patch | 74 ++++ .../refresh-control-paper-haptic.patch.md | 5 + .../scheduler-delegate-invalidation.patch | 15 + .../scheduler-delegate-invalidation.patch.md | 15 + .../scrollview-center-content-insets.patch | 46 +++ .../scrollview-center-content-insets.patch.md | 19 + .../scrollview-disable-recycling.patch | 16 + .../scrollview-disable-recycling.patch.md | 8 + .../text-input-reveal-caret.patch | 63 ++++ .../text-input-reveal-caret.patch.md | 4 + .../view-group-clipping-null-child.patch | 29 ++ .../view-group-clipping-null-child.patch.md | 25 ++ patches/react-native@0.86.3.patch.md | 248 +------------ pnpm-workspace.yaml | 1 + 31 files changed, 1144 insertions(+), 243 deletions(-) create mode 100644 patches/react-native/README.md create mode 100644 patches/react-native/find-shadow-node-by-tag-race.patch create mode 100644 patches/react-native/find-shadow-node-by-tag-race.patch.md create mode 100644 patches/react-native/hairline-border-contents-center.patch create mode 100644 patches/react-native/hairline-border-contents-center.patch.md create mode 100644 patches/react-native/pr-54260-581d643a9e.patch create mode 100644 patches/react-native/pr-54260-581d643a9e.patch.md create mode 100644 patches/react-native/pr-56747-efcab20908.patch create mode 100644 patches/react-native/pr-56747-efcab20908.patch.md create mode 100644 patches/react-native/pr-58364-f20f857241.patch create mode 100644 patches/react-native/pr-58364-f20f857241.patch.md create mode 100644 patches/react-native/prepared-text-layout.patch create mode 100644 patches/react-native/prepared-text-layout.patch.md create mode 100644 patches/react-native/refresh-control-defer-props.patch create mode 100644 patches/react-native/refresh-control-defer-props.patch.md create mode 100644 patches/react-native/refresh-control-paper-haptic.patch create mode 100644 patches/react-native/refresh-control-paper-haptic.patch.md create mode 100644 patches/react-native/scheduler-delegate-invalidation.patch create mode 100644 patches/react-native/scheduler-delegate-invalidation.patch.md create mode 100644 patches/react-native/scrollview-center-content-insets.patch create mode 100644 patches/react-native/scrollview-center-content-insets.patch.md create mode 100644 patches/react-native/scrollview-disable-recycling.patch create mode 100644 patches/react-native/scrollview-disable-recycling.patch.md create mode 100644 patches/react-native/text-input-reveal-caret.patch create mode 100644 patches/react-native/text-input-reveal-caret.patch.md create mode 100644 patches/react-native/view-group-clipping-null-child.patch create mode 100644 patches/react-native/view-group-clipping-null-child.patch.md diff --git a/AGENTS.md b/AGENTS.md index 9f3c1645b..ae793d3dd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -570,6 +570,14 @@ Only use `useMemo`/`useCallback` when you have a specific reason, such as: - The value is immediately used in an effect's dependency array - You're passing a callback to a non-React library that needs referential stability +### Patching react-native + +`patches/react-native@.patch` is generated - don't edit it or use +`pnpm patch react-native` directly. Each change lives in `patches/react-native/` +as its own patch against pristine react-native, with a `.patch.md` explaining +it. After adding or changing one, run `pnpm patch:react-native` to rebuild the +combined patch. See `patches/react-native/README.md`. + ## Best Practices 1. **Accessibility**: Always provide `label` prop for interactive elements, use `accessibilityHint` where helpful diff --git a/package.json b/package.json index df312725a..f3f1101a9 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "prepare": "is-ci || husky", "postinstall": "pnpm lexicons:generate && pnpm intl:compile-if-needed", "prebuild": "EXPO_NO_GIT_STATUS=1 expo prebuild --clean", + "patch:react-native": "rm -rf node_modules/.patch-react-native && pnpm patch react-native@0.86.3 --ignore-existing --edit-dir node_modules/.patch-react-native && git apply --directory=node_modules/.patch-react-native patches/react-native/*.patch && pnpm patch-commit node_modules/.patch-react-native && pnpm update react-native --depth 0", "android": "expo run:android --variant debugOptimized", "android:prod": "expo run:android --variant release", "android:profile": "BSKY_PROFILE=1 expo run:android --variant release", diff --git a/patches/react-native/README.md b/patches/react-native/README.md new file mode 100644 index 000000000..21c7c8b57 --- /dev/null +++ b/patches/react-native/README.md @@ -0,0 +1,31 @@ +# react-native patches + +pnpm supports one patch per package, so `patches/react-native@.patch` +is generated from the patches in this directory. Each one is a diff against +pristine react-native and has a `.patch.md` explaining it. Patches that +backport an upstream PR are named `pr--.patch`, using the +first 10 characters of the commit that landed (or of the PR head). + +Regenerate the combined patch after any change here: + +```sh +pnpm patch:react-native +``` + +## Editing a patch + +```sh +pnpm patch react-native@ --ignore-existing --edit-dir node_modules/.edit-react-native +cd node_modules/.edit-react-native +git init -q && git add -A && git commit -qm pristine +git apply ../../patches/react-native/.patch # skip for a new patch +# edit files, then: +git add -A && git diff --cached > ../../patches/react-native/.patch +``` + +## Upgrading react-native + +Update the version in the `patch:react-native` script, remove the old entry +from `patchedDependencies` in `pnpm-workspace.yaml` along with the old combined +patch, and regenerate. For patches that no longer apply, follow the steps above +with `git apply --reject` and port the `.rej` hunks by hand. diff --git a/patches/react-native/find-shadow-node-by-tag-race.patch b/patches/react-native/find-shadow-node-by-tag-race.patch new file mode 100644 index 000000000..514c5df55 --- /dev/null +++ b/patches/react-native/find-shadow-node-by-tag-race.patch @@ -0,0 +1,37 @@ +diff --git a/ReactCommon/react/renderer/uimanager/UIManager.cpp b/ReactCommon/react/renderer/uimanager/UIManager.cpp +index 4d64040..ecbd4bd 100644 +--- a/ReactCommon/react/renderer/uimanager/UIManager.cpp ++++ b/ReactCommon/react/renderer/uimanager/UIManager.cpp +@@ -535,30 +535,8 @@ std::shared_ptr UIManager::findShadowNodeByTag_DEPRECATED( + auto shadowNode = std::shared_ptr{}; + + shadowTreeRegistry_.enumerate([&](const ShadowTree& shadowTree, bool& stop) { +- // Obtain a pointer to the root node. The flag-gated path uses +- // getCurrentRevision() which keeps the root alive via shared_ptr for +- // the entire traversal, fixing a use-after-free race condition. +- RootShadowNode::Shared rootShadowNodeHolder; +- const RootShadowNode* rootShadowNode = nullptr; +- if (ReactNativeFeatureFlags::fixFindShadowNodeByTagRaceCondition()) { +- rootShadowNodeHolder = shadowTree.getCurrentRevision().rootShadowNode; +- rootShadowNode = rootShadowNodeHolder.get(); +- } else { +- // TODO(T257154369): Remove after flag rollout. +- // The public interface of `ShadowTree` discourages accessing a stored +- // pointer to a root node because of the possible data race. +- // To work around this, we ask for a commit and immediately cancel it +- // returning `nullptr` instead of a new shadow tree. +- // We don't want to add a way to access a stored pointer to a root +- // node because this `findShadowNodeByTag` is deprecated. It is only +- // added to make migration to the new architecture easier. +- shadowTree.tryCommit( +- [&](const RootShadowNode& oldRootShadowNode) { +- rootShadowNode = &oldRootShadowNode; +- return nullptr; +- }, +- {/* default commit options */}); +- } ++ auto rootShadowNodeHolder = shadowTree.getCurrentRevision().rootShadowNode; ++ const auto* rootShadowNode = rootShadowNodeHolder.get(); + + if (rootShadowNode != nullptr) { + const auto& children = rootShadowNode->getChildren(); diff --git a/patches/react-native/find-shadow-node-by-tag-race.patch.md b/patches/react-native/find-shadow-node-by-tag-race.patch.md new file mode 100644 index 000000000..54c7d817c --- /dev/null +++ b/patches/react-native/find-shadow-node-by-tag-race.patch.md @@ -0,0 +1,14 @@ +## UIManager.cpp Patch - Fabric focus navigation use-after-free + +Fixes Sentry issue APP-T4H9: a SIGSEGV in +`FabricUIManagerBinding::findNextFocusableElement` during focus navigation. + +React Native 0.86 contains the safe implementation behind +`fixFindShadowNodeByTagRaceCondition`, but the public default is false. The +fallback captures a raw root shadow-node pointer in `tryCommit` and dereferences +it after the lock is released, allowing a concurrent commit or surface stop to +free the node first. This backports the final upstream implementation, which +holds the current revision's `shared_ptr` for the entire traversal. + +**TODO: Remove after bumping React Native to a release containing +facebook/react-native#56850.** diff --git a/patches/react-native/hairline-border-contents-center.patch b/patches/react-native/hairline-border-contents-center.patch new file mode 100644 index 000000000..0b207280d --- /dev/null +++ b/patches/react-native/hairline-border-contents-center.patch @@ -0,0 +1,23 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +index b033b7c..7e10dc9 100644 +--- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +@@ -827,9 +827,17 @@ static void RCTAddContourEffectToLayer( + } else { + CGSize imageSize = image.size; + UIEdgeInsets imageCapInsets = image.capInsets; ++ // The stretchable middle is whatever lies between the cap insets. The image ++ // may be larger than capInsets + 1 (its size is ceil'd to whole points), so ++ // deriving the middle from the caps rather than assuming a 1pt band keeps ++ // the bottom/right caps at their true size. A phantom cap here makes the ++ // caps overflow sub-pixel-sized layers (e.g. hairline borders), and the ++ // squeezed mesh + nearest-neighbor filtering drops the stroke entirely. + CGRect contentsCenter = CGRect{ + CGPoint{imageCapInsets.left / imageSize.width, imageCapInsets.top / imageSize.height}, +- CGSize{(CGFloat)1.0 / imageSize.width, (CGFloat)1.0 / imageSize.height}}; ++ CGSize{ ++ (imageSize.width - imageCapInsets.left - imageCapInsets.right) / imageSize.width, ++ (imageSize.height - imageCapInsets.top - imageCapInsets.bottom) / imageSize.height}}; + layer.contents = (id)image.CGImage; + layer.contentsScale = image.scale; + diff --git a/patches/react-native/hairline-border-contents-center.patch.md b/patches/react-native/hairline-border-contents-center.patch.md new file mode 100644 index 000000000..72ebb9445 --- /dev/null +++ b/patches/react-native/hairline-border-contents-center.patch.md @@ -0,0 +1,18 @@ +## RCTViewComponentView.mm Patch - Hairline border strokes dropped at certain subpixel Y offsets on New Arch + +Symptom: dividers built as `borderTopWidth: hairlineWidth` vanish on some screens and not +others, deterministically by the view's absolute subpixel Y. A background fill of the same +geometry always renders. + +Cause: Fabric draws borders as a stretched 9-slice image. The consumer +(`RCTAddContourEffectToLayer`) hardcodes the stretchable middle as a 1pt band, which matched +the image the producer built until RN 0.81. facebook/react-native#54237 changed the image +size to `ceil(insets) + 1 + ceil(insets)` without updating that formula, so for fractional +(hairline) insets the labels no longer match the image: transparent filler is treated as a +rigid cap, and when squeezed into a one-pixel-tall layer the sampling can land on it instead +of the stroke - no line. + +Fix: compute the middle from the cap insets (`size - caps`) instead of assuming 1pt. + +Upstream issue: https://github.com/react/react-native/issues/58054 (repro: +https://github.com/abulenok/HairlineBorderRepro, fails identically on 0.86.0 and 0.87.0). diff --git a/patches/react-native/pr-54260-581d643a9e.patch b/patches/react-native/pr-54260-581d643a9e.patch new file mode 100644 index 000000000..713cc07ee --- /dev/null +++ b/patches/react-native/pr-54260-581d643a9e.patch @@ -0,0 +1,16 @@ +diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +index ac55304..d99c8f4 100644 +--- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm ++++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +@@ -389,8 +389,9 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage + size.height = enumeratedLinesHeight; + } + +- size = (CGSize){ceil(size.width * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor, +- ceil(size.height * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor}; ++ CGFloat epsilon = 0.001; ++ size = (CGSize){ceil((size.width + epsilon) * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor, ++ ceil((size.height + epsilon) * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor}; + + NSRange visibleGlyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; + diff --git a/patches/react-native/pr-54260-581d643a9e.patch.md b/patches/react-native/pr-54260-581d643a9e.patch.md new file mode 100644 index 000000000..e05fc767c --- /dev/null +++ b/patches/react-native/pr-54260-581d643a9e.patch.md @@ -0,0 +1,4 @@ +## RCTTextLayoutManager.mm Patch - Text overflows instead of wrapping on the last line + +Issue: https://github.com/react/react-native/issues/53450#issuecomment-3298157830 +Bandaid fix taken from: https://github.com/react/react-native/commit/581d643a9e59fd88f93757f80194e1efd11bd0e5 diff --git a/patches/react-native/pr-56747-efcab20908.patch b/patches/react-native/pr-56747-efcab20908.patch new file mode 100644 index 000000000..d46c089b1 --- /dev/null +++ b/patches/react-native/pr-56747-efcab20908.patch @@ -0,0 +1,13 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +index 9ab1db4..02d9907 100644 +--- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +@@ -523,7 +523,7 @@ - (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event + } + } + +- return isPointInside ? self : nil; ++ return isPointInside ? _scrollView : nil; + } + + /* diff --git a/patches/react-native/pr-56747-efcab20908.patch.md b/patches/react-native/pr-56747-efcab20908.patch.md new file mode 100644 index 000000000..112aa6398 --- /dev/null +++ b/patches/react-native/pr-56747-efcab20908.patch.md @@ -0,0 +1,19 @@ +## RCTScrollViewComponentView.mm Patch - ScrollView pinch/pan ignored outside content area on New Arch + +**TODO: Remove after bumping React Native to 0.87+** (fixed upstream by facebook/react-native#56747, +commit efcab20908; first shipped in 0.87.0-rc.0). + +On Fabric, `betterHitTest` in `RCTScrollViewComponentView` deliberately skips the `_containerView` +and hit-tests its grandchildren, returning `self` (the wrapper component view) when the touch lands +inside the scroll view bounds but outside any content. UIKit only delivers touches to a gesture +recognizer when the hit view is the recognizer's view or a descendant of it, and the `UIScrollView` +is a *child* of the wrapper - so its native pinch/pan recognizers never see those touches. In the +lightbox this means pinch-to-zoom and pan-while-zoomed only respond when the fingers are over the +image itself, not over the letterbox bars above/below it. On the old architecture, default UIKit +hit-testing returns the `UIScrollView` itself for those touches, so everything works. + +Backport of the upstream one-liner: return `_scrollView` instead of `self` so touches in the +content-less area are attributed to the `UIScrollView`. + +Issue: https://github.com/facebook/react-native/issues/54123 +PR: https://github.com/react/react-native/pull/56747 diff --git a/patches/react-native/pr-58364-f20f857241.patch b/patches/react-native/pr-58364-f20f857241.patch new file mode 100644 index 000000000..ba32d7cab --- /dev/null +++ b/patches/react-native/pr-58364-f20f857241.patch @@ -0,0 +1,19 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +index c27f816..a779613 100644 +--- a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +@@ -159,7 +159,13 @@ - (void)dismissViewController:(UIViewController *)modalViewController + animated:(BOOL)animated + completion:(void (^)(void))completion + { +- [modalViewController dismissViewControllerAnimated:animated completion:completion]; ++ if (modalViewController.presentedViewController) { ++ // Dismissing a controller that is itself presenting only dismisses its child, so dismiss both. ++ UIViewController *presentingViewController = modalViewController.presentingViewController ?: modalViewController; ++ [presentingViewController dismissViewControllerAnimated:animated completion:completion]; ++ } else { ++ [modalViewController dismissViewControllerAnimated:animated completion:completion]; ++ } + } + + - (void)ensurePresentedOnlyIfNeeded diff --git a/patches/react-native/pr-58364-f20f857241.patch.md b/patches/react-native/pr-58364-f20f857241.patch.md new file mode 100644 index 000000000..63a8d5018 --- /dev/null +++ b/patches/react-native/pr-58364-f20f857241.patch.md @@ -0,0 +1,15 @@ +## RCTModalHostViewComponentView.mm Patch - Blank sheet when dismissing a modal with a child controller + +Fixes https://github.com/bluesky-social/social-app/issues/11393: showing the iOS +Undo Typing alert while submitting a post or reply can leave an empty composer +sheet that cannot be dismissed. UIKit dismisses only the child controller when +the modal itself receives `dismissViewControllerAnimated:completion:`. + +Backport of https://github.com/react/react-native/pull/58364, commit +`3f556d7574999bcba5fa8a1ba70de57346284463`: when a child is presented, dismiss +through the modal's presenting controller to close the entire stack. Fall back +to the modal if its presenting controller is nil, and keep direct dismissal when +there is no child. + +**TODO: Remove after upgrading to a React Native release containing this fix.** +The upstream PR is still open as of September 9, 2026. diff --git a/patches/react-native/prepared-text-layout.patch b/patches/react-native/prepared-text-layout.patch new file mode 100644 index 000000000..470988e69 --- /dev/null +++ b/patches/react-native/prepared-text-layout.patch @@ -0,0 +1,334 @@ +diff --git a/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp b/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp +index 17b14c4..9c46cd9 100644 +--- a/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp ++++ b/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp +@@ -315,6 +315,12 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) { + + auto measuredLayout = findUsableLayout(); + ++#ifdef __APPLE__ ++ // [Bluesky] The text view redraws when its attributed string changes. ++ const bool attributedStringChanged = ++ !(getStateData().attributedString == content.attributedString); ++#endif ++ + if constexpr ( + TextLayoutManagerExtended::supportsPreparedTextLayout() && + std::is_constructible_v< +@@ -342,6 +348,18 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) { + updateStateIfNeeded(content); + } + ++#ifdef __APPLE__ ++ // [Bluesky] Lay the text out now, off the main thread, for the content frame ++ // the text view will draw into. Otherwise its first draw does it on the main ++ // thread. ++ if (attributedStringChanged && !content.attributedString.isEmpty()) { ++ textLayoutManager_->prepareForDrawing( ++ content.attributedString, ++ content.paragraphAttributes, ++ layoutMetrics.getContentFrame().size); ++ } ++#endif ++ + TextLayoutContext textLayoutContext{ + .pointScaleFactor = layoutContext.pointScaleFactor, + .surfaceId = getSurfaceId(), +diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h +index a4b9be7..a6e2fe7 100644 +--- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h ++++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h +@@ -37,6 +37,15 @@ using RCTTextLayoutFragmentEnumerationBlock = + layoutContext:(facebook::react::TextLayoutContext)layoutContext + layoutConstraints:(facebook::react::LayoutConstraints)layoutConstraints; + ++/** ++ * [Bluesky] Lays out `attributedString` for a text view with a content frame ++ * of `size`, so that drawAttributedString: at that size doesn't lay it out ++ * again on the main thread. Can be called from any thread. ++ */ ++- (void)prepareAttributedStringForDrawing:(facebook::react::AttributedString)attributedString ++ paragraphAttributes:(facebook::react::ParagraphAttributes)paragraphAttributes ++ size:(CGSize)size; ++ + - (void)drawAttributedString:(facebook::react::AttributedString)attributedString + paragraphAttributes:(facebook::react::ParagraphAttributes)paragraphAttributes + frame:(CGRect)frame +diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +index ac55304..994c66b 100644 +--- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm ++++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +@@ -14,11 +14,133 @@ + #import + #import + #import ++#import ++ ++#include ++#include ++#include ++#include ++#include + + using namespace facebook::react; + ++/* ++ * [Bluesky] Text layouts made off the main thread, so that a text view's first ++ * draw doesn't lay its text out again on the main thread. ++ * ++ * - Measuring keeps its laid-out text storage ("measured layouts"). ++ * - After layout, ParagraphShadowNode asks for the text of every text view ++ * whose content changed to be prepared at its final content frame size ++ * ("prepared layouts"). That reuses a measured layout when it lays out the ++ * same way, or lays the text out at exactly the frame size, as the draw ++ * would. ++ * - The draw takes the prepared layout for its exact size and otherwise lays ++ * the text out itself, as React Native does by default. ++ */ ++namespace { ++ ++struct RCTTextLayoutKey { ++ AttributedString attributedString; ++ ParagraphAttributes paragraphAttributes; ++ ++ bool operator==(const RCTTextLayoutKey &rhs) const ++ { ++ return attributedString == rhs.attributedString && paragraphAttributes == rhs.paragraphAttributes; ++ } ++}; ++ ++struct RCTTextLayoutKeyHash { ++ size_t operator()(const RCTTextLayoutKey &key) const ++ { ++ return hash_combine(key.attributedString, key.paragraphAttributes); ++ } ++}; ++ ++struct RCTTextLayout { ++ NSTextStorage *textStorage; ++ // Size of the frame the text was laid out for. For measured layouts, the ++ // width of the text container and the measured height. ++ CGSize size; ++}; ++ ++/* ++ * Text layouts waiting to be taken, a few per key. Each layout is handed out ++ * once, so only one thread uses a text storage at a time. Keys that are never ++ * taken (text that is never drawn, or drawn at another size) are evicted ++ * oldest-first. ++ */ ++template ++class RCTTextLayoutPool { ++ public: ++ void add(const RCTTextLayoutKey &key, RCTTextLayout layout) ++ { ++ std::lock_guard lock(mutex_); ++ auto &layouts = layouts_[key]; ++ if (layouts.empty()) { ++ order_.push_back(key); ++ } ++ if (layouts.size() >= maxPerKey_) { ++ layouts.erase(layouts.begin()); ++ } ++ layouts.push_back(std::move(layout)); ++ ++ while (order_.size() > maxKeys_) { ++ // A taken key stays in order_, so this can drop a newer layout for the ++ // same text. That text then just takes the default path. ++ layouts_.erase(order_.front()); ++ order_.pop_front(); ++ } ++ } ++ ++ /* ++ * Removes and returns the newest layout for `key` that satisfies `matches`. ++ */ ++ NSTextStorage *_Nullable take(const RCTTextLayoutKey &key, const std::function &matches) ++ { ++ std::lock_guard lock(mutex_); ++ auto it = layouts_.find(key); ++ if (it == layouts_.end()) { ++ return nil; ++ } ++ ++ auto &layouts = it->second; ++ for (auto layout = layouts.rbegin(); layout != layouts.rend(); ++layout) { ++ if (matches(layout->size)) { ++ NSTextStorage *textStorage = layout->textStorage; ++ layouts.erase(std::next(layout).base()); ++ if (layouts.empty()) { ++ layouts_.erase(it); ++ } ++ return textStorage; ++ } ++ } ++ ++ return nil; ++ } ++ ++ private: ++ std::mutex mutex_; ++ std::unordered_map, RCTTextLayoutKeyHash> layouts_; ++ std::deque order_; ++}; ++ ++// Yoga rounds frames to the pixel grid, so a frame can differ from the ++// measured size by a fraction of a point. ++constexpr CGFloat kRCTMeasuredTextLayoutTolerance = 0.5; ++// Prepared layouts are made for the same frame size the draw uses. ++constexpr CGFloat kRCTPreparedTextLayoutTolerance = 0.01; ++ ++} // namespace ++ + @implementation RCTTextLayoutManager { + SimpleThreadSafeCache, 256> _cache; ++ /* ++ * [Bluesky] See RCTTextLayoutPool. Yoga measures every text in a commit ++ * before any of them is prepared, and a screen can have a few hundred. Texts ++ * are often measured more than once while Yoga resolves flex sizes. ++ */ ++ RCTTextLayoutPool<512, 3> _measuredLayouts; ++ RCTTextLayoutPool<512, 2> _preparedLayouts; + } + + static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsizeMode) +@@ -60,10 +182,67 @@ - (TextMeasurement)measureAttributedString:(AttributedString)attributedString + layoutContext:(TextLayoutContext)layoutContext + layoutConstraints:(LayoutConstraints)layoutConstraints + { +- return [self measureNSAttributedString:[self _nsAttributedStringFromAttributedString:attributedString] +- paragraphAttributes:paragraphAttributes +- layoutContext:layoutContext +- layoutConstraints:layoutConstraints]; ++ NSAttributedString *nsAttributedString = [self _nsAttributedStringFromAttributedString:attributedString]; ++ if (nsAttributedString.length == 0) { ++ // See measureNSAttributedString:. ++ return {}; ++ } ++ ++ CGSize maximumSize = CGSize{layoutConstraints.maximumSize.width, CGFLOAT_MAX}; ++ NSTextStorage *textStorage = [self _textStorageAndLayoutManagerWithAttributesString:nsAttributedString ++ paragraphAttributes:paragraphAttributes ++ size:maximumSize]; ++ TextMeasurement measurement = [self _measureTextStorage:textStorage ++ paragraphAttributes:paragraphAttributes ++ layoutContext:layoutContext]; ++ ++ // [Bluesky] Font scaling depends on the final frame size, so those layouts ++ // can't be reused. ++ if (!paragraphAttributes.adjustsFontSizeToFit && isfinite(maximumSize.width)) { ++ _measuredLayouts.add( ++ RCTTextLayoutKey{.attributedString = attributedString, .paragraphAttributes = paragraphAttributes}, ++ RCTTextLayout{.textStorage = textStorage, .size = CGSize{maximumSize.width, measurement.size.height}}); ++ } ++ ++ return measurement; ++} ++ ++- (void)prepareAttributedStringForDrawing:(AttributedString)attributedString ++ paragraphAttributes:(ParagraphAttributes)paragraphAttributes ++ size:(CGSize)size ++{ ++ if (size.width <= 0 || size.height <= 0) { ++ return; ++ } ++ ++ RCTTextLayoutKey key{.attributedString = attributedString, .paragraphAttributes = paragraphAttributes}; ++ ++ /* ++ * Measuring lays text out at the full available width with unlimited ++ * height. That gives the same result as a layout at `size` when the width ++ * is the same and the frame is tall enough for every measured line. ++ */ ++ NSTextStorage *textStorage = paragraphAttributes.adjustsFontSizeToFit ++ ? nil ++ : _measuredLayouts.take(key, [&](CGSize measured) { ++ return fabs(measured.width - size.width) <= kRCTMeasuredTextLayoutTolerance && ++ size.height >= measured.height - kRCTMeasuredTextLayoutTolerance; ++ }); ++ ++ if (textStorage == nil) { ++ NSAttributedString *nsAttributedString = [self _nsAttributedStringFromAttributedString:attributedString]; ++ if (nsAttributedString.length == 0) { ++ return; ++ } ++ // Exactly what drawAttributedString: would make for this size. ++ textStorage = [self _textStorageAndLayoutManagerWithAttributesString:nsAttributedString ++ paragraphAttributes:paragraphAttributes ++ size:size]; ++ NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject; ++ [layoutManager ensureLayoutForTextContainer:layoutManager.textContainers.firstObject]; ++ } ++ ++ _preparedLayouts.add(key, RCTTextLayout{.textStorage = textStorage, .size = size}); + } + + - (void)drawAttributedString:(AttributedString)attributedString +@@ -71,10 +250,20 @@ - (void)drawAttributedString:(AttributedString)attributedString + frame:(CGRect)frame + drawHighlightPath:(void (^_Nullable)(UIBezierPath *highlightPath))block + { +- NSTextStorage *textStorage = [self +- _textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString] +- paragraphAttributes:paragraphAttributes +- size:frame.size]; ++ // [Bluesky] Use the layout prepared off the main thread for this size, if ++ // any. Otherwise lay the text out here, as React Native does by default. ++ NSTextStorage *textStorage = _preparedLayouts.take( ++ RCTTextLayoutKey{.attributedString = attributedString, .paragraphAttributes = paragraphAttributes}, ++ [&](CGSize prepared) { ++ return fabs(prepared.width - frame.size.width) <= kRCTPreparedTextLayoutTolerance && ++ fabs(prepared.height - frame.size.height) <= kRCTPreparedTextLayoutTolerance; ++ }); ++ if (textStorage == nil) { ++ textStorage = [self ++ _textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString] ++ paragraphAttributes:paragraphAttributes ++ size:frame.size]; ++ } + NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject; + NSTextContainer *textContainer = layoutManager.textContainers.firstObject; + +diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h +index ce564b0..c842534 100644 +--- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h ++++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h +@@ -61,6 +61,16 @@ class TextLayoutManager { + */ + std::shared_ptr getNativeTextLayoutManager() const; + ++ /* ++ * [Bluesky] Lays out `attributedString` ahead of time for a text view whose ++ * content frame has `size`, so its first draw on the main thread can reuse ++ * it. ++ */ ++ void prepareForDrawing( ++ const AttributedString &attributedString, ++ const ParagraphAttributes ¶graphAttributes, ++ const Size &size) const; ++ + protected: + std::shared_ptr contextContainer_; + std::shared_ptr nativeTextLayoutManager_; +diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm +index cddafb5..c31e530 100644 +--- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm ++++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm +@@ -99,6 +99,17 @@ + return measurement; + } + ++void TextLayoutManager::prepareForDrawing( ++ const AttributedString &attributedString, ++ const ParagraphAttributes ¶graphAttributes, ++ const Size &size) const ++{ ++ RCTTextLayoutManager *textLayoutManager = (RCTTextLayoutManager *)unwrapManagedObject(nativeTextLayoutManager_); ++ [textLayoutManager prepareAttributedStringForDrawing:attributedString ++ paragraphAttributes:paragraphAttributes ++ size:CGSizeMake(size.width, size.height)]; ++} ++ + LinesMeasurements TextLayoutManager::measureLines( + const AttributedStringBox &attributedStringBox, + const ParagraphAttributes ¶graphAttributes, diff --git a/patches/react-native/prepared-text-layout.patch.md b/patches/react-native/prepared-text-layout.patch.md new file mode 100644 index 000000000..60c6385fd --- /dev/null +++ b/patches/react-native/prepared-text-layout.patch.md @@ -0,0 +1,37 @@ +## RCTTextLayoutManager.mm / TextLayoutManager / ParagraphShadowNode.cpp Patch - text laid out on the main thread when first drawn + +The first time a text view draws, `drawAttributedString:` runs on the main +thread and lays the text out from scratch: it rebuilds the attributed string +(font lookups), attaches a new layout manager (font fixing, glyph generation) +and lays out every line. Measurement already did the same work off the main +thread, but throws it away. Painting the glyphs is only a small part of the +cost. While scrolling the feed this was the largest single main-thread cost +when new posts appear. React Native's `enablePreparedTextLayout` flag solves +this only on Android. + +- After layout, `ParagraphShadowNode::layout` calls the new + `TextLayoutManager::prepareForDrawing` whenever a text view's attributed + string changes, which is when the view redraws. It passes the content frame + size the view will draw into. This only compiles on Apple platforms. +- `prepareAttributedStringForDrawing:` makes the layout the draw would make + for that size, on the calling thread (usually the JS thread). If measuring + already laid the text out at the same width (within 0.5pt of pixel + rounding), and the frame is tall enough for every measured line, it reuses + that layout. Measurement uses unlimited height, so the result is the same. + Otherwise it lays the text out at exactly that size. +- `drawAttributedString:` takes the prepared layout for its exact frame size. + If there is none (for example, the frame changed without new text), it lays + the text out as before. +- Layouts are handed out once, so only one thread uses a text storage at a + time. Unused ones (text that is never drawn) are evicted oldest-first, with + at most 512 texts kept per kind. +- Measured layouts are never reused for `adjustsFontSizeToFit`, whose font size + depends on the final frame. + +Measured on an iPhone 16 Pro Max (Release build, 30s fling through the feed): +main-thread time in `drawAttributedString:` went from about 570ms to 160ms, all +draws on launch used a prepared layout, and the JS thread spent about 300ms +preparing text. About half of the prepared layouts are never drawn (text in +views that are offscreen or replaced before mounting). + +**TODO: Re-evaluate on React Native upgrades.** Not an upstream backport. diff --git a/patches/react-native/refresh-control-defer-props.patch b/patches/react-native/refresh-control-defer-props.patch new file mode 100644 index 000000000..b051bd48a --- /dev/null +++ b/patches/react-native/refresh-control-defer-props.patch @@ -0,0 +1,174 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +index 60160ef..fb646fe 100644 +--- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +@@ -42,6 +42,32 @@ - (void)setRefreshing:(BOOL)refreshing + @implementation RCTPullToRefreshViewComponentView { + UIRefreshControl *_refreshControl; + RCTScrollViewComponentView *__weak _scrollViewComponentView; ++ /* ++ * Deferred props: updateProps runs during the Create mount mutation, before ++ * _attach puts the control on the scroll view, and writes to a detached ++ * UIRefreshControl are hazardous: ++ * ++ * - tintColor: writing it to a detached control permanently suppresses the ++ * pull-to-refresh trigger haptic on iOS 17.4+ ++ * (https://github.com/facebook/react-native/issues/43388). ++ * ++ * - progressViewOffset (the bounds.origin shift): on iOS 26 the control's ++ * _UIRefreshControlModernContentView positions itself at whatever ++ * bounds.origin it observes when it is CREATED - at insertion into the ++ * scroll view, or earlier if a pre-attach property write materializes it - ++ * and keeps that y forever (width tracks, y never re-pins; verified via ++ * on-device frame logging, Aug 2026). A pre-attach shift is therefore ++ * baked into the content view's own frame and cancelled exactly, hiding ++ * the spinner. Applied post-attach, the content view has already been ++ * created at origin 0 and the same bounds shift works as intended. ++ * ++ * Both props are parked here and applied only once the control is inside ++ * the scroll view. ++ */ ++ UIColor *_pendingTintColor; ++ BOOL _hasPendingTintColor; ++ CGFloat _pendingProgressViewOffset; ++ BOOL _hasPendingProgressViewOffset; + // This variable keeps track of whether the view is recycled or not. Once the view is recycled, the component + // creates a new instance of UIRefreshControl, resetting the native props to the default values. + // However, when recycling, we are keeping around the old _props. The flag is used to force the application +@@ -79,10 +105,25 @@ + (ComponentDescriptorProvider)componentDescriptorProvider + return concreteComponentDescriptorProvider(); + } + ++// Recycled instances get all props force-applied in updateProps, which runs ++// before the new UIRefreshControl is inserted into the scroll view hierarchy; ++// touching the control that early suppresses the pull-to-refresh haptic on ++// iOS 17.4+ (react-native#43388). Opting out of recycling keeps every mount on ++// the untouched-before-attach path. Refresh controls are rare and cheap, so ++// losing recycling for them is negligible. +++ (BOOL)shouldBeRecycled ++{ ++ return NO; ++} ++ + - (void)prepareForRecycle + { + [super prepareForRecycle]; + _scrollViewComponentView = nil; ++ _pendingTintColor = nil; ++ _hasPendingTintColor = NO; ++ _pendingProgressViewOffset = 0; ++ _hasPendingProgressViewOffset = NO; + [self _initializeUIRefreshControl]; + _recycled = YES; + } +@@ -93,7 +134,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & + const auto &newConcreteProps = static_cast(*props); + + if (_recycled || newConcreteProps.tintColor != oldConcreteProps.tintColor) { +- _refreshControl.tintColor = RCTUIColorFromSharedColor(newConcreteProps.tintColor); ++ // Deferred until the control is inside the scroll view (#43388). ++ [self _updateTintColor:RCTUIColorFromSharedColor(newConcreteProps.tintColor)]; + } + + if (_recycled || newConcreteProps.progressViewOffset != oldConcreteProps.progressViewOffset) { +@@ -141,11 +183,50 @@ - (void)handleUIControlEventValueChanged + + - (void)_updateProgressViewOffset:(Float)progressViewOffset + { ++ _pendingProgressViewOffset = progressViewOffset; ++ _hasPendingProgressViewOffset = YES; ++ // Applies immediately for runtime changes while the control is attached; ++ // pre-attach sets wait until the control is inside the scroll view (see the ++ // _pendingProgressViewOffset declaration). ++ [self _applyPendingProgressViewOffsetIfPossible]; ++ if (_hasPendingProgressViewOffset) { ++ [self setNeedsLayout]; ++ } ++} ++ ++- (void)_applyPendingProgressViewOffsetIfPossible ++{ ++ if (!_hasPendingProgressViewOffset || ![_refreshControl.superview isKindOfClass:[UIScrollView class]]) { ++ return; ++ } + _refreshControl.bounds = CGRectMake( + _refreshControl.bounds.origin.x, +- -progressViewOffset, ++ -_pendingProgressViewOffset, + _refreshControl.bounds.size.width, + _refreshControl.bounds.size.height); ++ _hasPendingProgressViewOffset = NO; ++} ++ ++- (void)_updateTintColor:(UIColor *)tintColor ++{ ++ _pendingTintColor = tintColor; ++ _hasPendingTintColor = YES; ++ // Applies immediately for runtime changes while the control is attached; ++ // pre-attach sets wait until the control is inside the scroll view. ++ [self _applyPendingTintColorIfPossible]; ++ if (_hasPendingTintColor) { ++ [self setNeedsLayout]; ++ } ++} ++ ++- (void)_applyPendingTintColorIfPossible ++{ ++ if (!_hasPendingTintColor || ![_refreshControl.superview isKindOfClass:[UIScrollView class]]) { ++ return; ++ } ++ _refreshControl.tintColor = _pendingTintColor; ++ _pendingTintColor = nil; ++ _hasPendingTintColor = NO; + } + + - (void)_updateTitle +@@ -153,7 +234,12 @@ - (void)_updateTitle + const auto &concreteProps = static_cast(*_props); + + if (concreteProps.title.empty()) { +- _refreshControl.attributedTitle = nil; ++ // Avoid touching the control when there is nothing to clear - writing ++ // attributedTitle (even nil) before the control is in the scroll view ++ // hierarchy can suppress the pull-to-refresh haptic (#43388). ++ if (_refreshControl.attributedTitle != nil) { ++ _refreshControl.attributedTitle = nil; ++ } + return; + } + +@@ -172,6 +258,18 @@ - (void)layoutSubviews + { + [super layoutSubviews]; + ++ /* ++ * Fallback for the pending props: _attach applies them right after the ++ * refreshControl assignment (insertion is synchronous there on current iOS), ++ * but should UIKit ever defer the insertion to a later layout pass, re-arm ++ * and retry until the control is actually inside the scroll view. ++ */ ++ [self _applyPendingTintColorIfPossible]; ++ [self _applyPendingProgressViewOffsetIfPossible]; ++ if ((_hasPendingTintColor || _hasPendingProgressViewOffset) && _scrollViewComponentView != nil) { ++ [self setNeedsLayout]; ++ } ++ + // Attempts to begin refreshing before the initial layout are ignored by _refreshControl. So if the control is + // refreshing when mounted, we need to call beginRefreshing in layoutSubviews or it won't work. + if (self.window) { +@@ -209,6 +307,15 @@ - (void)_attach + + // This ensures that layoutSubviews is called. Without this, recycled instances won't refresh on mount + [self setNeedsLayout]; ++ ++ /* ++ * The assignment above inserts the control (and creates its content view) ++ * synchronously on current iOS - verified via frame logging - so the ++ * pending props can be applied immediately. layoutSubviews is the fallback ++ * if insertion is ever deferred. ++ */ ++ [self _applyPendingTintColorIfPossible]; ++ [self _applyPendingProgressViewOffsetIfPossible]; + } + } + diff --git a/patches/react-native/refresh-control-defer-props.patch.md b/patches/react-native/refresh-control-defer-props.patch.md new file mode 100644 index 000000000..9f0eb6726 --- /dev/null +++ b/patches/react-native/refresh-control-defer-props.patch.md @@ -0,0 +1,56 @@ +## RCTPullToRefreshViewComponentView.mm Patch - iOS 17.4+ haptic regression and iOS 26 progressViewOffset cancellation on New Arch + +Both bugs share one root cause, established by instrumented frame-logging runs on the iOS 26 +simulator (Aug 2026): **writes to a detached `UIRefreshControl` are hazardous, because the +control's `_UIRefreshControlModernContentView` bakes in the state it observes at its own +creation.** Facts proven by the logs: + +- `scrollView.refreshControl` assignment inserts the control and creates its content view + **synchronously** on iOS 26 (the "UIKit inserts lazily on a later layout pass" folklore is + false there). +- The content view can also be materialized **earlier** by a pre-attach property write (observed + with `tintColor`) while the control is still detached. +- The content view positions itself at whatever `bounds.origin` exists at its creation and keeps + that y forever - width tracks on later layouts, y never re-pins. + +Consequences: + +**1. progressViewOffset.** Stock Fabric writes the offset as a `bounds.origin` shift in +`updateProps`, pre-attach. The content view is then created (at insertion) already inside the +shifted bounds, pins to it, and cancels the shift exactly - spinner hidden behind the floating +home header (home is the only screen passing a non-zero offset). Stock RN appeared to work only +by accident: its own pre-attach `tintColor` write materialized the content view at origin 0 +*before* the offset write. Possibly related upstream: react-native#54183. + +**2. Haptic (react-native#43388).** The Paper fix above does not cover Fabric: `updateProps` +writes `tintColor` pre-attach, and a tint write on a detached control materializes the content +view outside the scroll view, permanently suppressing the trigger haptic on iOS 17.4+ (the +creation-time-state story likely explains this too, though the haptic wiring itself is not +observable in logs). + +**The fix**: both `tintColor` and `progressViewOffset` are parked in the component view +(`_pendingTintColor` / `_pendingProgressViewOffset`, no `UIRefreshControl` subclass) and applied +only once `_refreshControl.superview` is the scroll view - by then the content view exists, +was created at origin 0, and a bounds shift lands visibly. Application points: immediately in +`_updateX` for runtime changes while attached; in `_attach` right after the assignment (insertion +is synchronous); and from `layoutSubviews` with a `setNeedsLayout` re-arm as a fallback should +insertion ever be deferred. + +Supporting changes: + +- `shouldBeRecycled = NO`: recycled instances get all props force-applied in `updateProps` before + the new control is attached, which would re-trigger the pre-attach hazards; opting out keeps + every mount on the untouched-before-attach path. +- `_updateTitle` no longer writes `attributedTitle = nil` when there is nothing to clear - even a + nil write before attach suppresses the haptic. + +History: an earlier iteration fixed the offset by porting Paper's frame-offset trick into an +`RCTHapticCompatibleRefreshControl` subclass (worked, verified on device) - replaced by the +deferral once the root cause was understood. The control's `didMoveToSuperview` appeared broken +as a tint application point in early non-rigorous testing; unproven, not disproven. + +Upstream issue #43388 still open as of Aug 2026. Haptics cannot be verified on the simulator - +physical device only. Spinner position verified via frame logs; haptic on this variant NOT yet +device-verified. + +Opened issue in RN repo: https://github.com/react/react-native/issues/57843 diff --git a/patches/react-native/refresh-control-paper-haptic.patch b/patches/react-native/refresh-control-paper-haptic.patch new file mode 100644 index 000000000..7c74d15d2 --- /dev/null +++ b/patches/react-native/refresh-control-paper-haptic.patch @@ -0,0 +1,74 @@ +diff --git a/React/Views/RefreshControl/RCTRefreshControl.h b/React/Views/RefreshControl/RCTRefreshControl.h +index ed306d7..d447dad 100644 +--- a/React/Views/RefreshControl/RCTRefreshControl.h ++++ b/React/Views/RefreshControl/RCTRefreshControl.h +@@ -18,6 +18,7 @@ __attribute__((deprecated("This API will be removed along with the legacy archit + @property (nonatomic, copy) NSString *title; + @property (nonatomic, copy) RCTDirectEventBlock onRefresh; + @property (nonatomic, weak) UIScrollView *scrollView; ++@property (nonatomic, copy) UIColor *customTintColor; + + @end + +diff --git a/React/Views/RefreshControl/RCTRefreshControl.m b/React/Views/RefreshControl/RCTRefreshControl.m +index 2dc86e4..6661dc6 100644 +--- a/React/Views/RefreshControl/RCTRefreshControl.m ++++ b/React/Views/RefreshControl/RCTRefreshControl.m +@@ -25,6 +25,7 @@ @implementation RCTRefreshControl { + UIColor *_titleColor; + CGFloat _progressViewOffset; + BOOL _hasMovedToWindow; ++ UIColor *_customTintColor; + } + + - (instancetype)init +@@ -60,6 +61,12 @@ - (void)layoutSubviews + _isInitialRender = false; + } + ++- (void)didMoveToSuperview ++{ ++ [super didMoveToSuperview]; ++ [self setTintColor:_customTintColor]; ++} ++ + - (void)didMoveToWindow + { + [super didMoveToWindow]; +@@ -225,6 +232,18 @@ - (void)refreshControlValueChanged + } + } + ++// Fix for https://github.com/facebook/react-native/issues/43388 ++// A bug in iOS 17.4 causes the haptic to not play when refreshing if the tintColor ++// is set before the refresh control gets added to the scrollview. We'll call this ++// function whenever the superview changes. We'll also call it if the value of customTintColor ++// changes. ++- (void)setTintColor:(UIColor *)tintColor ++{ ++ if ([self.superview isKindOfClass:[UIScrollView class]] && self.tintColor != tintColor) { ++ [super setTintColor:tintColor]; ++ } ++} ++ + @end + + #endif // RCT_REMOVE_LEGACY_ARCH +diff --git a/React/Views/RefreshControl/RCTRefreshControlManager.m b/React/Views/RefreshControl/RCTRefreshControlManager.m +index 1e9ff52..44329c5 100644 +--- a/React/Views/RefreshControl/RCTRefreshControlManager.m ++++ b/React/Views/RefreshControl/RCTRefreshControlManager.m +@@ -24,11 +24,12 @@ - (UIView *)view + + RCT_EXPORT_VIEW_PROPERTY(onRefresh, RCTDirectEventBlock) + RCT_EXPORT_VIEW_PROPERTY(refreshing, BOOL) +-RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) + RCT_EXPORT_VIEW_PROPERTY(title, NSString) + RCT_EXPORT_VIEW_PROPERTY(titleColor, UIColor) + RCT_EXPORT_VIEW_PROPERTY(progressViewOffset, CGFloat) + ++RCT_REMAP_VIEW_PROPERTY(tintColor, customTintColor, UIColor) ++ + RCT_EXPORT_METHOD(setNativeRefreshing : (nonnull NSNumber *)viewTag toRefreshing : (BOOL)refreshing) + { + [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { diff --git a/patches/react-native/refresh-control-paper-haptic.patch.md b/patches/react-native/refresh-control-paper-haptic.patch.md new file mode 100644 index 000000000..b93e303de --- /dev/null +++ b/patches/react-native/refresh-control-paper-haptic.patch.md @@ -0,0 +1,5 @@ +## RefreshControl Patch - iOS 17.4 Haptic Regression + +Patching `RCTRefreshControl.mm` temporarily to play an impact haptic on refresh when using iOS 17.4 or higher. Since +17.4, there has been a regression somewhere causing haptics to not play on iOS on refresh. Should monitor for an update +in the RN repo: https://github.com/facebook/react-native/issues/43388 diff --git a/patches/react-native/scheduler-delegate-invalidation.patch b/patches/react-native/scheduler-delegate-invalidation.patch new file mode 100644 index 000000000..152243008 --- /dev/null +++ b/patches/react-native/scheduler-delegate-invalidation.patch @@ -0,0 +1,15 @@ +diff --git a/ReactCommon/react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h b/ReactCommon/react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h +index fdabd7b..ef70011 100644 +--- a/ReactCommon/react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h ++++ b/ReactCommon/react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h +@@ -21,6 +21,10 @@ class ReactNativeFeatureFlagsOverridesOSSStable : public ReactNativeFeatureFlags + { + return true; + } ++ bool enableSchedulerDelegateInvalidation() override ++ { ++ return true; ++ } + bool useTurboModules() override + { + return true; diff --git a/patches/react-native/scheduler-delegate-invalidation.patch.md b/patches/react-native/scheduler-delegate-invalidation.patch.md new file mode 100644 index 000000000..dea4550ea --- /dev/null +++ b/patches/react-native/scheduler-delegate-invalidation.patch.md @@ -0,0 +1,15 @@ +## Scheduler delegate invalidation - iOS use-after-free + +Fixes Sentry issue APP-T28X: an `EXC_BAD_ACCESS` in +`Scheduler::uiManagerDidFinishTransaction` or +`Scheduler::uiManagerDidDispatchCommand` after a queued rendering update +outlives its captured raw `SchedulerDelegate` pointer. + +React Native 0.86 contains the invalidation-token guard from +facebook/react-native#56680, but `enableSchedulerDelegateInvalidation` is false +for the stable release level used by Expo. Override only this flag in +`ReactNativeFeatureFlagsOverridesOSSStable` instead of opting the app into all +experimental React Native flags. + +**TODO: Remove after upgrading to a React Native release that closes the +queued Scheduler delegate lifetime race by default.** diff --git a/patches/react-native/scrollview-center-content-insets.patch b/patches/react-native/scrollview-center-content-insets.patch new file mode 100644 index 000000000..68ca9b38c --- /dev/null +++ b/patches/react-native/scrollview-center-content-insets.patch @@ -0,0 +1,46 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm +index 1b02e8b..b3481c1 100644 +--- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm ++++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm +@@ -102,6 +102,20 @@ - (void)setContentOffset:(CGPoint)contentOffset + RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y")); + } + ++- (void)setCenterContent:(BOOL)centerContent ++{ ++ if (_centerContent != centerContent) { ++ _centerContent = centerContent; ++ [self centerContentIfNeeded]; ++ } ++} ++ ++- (void)setContentSize:(CGSize)contentSize ++{ ++ [super setContentSize:contentSize]; ++ [self centerContentIfNeeded]; ++} ++ + - (void)setFrame:(CGRect)frame + { + [super setFrame:frame]; +diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +index 9ab1db4..b189a1b 100644 +--- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +@@ -396,7 +396,15 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & + + MAP_SCROLL_VIEW_PROP(zoomScale); + +- if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset) { ++ // When disabling centerContent, reset inset to prop value ++ // (enabling is handled automatically by the setCenterContent: setter) ++ if (oldScrollViewProps.centerContent && !newScrollViewProps.centerContent) { ++ _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset); ++ } ++ ++ // Only apply contentInset from props if centerContent is disabled ++ // When centerContent is enabled, the inset is calculated by centerContentIfNeeded ++ if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset && !newScrollViewProps.centerContent) { + _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset); + } + diff --git a/patches/react-native/scrollview-center-content-insets.patch.md b/patches/react-native/scrollview-center-content-insets.patch.md new file mode 100644 index 000000000..c56d55e53 --- /dev/null +++ b/patches/react-native/scrollview-center-content-insets.patch.md @@ -0,0 +1,19 @@ +## RCTEnhancedScrollView.mm / RCTScrollViewComponentView.mm Patch - centerContent insets stale after content resize on New Arch + +**TODO: Remove after bumping React Native to 0.87+** (fixed upstream by facebook/react-native#56832, +commit d50c1b5207; first shipped in 0.87.0-rc.0). + +On Fabric, `centerContent` centers by computing `contentInset` in `centerContentIfNeeded`, but that +recompute only ran on `setFrame`/`didAddSubview`/`scrollViewDidZoom` - not when a state update assigns a +new `contentSize` in `updateState`. Any content that resizes after mount inside a `centerContent` +ScrollView (e.g. the lightbox image crop view getting its real aspect ratio from `onLoad` when the embed +has no aspectRatio metadata) keeps the old insets: content rests off-center and the excess inset creates +phantom scroll range, so the image can be dragged and parked off-center and the native scroll steals the +swipe-down-to-dismiss pan. The old architecture paired every `contentSize` update with re-centering in +`RCTScrollView.updateContentSizeIfNeeded`; Fabric dropped that link. + +Backport of the upstream fix: `setContentSize:`/`setCenterContent:` overrides on `RCTEnhancedScrollView` +that call `centerContentIfNeeded`, plus the `updateProps` guards so the `contentInset` prop does not +fight the computed centering inset. + +Issue: https://github.com/facebook/react-native/issues/55090 diff --git a/patches/react-native/scrollview-disable-recycling.patch b/patches/react-native/scrollview-disable-recycling.patch new file mode 100644 index 000000000..6ab0cf715 --- /dev/null +++ b/patches/react-native/scrollview-disable-recycling.patch @@ -0,0 +1,16 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +index 9ab1db4..c20da25 100644 +--- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +@@ -1133,6 +1133,11 @@ - (RCTVirtualViewContainerState *)virtualViewContainerState + return _virtualViewContainerState; + } + +++ (BOOL)shouldBeRecycled ++{ ++ return NO; ++} ++ + @end + + Class RCTScrollViewCls(void) diff --git a/patches/react-native/scrollview-disable-recycling.patch.md b/patches/react-native/scrollview-disable-recycling.patch.md new file mode 100644 index 000000000..995c4f5c0 --- /dev/null +++ b/patches/react-native/scrollview-disable-recycling.patch.md @@ -0,0 +1,8 @@ +## RCTScrollViewComponentView.mm Patch - Disable ScrollView component-view recycling on New Arch + +Fabric ScrollView component-view recycling is disabled by returning `NO` from +`shouldBeRecycled`. This was added in social-app#8295 to prevent a recycled ScrollView from +carrying `contentInset` mutations, such as those made by Reanimated, into the next rendered +ScrollView. The original patch also reset the inset in `prepareForRecycle`; that reset no longer +survives, leaving the recycling override as the remaining protection. Re-evaluate this hunk when +upgrading React Native rather than assuming it belongs to either ScrollView fix above. diff --git a/patches/react-native/text-input-reveal-caret.patch b/patches/react-native/text-input-reveal-caret.patch new file mode 100644 index 000000000..c16f1749e --- /dev/null +++ b/patches/react-native/text-input-reveal-caret.patch @@ -0,0 +1,63 @@ +diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +index 917dc6d..38c14f9 100644 +--- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm ++++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +@@ -372,6 +372,10 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics + _previousContentSize = _backedTextInputView.contentSize; + static_cast(*_eventEmitter).onContentSizeChange([self _textInputMetrics]); + } ++ ++ if (layoutMetrics.frame.size.height > oldLayoutMetrics.frame.size.height) { ++ [self _scrollCaretIntoEnclosingScrollView]; ++ } + } + + - (void)prepareForRecycle +@@ -821,6 +825,47 @@ - (void)scrollCursorIntoView + } + } + ++/* ++ * A multiline input grows one commit after UIKit has inserted the newline. UIKit reveals the caret ++ * synchronously inside the text change and never again when the frame changes. While scrolling is ++ * disabled the text container tracks the frame, so at that moment the new line has no layout yet and ++ * UIKit reveals the previous line instead; the new line then sits under the keyboard until the next ++ * keystroke. Reveal it here, right after the taller frame has been applied, so growth and scroll land ++ * in the same frame. ++ */ ++- (void)_scrollCaretIntoEnclosingScrollView ++{ ++ if (![_backedTextInputView isKindOfClass:[UITextView class]] || !_backedTextInputView.isFirstResponder) { ++ return; ++ } ++ ++ UIScrollView *enclosingScrollView = nil; ++ for (UIView *view = self.superview; view != nil; view = view.superview) { ++ if ([view isKindOfClass:[UIScrollView class]]) { ++ enclosingScrollView = (UIScrollView *)view; ++ break; ++ } ++ } ++ if (enclosingScrollView == nil) { ++ return; ++ } ++ ++ UITextRange *selectedTextRange = _backedTextInputView.selectedTextRange; ++ if (selectedTextRange == nil) { ++ return; ++ } ++ ++ [_backedTextInputView layoutIfNeeded]; ++ CGRect caretRect = [_backedTextInputView caretRectForPosition:selectedTextRange.end]; ++ if (CGRectIsNull(caretRect) || CGRectIsInfinite(caretRect) || CGRectGetMaxY(caretRect) <= 0) { ++ return; ++ } ++ ++ CGRect caretRectInScrollView = [_backedTextInputView convertRect:caretRect toView:enclosingScrollView]; ++ // Keep the same breathing room UIKit adds when it reveals the caret itself. ++ [enclosingScrollView scrollRectToVisible:CGRectInset(caretRectInScrollView, 0, -4) animated:NO]; ++} ++ + - (void)_setMultiline:(BOOL)multiline + { + [_backedTextInputView removeFromSuperview]; diff --git a/patches/react-native/text-input-reveal-caret.patch.md b/patches/react-native/text-input-reveal-caret.patch.md new file mode 100644 index 000000000..34882a17f --- /dev/null +++ b/patches/react-native/text-input-reveal-caret.patch.md @@ -0,0 +1,4 @@ +## RCTTextInputComponentView.mm Patch - reveal the caret after a multiline input grows (iOS New Arch) + +Fixes ScrollView doesn't scroll up on new line in TextInput issue +https://github.com/react/react-native/issues/58517 diff --git a/patches/react-native/view-group-clipping-null-child.patch b/patches/react-native/view-group-clipping-null-child.patch new file mode 100644 index 000000000..ca37fc4af --- /dev/null +++ b/patches/react-native/view-group-clipping-null-child.patch @@ -0,0 +1,29 @@ +diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt +index 5977524..426de3a 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt +@@ -459,6 +459,13 @@ public open class ReactViewGroup public constructor(context: Context?) : + inSubviewClippingLoop = true + var clippedSoFar = 0 + for (i in 0.. updateClippingRect` during an animated smooth scroll +(New Architecture, `removeClippedSubviews`). + +The clipping loop in `updateClippingToRect` captures its bound once, but clipping a view +(`removeViewsInLayout`) can synchronously trigger reentrant child removal (layout-change +listeners, animation-end callbacks, Fabric mounting on the UI thread), which compacts +`allChildren` and nulls the tail mid-loop. Upstream already catches the +`IndexOutOfBoundsException` variant of this corruption with diagnostics, but the null-child +variant throws `IllegalStateException` and escapes as a fatal crash. A null entry means the +view is already detached, so we skip it and count it as clipped to keep index math aligned. + +Not fixed upstream as of July 2026 (identical `checkNotNull` on `main`); the sibling fix +attempt facebook/react-native#57365 for the same bookkeeping corruption (different stack) +was abandoned. Re-check when bumping React Native. + +Note on build modes: every Android build compiles react-android from source +(`buildReactNativeFromSource: true` via expo-build-properties in app.config.js injects +the includeBuild/dependency-substitution block at prebuild), so this hunk, like any +ReactAndroid or ReactCommon change in this patch, is active in dev builds too. Before +that, only production builds compiled from source, and dev builds used the prebuilt AAR +from Maven Central, where these hunks have no effect. diff --git a/patches/react-native@0.86.3.patch.md b/patches/react-native@0.86.3.patch.md index 48da5695c..1483587a2 100644 --- a/patches/react-native@0.86.3.patch.md +++ b/patches/react-native@0.86.3.patch.md @@ -1,244 +1,6 @@ -# ***This second part of this patch is load bearing, do not remove.*** +# react-native@0.86.3 -## Scheduler delegate invalidation - iOS use-after-free - -Fixes Sentry issue APP-T28X: an `EXC_BAD_ACCESS` in -`Scheduler::uiManagerDidFinishTransaction` or -`Scheduler::uiManagerDidDispatchCommand` after a queued rendering update -outlives its captured raw `SchedulerDelegate` pointer. - -React Native 0.86 contains the invalidation-token guard from -facebook/react-native#56680, but `enableSchedulerDelegateInvalidation` is false -for the stable release level used by Expo. Override only this flag in -`ReactNativeFeatureFlagsOverridesOSSStable` instead of opting the app into all -experimental React Native flags. - -**TODO: Remove after upgrading to a React Native release that closes the -queued Scheduler delegate lifetime race by default.** - -## UIManager.cpp Patch - Fabric focus navigation use-after-free - -Fixes Sentry issue APP-T4H9: a SIGSEGV in -`FabricUIManagerBinding::findNextFocusableElement` during focus navigation. - -React Native 0.86 contains the safe implementation behind -`fixFindShadowNodeByTagRaceCondition`, but the public default is false. The -fallback captures a raw root shadow-node pointer in `tryCommit` and dereferences -it after the lock is released, allowing a concurrent commit or surface stop to -free the node first. This backports the final upstream implementation, which -holds the current revision's `shared_ptr` for the entire traversal. - -**TODO: Remove after bumping React Native to a release containing -facebook/react-native#56850.** - -## RefreshControl Patch - iOS 17.4 Haptic Regression - -Patching `RCTRefreshControl.mm` temporarily to play an impact haptic on refresh when using iOS 17.4 or higher. Since -17.4, there has been a regression somewhere causing haptics to not play on iOS on refresh. Should monitor for an update -in the RN repo: https://github.com/facebook/react-native/issues/43388 - -## RCTPullToRefreshViewComponentView.mm Patch - iOS 17.4+ haptic regression and iOS 26 progressViewOffset cancellation on New Arch - -Both bugs share one root cause, established by instrumented frame-logging runs on the iOS 26 -simulator (Aug 2026): **writes to a detached `UIRefreshControl` are hazardous, because the -control's `_UIRefreshControlModernContentView` bakes in the state it observes at its own -creation.** Facts proven by the logs: - -- `scrollView.refreshControl` assignment inserts the control and creates its content view - **synchronously** on iOS 26 (the "UIKit inserts lazily on a later layout pass" folklore is - false there). -- The content view can also be materialized **earlier** by a pre-attach property write (observed - with `tintColor`) while the control is still detached. -- The content view positions itself at whatever `bounds.origin` exists at its creation and keeps - that y forever - width tracks on later layouts, y never re-pins. - -Consequences: - -**1. progressViewOffset.** Stock Fabric writes the offset as a `bounds.origin` shift in -`updateProps`, pre-attach. The content view is then created (at insertion) already inside the -shifted bounds, pins to it, and cancels the shift exactly - spinner hidden behind the floating -home header (home is the only screen passing a non-zero offset). Stock RN appeared to work only -by accident: its own pre-attach `tintColor` write materialized the content view at origin 0 -*before* the offset write. Possibly related upstream: react-native#54183. - -**2. Haptic (react-native#43388).** The Paper fix above does not cover Fabric: `updateProps` -writes `tintColor` pre-attach, and a tint write on a detached control materializes the content -view outside the scroll view, permanently suppressing the trigger haptic on iOS 17.4+ (the -creation-time-state story likely explains this too, though the haptic wiring itself is not -observable in logs). - -**The fix**: both `tintColor` and `progressViewOffset` are parked in the component view -(`_pendingTintColor` / `_pendingProgressViewOffset`, no `UIRefreshControl` subclass) and applied -only once `_refreshControl.superview` is the scroll view - by then the content view exists, -was created at origin 0, and a bounds shift lands visibly. Application points: immediately in -`_updateX` for runtime changes while attached; in `_attach` right after the assignment (insertion -is synchronous); and from `layoutSubviews` with a `setNeedsLayout` re-arm as a fallback should -insertion ever be deferred. - -Supporting changes: - -- `shouldBeRecycled = NO`: recycled instances get all props force-applied in `updateProps` before - the new control is attached, which would re-trigger the pre-attach hazards; opting out keeps - every mount on the untouched-before-attach path. -- `_updateTitle` no longer writes `attributedTitle = nil` when there is nothing to clear - even a - nil write before attach suppresses the haptic. - -History: an earlier iteration fixed the offset by porting Paper's frame-offset trick into an -`RCTHapticCompatibleRefreshControl` subclass (worked, verified on device) - replaced by the -deferral once the root cause was understood. The control's `didMoveToSuperview` appeared broken -as a tint application point in early non-rigorous testing; unproven, not disproven. - -Upstream issue #43388 still open as of Aug 2026. Haptics cannot be verified on the simulator - -physical device only. Spinner position verified via frame logs; haptic on this variant NOT yet -device-verified. - -Opened issue in RN repo: https://github.com/react/react-native/issues/57843 - -## RCTEnhancedScrollView.mm / RCTScrollViewComponentView.mm Patch - centerContent insets stale after content resize on New Arch - -**TODO: Remove after bumping React Native to 0.87+** (fixed upstream by facebook/react-native#56832, -commit d50c1b5207; first shipped in 0.87.0-rc.0). - -On Fabric, `centerContent` centers by computing `contentInset` in `centerContentIfNeeded`, but that -recompute only ran on `setFrame`/`didAddSubview`/`scrollViewDidZoom` - not when a state update assigns a -new `contentSize` in `updateState`. Any content that resizes after mount inside a `centerContent` -ScrollView (e.g. the lightbox image crop view getting its real aspect ratio from `onLoad` when the embed -has no aspectRatio metadata) keeps the old insets: content rests off-center and the excess inset creates -phantom scroll range, so the image can be dragged and parked off-center and the native scroll steals the -swipe-down-to-dismiss pan. The old architecture paired every `contentSize` update with re-centering in -`RCTScrollView.updateContentSizeIfNeeded`; Fabric dropped that link. - -Backport of the upstream fix: `setContentSize:`/`setCenterContent:` overrides on `RCTEnhancedScrollView` -that call `centerContentIfNeeded`, plus the `updateProps` guards so the `contentInset` prop does not -fight the computed centering inset. - -Issue: https://github.com/facebook/react-native/issues/55090 - -## RCTScrollViewComponentView.mm Patch - ScrollView pinch/pan ignored outside content area on New Arch - -**TODO: Remove after bumping React Native to 0.87+** (fixed upstream by facebook/react-native#56747, -commit efcab20908; first shipped in 0.87.0-rc.0). - -On Fabric, `betterHitTest` in `RCTScrollViewComponentView` deliberately skips the `_containerView` -and hit-tests its grandchildren, returning `self` (the wrapper component view) when the touch lands -inside the scroll view bounds but outside any content. UIKit only delivers touches to a gesture -recognizer when the hit view is the recognizer's view or a descendant of it, and the `UIScrollView` -is a *child* of the wrapper - so its native pinch/pan recognizers never see those touches. In the -lightbox this means pinch-to-zoom and pan-while-zoomed only respond when the fingers are over the -image itself, not over the letterbox bars above/below it. On the old architecture, default UIKit -hit-testing returns the `UIScrollView` itself for those touches, so everything works. - -Backport of the upstream one-liner: return `_scrollView` instead of `self` so touches in the -content-less area are attributed to the `UIScrollView`. - -Issue: https://github.com/facebook/react-native/issues/54123 -PR: https://github.com/react/react-native/pull/56747 - -## ReactViewGroup.kt Patch - Fatal "Required value was null" during subview clipping on Android - -Fixes Sentry issue APP-T20Q: `IllegalStateException: Required value was null` thrown by -`checkNotNull(allChildren?.get(idx))` in `updateSubviewClipStatus`, reached from -`ReactScrollView.onScrollChanged -> updateClippingRect` during an animated smooth scroll -(New Architecture, `removeClippedSubviews`). - -The clipping loop in `updateClippingToRect` captures its bound once, but clipping a view -(`removeViewsInLayout`) can synchronously trigger reentrant child removal (layout-change -listeners, animation-end callbacks, Fabric mounting on the UI thread), which compacts -`allChildren` and nulls the tail mid-loop. Upstream already catches the -`IndexOutOfBoundsException` variant of this corruption with diagnostics, but the null-child -variant throws `IllegalStateException` and escapes as a fatal crash. A null entry means the -view is already detached, so we skip it and count it as clipped to keep index math aligned. - -Not fixed upstream as of July 2026 (identical `checkNotNull` on `main`); the sibling fix -attempt facebook/react-native#57365 for the same bookkeeping corruption (different stack) -was abandoned. Re-check when bumping React Native. - -Note on build modes: every Android build compiles react-android from source -(`buildReactNativeFromSource: true` via expo-build-properties in app.config.js injects -the includeBuild/dependency-substitution block at prebuild), so this hunk, like any -ReactAndroid or ReactCommon change in this patch, is active in dev builds too. Before -that, only production builds compiled from source, and dev builds used the prebuilt AAR -from Maven Central, where these hunks have no effect. - -## RCTTextLayoutManager.mm Patch - Text overflows instead of wrapping on the last line - -Issue: https://github.com/react/react-native/issues/53450#issuecomment-3298157830 -Bandaid fix taken from: https://github.com/react/react-native/commit/581d643a9e59fd88f93757f80194e1efd11bd0e5 - -## RCTTextLayoutManager.mm / TextLayoutManager / ParagraphShadowNode.cpp Patch - text laid out on the main thread when first drawn - -The first time a text view draws, `drawAttributedString:` runs on the main -thread and lays the text out from scratch: it rebuilds the attributed string -(font lookups), attaches a new layout manager (font fixing, glyph generation) -and lays out every line. Measurement already did the same work off the main -thread, but throws it away. Painting the glyphs is only a small part of the -cost. While scrolling the feed this was the largest single main-thread cost -when new posts appear. React Native's `enablePreparedTextLayout` flag solves -this only on Android. - -- After layout, `ParagraphShadowNode::layout` calls the new - `TextLayoutManager::prepareForDrawing` whenever a text view's attributed - string changes, which is when the view redraws. It passes the content frame - size the view will draw into. This only compiles on Apple platforms. -- `prepareAttributedStringForDrawing:` makes the layout the draw would make - for that size, on the calling thread (usually the JS thread). If measuring - already laid the text out at the same width (within 0.5pt of pixel - rounding), and the frame is tall enough for every measured line, it reuses - that layout. Measurement uses unlimited height, so the result is the same. - Otherwise it lays the text out at exactly that size. -- `drawAttributedString:` takes the prepared layout for its exact frame size. - If there is none (for example, the frame changed without new text), it lays - the text out as before. -- Layouts are handed out once, so only one thread uses a text storage at a - time. Unused ones (text that is never drawn) are evicted oldest-first, with - at most 512 texts kept per kind. -- Measured layouts are never reused for `adjustsFontSizeToFit`, whose font size - depends on the final frame. - -Measured on an iPhone 16 Pro Max (Release build, 30s fling through the feed): -main-thread time in `drawAttributedString:` went from about 570ms to 160ms, all -draws on launch used a prepared layout, and the JS thread spent about 300ms -preparing text. About half of the prepared layouts are never drawn (text in -views that are offscreen or replaced before mounting). - -**TODO: Re-evaluate on React Native upgrades.** Not an upstream backport. - -## RCTViewComponentView.mm Patch - Hairline border strokes dropped at certain subpixel Y offsets on New Arch - -Symptom: dividers built as `borderTopWidth: hairlineWidth` vanish on some screens and not -others, deterministically by the view's absolute subpixel Y. A background fill of the same -geometry always renders. - -Cause: Fabric draws borders as a stretched 9-slice image. The consumer -(`RCTAddContourEffectToLayer`) hardcodes the stretchable middle as a 1pt band, which matched -the image the producer built until RN 0.81. facebook/react-native#54237 changed the image -size to `ceil(insets) + 1 + ceil(insets)` without updating that formula, so for fractional -(hairline) insets the labels no longer match the image: transparent filler is treated as a -rigid cap, and when squeezed into a one-pixel-tall layer the sampling can land on it instead -of the stroke - no line. - -Fix: compute the middle from the cap insets (`size - caps`) instead of assuming 1pt. - -Upstream issue: https://github.com/react/react-native/issues/58054 (repro: -https://github.com/abulenok/HairlineBorderRepro, fails identically on 0.86.0 and 0.87.0). - -## RCTTextInputComponentView.mm Patch - reveal the caret after a multiline input grows (iOS New Arch) - -Fixes ScrollView doesn't scroll up on new line in TextInput issue -https://github.com/react/react-native/issues/58517 - -## RCTModalHostViewComponentView.mm Patch - Blank sheet when dismissing a modal with a child controller - -Fixes https://github.com/bluesky-social/social-app/issues/11393: showing the iOS -Undo Typing alert while submitting a post or reply can leave an empty composer -sheet that cannot be dismissed. UIKit dismisses only the child controller when -the modal itself receives `dismissViewControllerAnimated:completion:`. - -Backport of https://github.com/react/react-native/pull/58364, commit -`3f556d7574999bcba5fa8a1ba70de57346284463`: when a child is presented, dismiss -through the modal's presenting controller to close the entire stack. Fall back -to the modal if its presenting controller is nil, and keep direct dismissal when -there is no child. - -**TODO: Remove after upgrading to a React Native release containing this fix.** -The upstream PR is still open as of September 9, 2026. +**Generated - do not edit the .patch next to this file.** It is built from the +patches in [`patches/react-native/`](react-native/) by +`pnpm patch:react-native`. Each patch there has a `.patch.md` explaining it; +see [the README](react-native/README.md) for how to add or change one. diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index d795215e9..73cc43428 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -12,6 +12,7 @@ packageExtensions: optional: true trustPolicy: 'no-downgrade' # default: off trustPolicyIgnoreAfter: 10080 # 7 days, default: undefined +pmOnFail: download # run the pnpm version pinned in devEngines; package.json keeps onFail: warn because npm/npx read it too overrides: '@react-native/babel-preset': '0.86.3' '@react-native/normalize-colors': '0.86.3' -- knotmirror 0.0.1