Skip to content

Commit 84299f7

Browse files
committed
Remove an early return to suppress a deprecated API warning for UIMenuController (facebook#42277)
Summary: `UIMenuController` is deprecated as of iOS 16. facebook@e08a197 migrated a usage into an `available` check. However, it does not properly fall back to the deprecated API in the "else" block of the availability check, instead it uses an early return. It seems this means Xcode still sees the API as used, and spits out a deprecated warning. Let's just refactor the code so we don't have that anymore. [IOS] [FIXED] - Remove an early return to suppress a deprecated API warning for `UIMenuController` Pull Request resolved: facebook#42277 Test Plan: CI should pass. Reviewed By: cipolleschi Differential Revision: D52785488 Pulled By: sammy-SC fbshipit-source-id: 0b47e8aa8d7c94728e3d68332fbb8f97f8ded34e
1 parent 7ad7df4 commit 84299f7

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

packages/react-native/Libraries/Text/Text/RCTTextView.m

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,15 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
386386
if (_editMenuInteraction) {
387387
[_editMenuInteraction presentEditMenuWithConfiguration:config];
388388
}
389-
return;
390-
}
391-
UIMenuController *menuController = [UIMenuController sharedMenuController];
392-
393-
if (menuController.isMenuVisible) {
394-
return;
395-
}
389+
} else {
390+
UIMenuController *menuController = [UIMenuController sharedMenuController];
396391

397-
if (!self.isFirstResponder) {
398-
[self becomeFirstResponder];
399-
}
392+
if (menuController.isMenuVisible) {
393+
return;
394+
}
400395

401-
[menuController showMenuFromView:self rect:self.bounds];
396+
[menuController showMenuFromView:self rect:self.bounds];
397+
}
402398
}
403399
#else // [macOS
404400

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,21 @@ - (void)disableContextMenu
251251

252252
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
253253
{
254-
if (@available(iOS 16.0, *)) {
254+
if (@available(iOS 16.0, macCatalyst 16.0, *)) {
255255
CGPoint location = [gesture locationInView:self];
256256
UIEditMenuConfiguration *config = [UIEditMenuConfiguration configurationWithIdentifier:nil sourcePoint:location];
257257
if (_editMenuInteraction) {
258258
[_editMenuInteraction presentEditMenuWithConfiguration:config];
259259
}
260-
return;
261-
}
262-
UIMenuController *menuController = [UIMenuController sharedMenuController];
260+
} else {
261+
UIMenuController *menuController = [UIMenuController sharedMenuController];
263262

264-
if (menuController.isMenuVisible) {
265-
return;
266-
}
263+
if (menuController.isMenuVisible) {
264+
return;
265+
}
267266

268-
if (!self.isFirstResponder) {
269-
[self becomeFirstResponder];
267+
[menuController showMenuFromView:self rect:self.bounds];
270268
}
271-
272-
[menuController showMenuFromView:self rect:self.bounds];
273269
}
274270
#endif // [macOS]
275271

0 commit comments

Comments
 (0)