Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated workaround for iOS 16 UITextInput.SelectedTextRange crashes #9559

Merged
merged 5 commits into from
Aug 25, 2022

Conversation

spouliot
Copy link
Contributor

@spouliot spouliot commented Aug 20, 2022

GitHub Issue (If applicable): #9430

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

UITextInput.SelectedTextRange crashes on iOS 16 betas

What is the new behavior?

Updated workaround to avoid the runtime crash while keeping the UITextInput.SelectedTextRange functionality available.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Pro: It does not break app compatibility, selection works

Con: This does not work currently with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding --registrar=static to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)

Internal Issue (If applicable):

…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
@gitpod-io
Copy link

gitpod-io bot commented Aug 20, 2022

@jeromelaban
Copy link
Member

jeromelaban commented Aug 22, 2022

It looks like there's something the runtime tests don't like, but I'm not seeing any exceptions in the apps log. Maybe it's changing the runtime behavior of TextBox?

@spouliot
Copy link
Contributor Author

@jeromelaban it should not (change the behaviour). I'll investigate this asap, thanks!

@jeromelaban
Copy link
Member

So the crash here is like this:

Xamarin.iOS: Don't know how to marshal a return value of type 'System.IntPtr'. Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new

@spouliot
Copy link
Contributor Author

@jeromelaban doh! That's why I could not duplicate it. That's the issue I fixed in xamarin-macios and requires using --registrar=static for simulator builds (until the fix is available)

@jeromelaban
Copy link
Member

Excellent! Let's see if the CI is happier now ;) Thanks!

@spouliot
Copy link
Contributor Author

@jeromelaban the CI still need another commit to add this flag. Resetting my mono tree to test it right now :)

@jeromelaban
Copy link
Member

@spouliot I can confirm that it works with the static registrar !

@jeromelaban
Copy link
Member

SelectedRange's value is used here, so it seems we still need to read the proper content:

viewRectInScrollView = multilineTextBoxView.GetCaretRectForPosition(multilineTextBoxView.SelectedTextRange.Start);
. Do you need to expose that property as the original name? Since there's the attribute specifying the native name, it may not be required and we can put that property private with another name?

@spouliot
Copy link
Contributor Author

@jeromelaban I forgot to include that change with my earlier commit.

As far as I know (and tested) there's no issue marshalling the native UITextRange subclass into managed code. The problem seems only related when a managed UITextRange instance is sent to native code. That's why only the setter was causing crash.

@MartinZikmund MartinZikmund merged commit c94d459 into unoplatform:master Aug 25, 2022
jeromelaban added a commit that referenced this pull request Aug 25, 2022
jeromelaban added a commit that referenced this pull request Aug 26, 2022
jeromelaban added a commit that referenced this pull request Aug 28, 2022
jeromelaban added a commit that referenced this pull request Aug 30, 2022
jeromelaban added a commit that referenced this pull request Aug 30, 2022
jeromelaban added a commit that referenced this pull request Aug 31, 2022
jeromelaban added a commit that referenced this pull request Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants