Add Translate to iOS selection context menu#169150
Add Translate to iOS selection context menu#169150LouiseHsu wants to merge 18 commits intoflutter:masterfrom
Conversation
|
haven't reviewed PR but the video looks so nice! How did you get the popover size on iPad working? |
justinmc
left a comment
There was a problem hiding this comment.
Super cool to see swift in the engine. Thanks for supporting both the system context menu and the Flutter context menu. The framework code looks great
I checked this branch out locally and did a bunch of QA on it. Everything was very close to native with a few nits:
- While the translate menu is up, the selection and handles should be grey, but they remain blue on this branch.
- This is definitely beyond the scope of this PR. I don't think we currently have an easy way to do this.
- While the translate menu is up, the context menu should not be shown, but it is on this branch when using the Flutter-rendered context menu.
- It works using SystemContextMenu.
- Could you close the context menu on the framework side when the Translate button is tapped?
- The "Replace with Translation" button is missing on this branch.
- Any idea if it's possible to support this?
If you can confirm any of these but can't fix them in this PR, can you open an issue to track them? These are pretty minor; I think it's probably ok to ship this feature without fixes for any of them..
| FlutterTextInputPlugin* _textInputPlugin = [self.engine textInputPlugin]; | ||
| UITextRange* range = _textInputPlugin.textInputView.selectedTextRange; | ||
|
|
||
| // firstRectForRange cannot be used here as it's current implementation does |
| /// * [LiveTextInputStatusNotifier], where the status of Live Text can be listened to. | ||
| liveTextInput, | ||
|
|
||
| /// A button that displays the translation screen for the current text selection |
| Future<void> translateForSelection(SelectionChangedCause cause) async { | ||
| assert(!widget.obscureText); |
There was a problem hiding this comment.
Should we handle the case where this is called on a non-iOS platform? It's possible to call this directly without checking translateEnabled. Or what will happen if Translate.invoke is called on non-iOS?
Looks like we don't handle it in lookUpSelection etc. but maybe we should.
| CGRect transformedLastRect = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| localRectFromFrameworkTransform:lastRect]; | ||
|
|
||
| // In case of RTL Language, get the minimum x coordinate too |
| @override | ||
| String toString() { | ||
| return 'IOSSystemContextMenuItemTranslate(title: $title)'; | ||
| } |
There was a problem hiding this comment.
I think I made a mistake by adding these toString methods, I should have mixed in Diagnosticable and overridden debugFillProperties instead. Can you do that here, and I will open an issue for converting the rest of them?
|
CI had a failure that stopped further tests from running. We need to investigate to determine the root cause. SHA at time of execution: 504065d. Possible causes:
A blank commit, or merging to head, will be required to resume running CI for this PR. Error Details: Stack trace: |
|
I assume this is not ready for re-review yet but feel free to tag me whenever it is. |
Sorry, Im getting some accessibility tree failures that will take some time to dig into, but Im occupied with something else at the moment. 😿 Im gonna put this back into draft to get it off your queue |
|
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. |
|
Greetings from stale PR triage! 👋 |
|
Greetings once more from stale RP triage! Should we close this? It has many conflicts now and has not been updated since the last visit to triage. |
I will close it - Im planning on revisiting this next month but probably will open a new PR to avoid the 100000000 merge conflicts. |
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.
This is the first swiftui api in the engine so fingers crossed I don't break everything. 👀 😨
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
///).