Bug 37673 - Mapbox SDK: "Width cannot be negative" exception when parent of Mapbox view is hidden
Summary: Mapbox SDK: "Width cannot be negative" exception when parent of Mapbox view i...
Status: RESOLVED ANSWERED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2016-01-14 02:29 UTC by bobme981
Modified: 2016-01-28 17:33 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
repro solution (56.19 KB, application/x-zip-compressed)
2016-01-14 02:29 UTC, bobme981
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description bobme981 2016-01-14 02:29:53 UTC
Created attachment 14579 [details]
repro solution

See attached repro solution using Xamarin.Forms.

If I set IsVisible=false directly on the MapboxView, no error occurs.
If I wrap the MapboxView in a ContentView and set IsVisible=false on the parent instead, the error occurs.

NOTE:
This DOES NOT repro on the Visual Studio Emulator for Android 7" KitKat (4.4) device.
This DOES repro on a real Amazon Kindle Fire HD running Fire OS 4.5.5.1.

Exception:
Java.Lang.IllegalArgumentException: width cannot be negative.

Stack trace:
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
  at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571
  at Android.Views.ViewGroup.Layout (Int32 l, Int32 t, Int32 r, Int32 b) [0x00082] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.ViewGroup.cs:3763
  at Xamarin.Forms.Platform.Android.ViewRenderer`2[TView,TNativeView].OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) [0x00059] in <filename unknown>:0
  at Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII (IntPtr jnienv, IntPtr native__this, Boolean p0, Int32 p1, Int32 p2, Int32 p3, Int32 p4) [0x00008] in <filename unknown>:0
  at at (wrapper dynamic-method) System.Object:71ec5384-e8fc-41f4-859f-23b7429a2a57 (intptr,intptr,bool,int,int,int,int)
  at --- End of managed exception stack trace ---
  at java.lang.IllegalArgumentException: width cannot be negative.
  at at com.mapbox.mapboxsdk.views.NativeMapView.resizeView(NativeMapView.java:109)
  at at com.mapbox.mapboxsdk.views.MapView.onSizeChanged(MapView.java:2019)
  at at android.view.View.sizeChange(View.java:15461)
  at at android.view.View.setFrame(View.java:15434)
  at at android.view.View.layout(View.java:15342)
  at at android.view.ViewGroup.layout(ViewGroup.java:4686)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ViewRenderer_2.n_onLayout(Native Method)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ViewRenderer_2.onLayout(ViewRenderer_2.java:46)
  at at android.view.View.layout(View.java:15346)
  at at android.view.ViewGroup.layout(ViewGroup.java:4686)
  at at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:29)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1.n_onLayout(Native Method)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:48)
  at at android.view.View.layout(View.java:15346)
<snip>
Comment 1 bobme981 2016-01-14 02:55:32 UTC
WORKAROUND:
Set the MapboxView's size to (0,0) instead of hiding it.

In XAML, looks like this:

  HorizontalOptions="Start"
  VerticalOptions="Start"
  WidthRequest="0"
  HeightRequest="0"

The horizontal/vertical options ensure the view does not get stretched to fill its parent (thus ignoring the width/height requests).
Comment 2 Jon Dick 2016-01-28 17:33:35 UTC
Thanks for posting back your workaround.  My suggestion was going to be something similar, since Forms is probably doing something the native view does not expect.

Glad you worked around it!