From 493dbb21907c71e2a220876eddd08a5ea075e1e8 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Tue, 2 Apr 2024 12:22:32 -0700 Subject: [PATCH] Remove AutoFill from context menu when using `contextMenuHidden` (#43468) Summary: This pull request resolves the issue https://github.com/facebook/react-native/issues/43452 Previously, when utilizing `contextMenuHidden`, the context menu wasn't entirely hidden as the "AutoFill" option remained visible. However, it's now possible to eliminate it using the menu builder. ## Changelog: [IOS] [FIXED] - hide AutoFill from context menu when using `contextMenuHidden` Pull Request resolved: https://github.com/facebook/react-native/pull/43468 Test Plan: Manual tests in RNTester: https://github.com/facebook/react-native/assets/39670088/dc0f828c-f613-412d-b560-f3b795dd3ffb Reviewed By: javache Differential Revision: D54902269 Pulled By: tdn120 fbshipit-source-id: e0f3d3b5a0817db1c072caf2f01648432c7d868d --- .../Text/TextInput/Multiline/RCTUITextView.mm | 10 ++++++++++ .../Text/TextInput/Singleline/RCTUITextField.mm | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm index 3fb6c8d6226..4ccff230dd0 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm @@ -267,6 +267,16 @@ static UIColor *defaultPlaceholderColor(void) return [super canPerformAction:action withSender:sender]; } +- (void)buildMenuWithBuilder:(id)builder +{ + if (_contextMenuHidden) { + if (@available(iOS 17.0, *)) { + [builder removeMenuForIdentifier:UIMenuAutoFill]; + } + } + [super buildMenuWithBuilder:builder]; +} + #pragma mark - Dictation - (void)dictationRecordingDidEnd diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index 82b186ead5f..7ec5835df5c 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -142,6 +142,16 @@ return [super canPerformAction:action withSender:sender]; } +- (void)buildMenuWithBuilder:(id)builder +{ + if (_contextMenuHidden) { + if (@available(iOS 17.0, *)) { + [builder removeMenuForIdentifier:UIMenuAutoFill]; + } + } + [super buildMenuWithBuilder:builder]; +} + #pragma mark - Dictation - (void)dictationRecordingDidEnd