Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@LouiseHsu
Copy link
Contributor

@LouiseHsu LouiseHsu commented Nov 20, 2023

Fixes flutter/flutter#138550

Simulator Screenshot - iPad Air (5th generation) - 2023-11-21 at 03 33 37

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@LouiseHsu LouiseHsu changed the title Louisehsu/fix share screen crashh on ipad Fix Share Screen Crash on iPad Nov 20, 2023
@LouiseHsu LouiseHsu marked this pull request as ready for review November 20, 2023 17:31
activityViewController.popoverPresentationController.sourceView = engineViewController.view;
activityViewController.popoverPresentationController.sourceRect =
CGRectMake(CGRectGetWidth(engineViewController.view.bounds) / 2,
CGRectGetHeight(engineViewController.view.bounds) / 2, 0, 0);
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

CGRect transformedRectLeft = [(FlutterTextInputView*)_textInputPlugin.textInputView
localRectFromFrameworkTransform:firstRect];
CGRect lastRect = [(FlutterTextInputView*)_textInputPlugin.textInputView
caretRectForPosition:(FlutterTextPosition*)range.end];
Copy link
Contributor

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];
Copy link
Contributor

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.

Copy link
Contributor Author

@LouiseHsu LouiseHsu Nov 21, 2023

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.

Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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?

@ueman
Copy link
Contributor

ueman commented Nov 21, 2023

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?

@hellohuanlin
Copy link
Contributor

hellohuanlin commented Nov 21, 2023

@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];
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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);
}
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 23, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 23, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 23, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 23, 2023
…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
LouiseHsu added a commit to LouiseHsu/engine that referenced this pull request Nov 27, 2023
caseycrogers pushed a commit to caseycrogers/flutter that referenced this pull request Dec 29, 2023
…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
DenisovAV pushed a commit to DenisovAV/flutter-tvos-engine that referenced this pull request May 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share button in textfield menu crashes app on iPad

3 participants