-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[iOS] Issue when using BindableLayout and Entry/Editor #15937
Comments
This issue seems to occur when binding a string longer than the length specified in MaxLength of Entry, Editor to TextProperty. The startPosition and endPosition obtained in the SetTextRange method of the TextInputExtions class were null. You should put a null check before calling GetTextRange method or consider MaxLength when calling GetPosition method. Below is the source code of .NET MAUI side. [src\Core\src\Platform\iOS\TextInputExtensions.cs]
If it is only a null check, it can be solved as follows. [src\Core\src\Platform\iOS\TextInputExtensions.cs]
|
Or if you consider MaxLength, [src\Core\src\Platform\iOS\TextInputExtensions.cs]
[src\Controls\src\Core\Platform\iOS\Extensions\TextExtensions.cs]
|
Additional Information: [HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 Java.Lang.IndexOutOfBoundsException: 'setSpan (11 ... 11) ends beyond length 10' [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.IndexOutOfBoundsException: setSpan (11 ... 11) ends beyond length 10 |
On the Android side, an IndexOutOfBoundsException occurred when calling the SetSelection method in the UpdateText method of the EditTextExtensions class. [src\Controls\src\Core\Platform\Android\Extensions\EditTextExtensions.cs]
If you consider the MaxLength property of Entry, Editor, [src\Controls\src\Core\Platform\Android\Extensions\EditTextExtensions.cs]
|
Exceptions don't occur on Windows, but if you want to do the same, it would look like this: [src\Controls\src\Core\Platform\Windows\Extensions\TextBoxExtensions.cs]
However, there is no problem with the Windows TextBox Select method even if you specify an Index that exceeds MaxLength, so there is no problem even if you do not include a guard condition. In addition to the solution in PR #7371, the MaxLength property should be considered. |
Hi, @juniorsaraviao [src\Controls\src\Core\Editor\Editor.Android.cs] In that case, you'll probably have to reimplement the MapText part yourself, but you'll have to port everything you need. |
We've just run into this error in our app on iOS devices only but I think its slightly different cause as we aren't exceeding MaxLength We've added a custom handler to sanitize the text as we want the result to be visible to the user if there was a change however when setting the sanitized text back to the entry or editor we get this crash (The handler gets called a few times before the crash and successfully completes) Ive added some code to check for exceeding the maxlength and we are nowhere near exceeding it, my current test is around 1600 characters in a 5000 character limit This is the handler we've added after adding the maxlength check in as well
The maxlength substring is not executing in the above as we aren't exceeding the maxlength This is the error we are getting
|
I ran into the same error, but the root cause was not the string length, but there were line breaks within the strings that was assigned. I now added logic that removes \r and \n from the string and the app does not crash anymore. |
The author of this PR to fix this has confirmed that this is no longer an issue. Please test with .NET 8 from next week and let us know if this has not been resolved for you. Thanks! |
@jfversluis I am just now encountering this issue and I am using net8.0. I can't for the life of me figure out what's causing it, it's with a new page that I have added to my app. It has some entries, editors as well as other controls. Navigating to the page causes no issue, neither does navigating back and returning to a new instance of the page. However, if I edit the value of one Entry for example, then navigate back and to a new instance this exception is thrown. The stack trace is here:
I need to do some more investigating but for now I am stumped. |
@varyamereon if that's the case please try and reproduce in a new .NET MAUI project built against .NET 8, add that project to a new issue and link to this one so we can track it properly. Please tag me and I will have a look, thanks! |
Absolutely will do when I get a chance, still trying to find out the root cause. |
@jfversluis ... I am also running into this issue. ---updated this to simplify after what I found:
Looking at the call stack below... it seems to occur on a UITextView... drilling in...
SOO... after all this... it seems it is definitely a result of having some special characters in a field... in combination with having previously brought up a keyboard/Picker/ any type of iOS native dialog
|
I have the same issue in .NET 8 only in iOS, when setting the text on an 'Editor' via a view model binding property. I do have some '\n' and '\r' values in the text for formatting. This is a showstopper for moving to Maui.
|
@jyotsnar as this issue is actually closed, please see new issue I created and linked |
Oh okay, thank you very much |
@jfversluis I could still replicate this issue, but I think the fix is here :) #20584 |
Description
I'm using a StackLayout with
BindableLayout.ItemsSource
to show Entry or Editor.However, the app throws an exception:
System.ArgumentNullException: Value cannot be null. (Parameter 'fromPosition')
Steps to Reproduce
Link to public reproduction project repository
https://github.com/juniorsaraviao/MauiSample
Version with bug
7.0.86
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 15.2 and up
Did you find any workaround?
No
Relevant log output
The text was updated successfully, but these errors were encountered: