-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix Share Screen Crash on iPad #48220
Fix Share Screen Crash on iPad #48220
Conversation
| activityViewController.popoverPresentationController.sourceView = engineViewController.view; | ||
| activityViewController.popoverPresentationController.sourceRect = | ||
| CGRectMake(CGRectGetWidth(engineViewController.view.bounds) / 2, | ||
| CGRectGetHeight(engineViewController.view.bounds) / 2, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIKit uses this rect to tell where the pop over should be presented. This should be the rect of the selected text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but we would have to pass in the rect size/coords from the framework, and then add logic to make sure that the view is being rendered either above/below/next to the text so that it's not clipping off the screen depending on the position of the text and the current view bounds... which is totally doable but since this is a fatal crash I wanted to get it at least non-crashing as soon as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, looks like the positioning is automatically handled 👀 will update this PR
…m:louisehsu/engine into louisehsu/fix-share-screen-crashh-on-ipad
| CGRect transformedRectLeft = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| localRectFromFrameworkTransform:firstRect]; | ||
| CGRect lastRect = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| caretRectForPosition:(FlutterTextPosition*)range.end]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc range.end is exclusive.
| UITextRange* range = _textInputPlugin.textInputView.selectedTextRange; | ||
|
|
||
| CGRect firstRect = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| caretRectForPosition:(FlutterTextPosition*)range.start]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a look at firstRectForRange which takes the range directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesnt, or at least not usably. After transforming it gives me the coordinates for the top right corner of the first character, which is right, but the size is super, super off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a note here that we can't use firstRectForRange API since it's current implementation doesn't always return the full rect of the range.
| - (instancetype)initWithOwner:(FlutterTextInputPlugin*)textInputPlugin NS_DESIGNATED_INITIALIZER; | ||
|
|
||
| - (CGRect)localRectFromFrameworkTransform:(CGRect)incomingRect; | ||
| - (CGRect)caretRectForPosition:(UITextPosition*)position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you exposing these APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a TODO here, explaining that these are exposed to be used for your feature, but we should consider moving your feature inside this plugin so we don't have to expose it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you file an issue to further investigate this?
|
Out of curiosity, what's the benefit of accessing the position of the selected text from the engine and not passing it from the framework to the engine? |
|
@ueman The framework does all the positioning, and these values on the engine were passed from the framework in the first place. We don't want to pass the same information again. |
| CGRect lastRect = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| caretRectForPosition:(FlutterTextPosition*)range.end]; | ||
| CGRect transformedRectRight = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| localRectFromFrameworkTransform:lastRect]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this localRectFromFrameworkTransform do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you get global coordinates from local ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. The naming is a bit weird and sounds like the opposite.
| CGRectMake(transformedRectLeft.origin.x, transformedRectLeft.origin.y, | ||
| transformedRectRight.origin.x - transformedRectLeft.origin.x, | ||
| transformedRectLeft.size.height); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work for RTL language. possibly crash due to negative width
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, would it help if i just wrapped in abs() ? I dont know what rtl language is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abs() should work. but please try it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RTL = right-to-left, e.g. arabic/hebrew
| applicationActivities:nil] autorelease]; | ||
|
|
||
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { | ||
| // On iPad, the share screen is presented in a popover view, and requires a CGRect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires a sourceView and a sourceRect
| // not always return the full rect of the range. | ||
| CGRect firstRect = [(FlutterTextInputView*)_textInputPlugin.textInputView | ||
| caretRectForPosition:(FlutterTextPosition*)range.start]; | ||
| CGRect transformedRectLeft = [(FlutterTextInputView*)_textInputPlugin.textInputView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you avoid left/right since it's not correct for RTL languages?
…m:louisehsu/engine into louisehsu/fix-share-screen-crashh-on-ipad
…138954) flutter/engine@f331e0a...bec0dac 2023-11-23 [email protected] Fix not being able to hide iOS status bar via setEnabledSystemUIMode (flutter/engine#48271) 2023-11-22 [email protected] [web] Hook the new JS API to the FlutterViewManager (flutter/engine#48283) 2023-11-22 [email protected] Roll Skia from 3a79d7a618aa to 5606ef899116 (1 revision) (flutter/engine#48331) 2023-11-22 [email protected] Fix Share Screen Crash on iPad (flutter/engine#48220) 2023-11-22 [email protected] Delete unused/test only code from FML (flutter/engine#48327) 2023-11-22 [email protected] Roll Skia from 30ecaac60b47 to 3a79d7a618aa (1 revision) (flutter/engine#48328) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fixes flutter/flutter#138550 
…lutter#138954) flutter/engine@f331e0a...bec0dac 2023-11-23 [email protected] Fix not being able to hide iOS status bar via setEnabledSystemUIMode (flutter/engine#48271) 2023-11-22 [email protected] [web] Hook the new JS API to the FlutterViewManager (flutter/engine#48283) 2023-11-22 [email protected] Roll Skia from 3a79d7a618aa to 5606ef899116 (1 revision) (flutter/engine#48331) 2023-11-22 [email protected] Fix Share Screen Crash on iPad (flutter/engine#48220) 2023-11-22 [email protected] Delete unused/test only code from FML (flutter/engine#48327) 2023-11-22 [email protected] Roll Skia from 30ecaac60b47 to 3a79d7a618aa (1 revision) (flutter/engine#48328) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fixes flutter/flutter#138550
Pre-launch Checklist
///).