dotMorten / MauiEx

A set of .NET MAUI controls
Apache License 2.0
224 stars 55 forks source link

iOS renderer crashes when ItemsSource has values too early #49

Closed kicsiede closed 4 years ago

kicsiede commented 5 years ago

Description

iOS renderer crashes (fails on applying layout constraints) if ItemsSource is set too early. Probably because the view is not attached to a superview yet.

Steps to Reproduce

try changing the constructor in the Simple example to this:

public Simple () { InitializeComponent(); Initialize(); SuggestBox1.ItemsSource = countries; }

this is a showstopper for me because i initialize through bindings and set the BindingContext in the constructor.

Expected Behavior

no crash :)

Basic Information

majdaneq commented 5 years ago

Any workaround for this issue?

mzaeemkhan commented 5 years ago

same issue here

majdaneq commented 5 years ago

i've found the workaround - you can set the itemsSource onfocus of the autocomplete control - working on both platforms(Android+iOS)

mzaeemkhan commented 5 years ago

Tested it on iOS. Working great. Thanks

dotMorten commented 4 years ago

@kicsiede Sorry just getting around to looking into this now. I've tried adding the line of code you mentioned above, and that doesn't appear to cause any crash. Also tried setting the itemssource with a binding, or setting the itemssource specifically to null, and still nothing. Sample runs fine. Could you share a more specific example and preferably a stack trace as well?

AbdellahMobiArchitects commented 4 years ago

@dotMorten Same problem occurs, would love to see this fixed

dotMorten commented 4 years ago

@AbdellahOusrhireDev could you provide a sample app that reproduce this since I'm not seeing this. A stack Trace would be helpful too

dotMorten commented 4 years ago

Closing due to not being able to repro, and lacking information to trouble shoot. Feel free to provide a sample or at least a stack trace and reopen

REDECODE commented 4 years ago

Same error for me on iOS 13.1.3. The issue is caused if I assign the ItemsSource of the AutoSuggestBox in the constructor of the ContentPage with an ObservableCollection with more than one value. The AutoSuggestBox in my case is inside of a custom view, AutocompleteBoxed, see row 9 of the stack trace and AutocompleteBoxed is invisible:

Objective-C exception thrown. Name: NSGenericException Reason: Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x280acbc80 "UITableView:0x10d1f5000.top"> and <NSLayoutYAxisAnchor:0x280acbbc0 "UITextField:0x10c3e9ca0.bottom"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal. Native stack trace: 0 CoreFoundation 0x000000018b1549a0 DA838E75-6B30-360E-9661-C4800A7E1BF6 + 1227168 1 libobjc.A.dylib 0x000000018ae7d0a4 objc_exception_throw + 56 2 Foundation 0x000000018b42a40c 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 152588 3 Test.iOS 0x000000010625cbe8 wrapper_managed_to_native_ObjCRuntime_Messaging_void_objc_msgSend_bool_intptr_intptr_bool + 152 4 Test.iOS 0x00000001061b0060 UIKit_NSLayoutConstraint_set_Active_bool + 80 5 Test.iOS 0x0000000107568b48 dotMorten_Xamarin_Forms_Platform_iOS_iOSAutoSuggestBox_set_IsSuggestionListOpen_bool + 1688 6 Test.iOS 0x0000000107567f20 dotMorten_Xamarin_Forms_Platform_iOS_iOSAutoSuggestBox_SetItems_System_Collections_Generic_IEnumerable_1_object_System_Func_2_object_string_System_Func_2_object_string + 1280 7 Test.iOS 0x0000000107565560 dotMorten_Xamarin_Forms_Platform_iOS_AutoSuggestBoxRenderer_UpdateDisplayMemberPath + 672 8 Test.iOS 0x0000000107563610 dotMorten_Xamarin_Forms_Platform_iOS_AutoSuggestBoxRenderer_OnElementChanged_Xamarin_Forms_Platform_iOS_ElementChangedEventArgs_1_dotMorten_Xamarin_Forms_AutoSuggestBox + 2320 9 Test.iOS 0x00000001050f4dc8 Test_iOS_Custom_AutocompleteBoxedRenderer_OnElementChanged_Xamarin_Forms_Platform_iOS_ElementChangedEventArgs_1_dotMorten_Xamarin_Forms_AutoSuggestBox + 136 10 Test.iOS ...

The workaround suggested (assign the ItemsSource property on Focused event) worked for me

dotMorten commented 4 years ago

@REDECODE Any chance you could supply a repro? I haven't been able to reproduce this issue

REDECODE commented 4 years ago

I try to reproduce it but I need time to create a new project with only that component.. then I'll send it to you

REDECODE commented 4 years ago

You can download a sample from this link on Drive: https://drive.google.com/file/d/1RDfXfQP6lN6ZNTIrlq70A04vbA98oWVR/view?usp=sharing

dotMorten commented 4 years ago

Thank you! Much appreciated! I can repro with this. Looks like it's a constraint update issue. I'll try and get this addressed in the next few days

dotMorten commented 4 years ago

Should be fixed now. Let me know if this works for you too. Thank you so much for the reproducer! That made it so much simpler to fix.

REDECODE commented 4 years ago

It works! Many thanks to you and your component, it's really usefull. Have a good day :)

dotMorten commented 4 years ago

And thank you. A repro makes all the difference for me!