Add Translate to iOS selection context menu#180021
Add Translate to iOS selection context menu#180021LouiseHsu wants to merge 27 commits intoflutter:masterfrom
Conversation
engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/darwin/ios/framework/Source/TranslateController.swift
Outdated
Show resolved
Hide resolved
| if let rect = ipadBounds { | ||
| return .rect(rect) | ||
| } | ||
| return .bounds |
There was a problem hiding this comment.
Can you add a comment on why use different anchor source for iphone/ipad?
The format is off. @jmagman i remember you setup formatter in packages repo. Do we also have it setup for flutter repo?
There was a problem hiding this comment.
@LouiseHsu can you manually format this code in xcode by using CMD + A then Control + I
|
autosubmit label was removed for flutter/flutter/180021, because - The status or check suite Linux web_canvaskit_tests_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
|
|
| dest='variant', | ||
| action='store', | ||
| default='host_debug_unopt_arm64', | ||
| default='host_debug_unopt', |
|
Ugh, the test failures are real. The semantic node order is wrong even when the translate option is not being triggered - this failure occurs for a test for just a normal disabled text field. Note that root node in the expect has |
justinmc
left a comment
There was a problem hiding this comment.
Thanks for adding this button, I'm really happy that we can keep expanding functionality here. Just some ideas for tests and some grammar nits.
There are a few tests that should be added on the framework side for parity with how we did the other buttons. Some simple tests for the IOS* classes like:
flutter/packages/flutter/test/widgets/system_context_menu_test.dart
Lines 619 to 626 in 9c66d26
and
flutter/packages/flutter/test/widgets/system_context_menu_test.dart
Lines 718 to 725 in 9c66d26
Also test SystemContextMenuController.getDefaultItems, which now includes the new translate button. Something similar to this test, but maybe you need to make a selection first in order to get it to show up. Maybe you could just add on to that test.
@chunhtai do you have any idea why the semantics id would be changing in this case?
| FlutterTextInputPlugin* _textInputPlugin = [self.engine textInputPlugin]; | ||
| UITextRange* range = _textInputPlugin.textInputView.selectedTextRange; | ||
|
|
||
| // firstRectForRange cannot be used here as it's current implementation does |
| } | ||
| } | ||
|
|
||
| /// A [IOSSystemContextMenuItemData] for the system's built-in translate |
| /// * [LiveTextInputStatusNotifier], where the status of Live Text can be listened to. | ||
| liveTextInput, | ||
|
|
||
| /// A button that launches a translation popup for the current text selection |
|
This tree looks like pre test setup This means the semantics tree failed to compile for some reason. Are you sure there is no other exception gets thrown? |
| /// Whether share is enabled. | ||
| bool get shareEnabled => true; | ||
|
|
||
| /// Whether translate is enabled |
There was a problem hiding this comment.
| /// Whether translate is enabled | |
| /// Whether translate is enabled. |
| /// Currently this is only implemented for iOS. | ||
| /// | ||
| /// When 'obscureText' is true or the selection is empty, | ||
| /// this function will not do anything |
There was a problem hiding this comment.
| /// this function will not do anything | |
| /// this function will not do anything. |
| /// When 'obscureText' is true or the selection is empty, | ||
| /// this function will not do anything | ||
| Future<void> translateSelection(SelectionChangedCause cause) async { | ||
| assert(!widget.obscureText); |
There was a problem hiding this comment.
Should this line be removed? The comment indicates this method intends to no-op on obscured text.
|
@LouiseHsu Thanks for your contribution! Since I haven't seen a reply, I'm going to reluctantly close this pull request for now, but if you get time to address the comments, we'd be more than happy to take a look at a new patch. If you do send a new patch, it would be very useful to reference this one in the description in order to help reviewers see the previous context. |
|
An existing Git SHA, To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Fixes #150392, part of #107578
This PR adds a "Translate" action to the ios selection context menu using this swiftui translate api announce during WWDC 2024.
Includes the ipad implementation as well.
Simulator.Screen.Recording.-.iPad.Air.11-inch.M3.-.2025-05-28.at.14.11.58.mp4
Simulator.Screen.Recording.-.iPhone.16.Plus.-.2025-05-28.at.14.09.13.mp4
Pre-launch Checklist
///).