TypeScript
fix(mobile): iOS filter menus close back into their pill without clipping or garbling (#31168)
Julius Marminge0bba3684b83e
diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsxindex 7463e325f73..dac883341cc 100644--- a/apps/mobile/src/features/home/HomeScreen.tsx+++ b/apps/mobile/src/features/home/HomeScreen.tsx@@ -809,6 +809,8 @@ export function HomeScreen(props: HomeScreenProps) {recycleItemsextraData={v2ExtraData}ListHeaderComponent={v2ListHeader}+ // Lifted above the rows so an iOS filter menu's dismissal morph is not covered.+ ListHeaderComponentStyle={{ zIndex: 1 }}ListFooterComponent={settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0 ? (<ThreadListV2ShowMoreRowdiff --git a/apps/mobile/src/features/home/ThreadListFilters.tsx b/apps/mobile/src/features/home/ThreadListFilters.tsxindex c6165e649b4..196e6a86480 100644--- a/apps/mobile/src/features/home/ThreadListFilters.tsx+++ b/apps/mobile/src/features/home/ThreadListFilters.tsx@@ -27,7 +27,7 @@ export function ThreadListFilters(props: {<ScrollViewhorizontalshowsHorizontalScrollIndicator={false}- style={{ marginHorizontal: -props.gutter }}+ style={{ marginHorizontal: -props.gutter, overflow: "visible" }}contentContainerStyle={{ paddingHorizontal: 20, paddingTop: 2, paddingBottom: 10, gap: 8 }}><ListFilterMenudiff --git a/apps/mobile/src/features/pull-requests/PullRequestListFilters.tsx b/apps/mobile/src/features/pull-requests/PullRequestListFilters.tsxindex cbc2c10ce3d..fbcb62406b7 100644--- a/apps/mobile/src/features/pull-requests/PullRequestListFilters.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestListFilters.tsx@@ -357,6 +357,7 @@ export function PullRequestListFilters(props: {<ScrollViewhorizontalshowsHorizontalScrollIndicator={false}+ style={{ overflow: "visible" }}// In the Android sidebar the first pill lines up with the rows' content instead// (8dp row margin + 12dp padding).contentContainerStyle={diff --git a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsxindex 8221d508013..593ded7d31a 100644--- a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx@@ -318,6 +318,8 @@ export function PullRequestsScreen(keyboardDismissMode="on-drag"keyboardShouldPersistTaps="handled"renderItem={renderPullRequest}+ // Lifted above the rows so an iOS filter menu's dismissal morph is not covered.+ ListHeaderComponentStyle={{ zIndex: 1 }}ListHeaderComponent={<><PullRequestListFilters sidebar={sidebar} filters={filters} />diff --git a/patches/@[email protected] b/patches/@[email protected]index a96e172c098..fc7c42bf4ed 100644--- a/patches/@[email protected]+++ b/patches/@[email protected]@@ -1,5 +1,5 @@diff --git a/ios/MenuViewManager.mm b/ios/MenuViewManager.mm-index 3d149b3e7426b8f7c999603ddf1e15e12331c33a..e80fe2caae86e339fcb03408419a7d64b3e5b04f 100644+index 3d149b3e7426b8f7c999603ddf1e15e12331c33a..73b9e8bbe30e6647b03cc1890806e8d48a1cbd8c 100644--- a/ios/MenuViewManager.mm+++ b/ios/MenuViewManager.mm@@ -1,6 +1,6 @@@@ -178,10 +178,19 @@ index 6a2a205f95c1001f3fdf6fb835815fa7c4c02c16..4f42b64349966fb1438f72439cec8256+}diff --git a/ios/Shared/MenuViewImplementation.swift b/ios/Shared/MenuViewImplementation.swift-index 5c4e0da4292b15d3a27b5ea1555f11452a470815..475a99b2a3b1800c9d3e3e5f77a64f552fa35828 100644+index 5c4e0da4292b15d3a27b5ea1555f11452a470815..381aa8e2900aeb0d2453dba514360304a79e95f1 100644--- a/ios/Shared/MenuViewImplementation.swift+++ b/ios/Shared/MenuViewImplementation.swift-@@ -60,17 +60,46 @@ public class MenuViewImplementation: UIButton {+@@ -17,7 +17,7 @@ public class MenuViewImplementation: UIButton {+ }+ _actions.removeAll()+ actions.forEach { menuAction in+- _actions.append(RCTMenuAction(details: menuAction).createUIMenuElement({action in self.sendButtonAction(action)}))++ _actions.append(RCTMenuAction(details: menuAction).createUIMenuElement({action in self.didSelectAction = true; self.sendButtonAction(action)}))+ }+ self.setup()+ }+@@ -60,17 +60,98 @@ public class MenuViewImplementation: UIButton {}public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {@@ -195,6 +204,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..475a99b2a3b1800c9d3e3e5f77a64f55+ self.setup()+ }+ isMenuPresented = true++ didSelectAction = false+ sendMenuInteractionStart()return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ inguard let self = self else { return nil }@@ -222,15 +232,66 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..475a99b2a3b1800c9d3e3e5f77a64f55+ pendingMenu = nil+ self.setup()+ }++ }++++ public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {++ return contentPreview() ?? super.contextMenuInteraction(interaction, previewForHighlightingMenuWithConfiguration: configuration)++ }++++ public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForDismissingMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {++ guard let preview = contentPreview() else {++ return super.contextMenuInteraction(interaction, previewForDismissingMenuWithConfiguration: configuration)++ }++ // A selection usually re-renders the trigger, so fade instead of landing on its old look.++ return didSelectAction ? nil : preview}++ // The button is a transparent overlay: morph from the React content so UIKit hides and restores it.++ // iOS 26 only, and only for content with its own corner radius; otherwise keep UIButton's default.++ private func contentPreview() -> UITargetedPreview? {++ guard #available(iOS 26.0, *) else {++ return nil++ }++ guard !shouldOpenOnLongPress, let siblings = self.superview?.subviews.filter({ $0 !== self }), siblings.count == 1, let content = siblings.first, content.window != nil, let (target, radius) = previewTarget(content) else {++ return nil++ }++ let bounds = target.bounds++ let parameters = UIPreviewParameters()++ parameters.backgroundColor = .clear++ parameters.visiblePath = UIBezierPath(roundedRect: bounds, cornerRadius: min(radius, bounds.height / 2, bounds.width / 2))++ return UITargetedPreview(view: target, parameters: parameters)++ }++++ // Walks the content's full-size single-child chain for its corner radius. A preview of a view++ // above a glass effect view drops the glass until UIKit restores the source, so target the glass view.++ private func previewTarget(_ content: UIView) -> (UIView, CGFloat)? {++ var radius: CGFloat?++ var view = content++ for depth in 0...4 {++ if radius == nil, view.layer.cornerRadius > 0 {++ radius = view.layer.cornerRadius++ }++ if let radius, view is UIVisualEffectView {++ return (view, radius)++ }++ guard depth < 4, view.subviews.count == 1, let child = view.subviews.first,++ abs(child.frame.size.width - view.bounds.size.width) <= 0.5,++ abs(child.frame.size.height - view.bounds.size.height) <= 0.5 else {++ break++ }++ view = child++ }++ return radius.map { (content, $0) }++ }++++ private var didSelectAction = false+ private var isMenuPresented = false+ private var pendingMenu: UIMenu?+func setup () {let menu = UIMenu(title: _title,identifier: nil,-@@ -86,8 +115,102 @@ public class MenuViewImplementation: UIButton {+@@ -86,8 +167,102 @@ public class MenuViewImplementation: UIButton {}}@@ -333,7 +394,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..475a99b2a3b1800c9d3e3e5f77a64f55}public override func reactSetFrame(_ frame: CGRect) {-@@ -124,4 +247,8 @@ public class MenuViewImplementation: UIButton {+@@ -124,4 +299,8 @@ public class MenuViewImplementation: UIButton {@objc func sendMenuOpen() {// NO-OP (should be overriden by parent)}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3e1dd4d26a4..0c2b6927c87 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -365,7 +365,7 @@ patchedDependencies:'@muse-code/[email protected]': 7b495b607fc5d76b444c7c4d58821e839726a30e6f3c53564f0d59f2d5b42101'@pierre/[email protected]': 322ac5f5db8b5715189c010802047f8235c3a45d8ed5ca0ba60fac266e2eba34'@react-native-ai/[email protected]': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d- '@react-native-menu/[email protected]': 910ec1bf22aa85a96fcf12299cd823bc30f702dd9b2d77b564d10b9ed709f7f6+ '@react-native-menu/[email protected]': 6872ba71b9847c5a0210b1b896923dadc3860faedfe28d9f062bcedfe786ef1d'@react-navigation/[email protected]': 990d575444c4af2ce8218b3b7a8280fe244c03abbdb32b822a2e862f791dbf42[email protected]: 07cc8c7e14b3b9af143ddd40a059f117c27e55139fbf20bd5dde2eb30509cedd[email protected]: 0fbe9ae51783f5768ebe197d12d1fdb7d477a08c92e5db2f6356bcce62613c53@@ -565,7 +565,7 @@ importers:version: 3.1.1([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])'@react-native-menu/menu':specifier: 2.0.0- version: 2.0.0(patch_hash=910ec1bf22aa85a96fcf12299cd823bc30f702dd9b2d77b564d10b9ed709f7f6)([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])+ version: 2.0.0(patch_hash=6872ba71b9847c5a0210b1b896923dadc3860faedfe28d9f062bcedfe786ef1d)([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])'@react-navigation/elements':specifier: 2.9.45version: 2.9.45(d8845bac868f4d8a58c8a8f12ad0d4a5)@@ -15714,7 +15714,7 @@ snapshots:react-native: 0.88.0(@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected])optional: true- '@react-native-menu/[email protected](patch_hash=910ec1bf22aa85a96fcf12299cd823bc30f702dd9b2d77b564d10b9ed709f7f6)([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])':+ '@react-native-menu/[email protected](patch_hash=6872ba71b9847c5a0210b1b896923dadc3860faedfe28d9f062bcedfe786ef1d)([email protected](@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected]))([email protected])':dependencies:react: 19.3.0react-native: 0.88.0(@babel/[email protected]([email protected]))(@react-native/[email protected](@babel/[email protected]([email protected]))([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected])