Bug 34777 - Android.Support.Design FloatingActionButton.Behavior overrides have same erasure
Summary: Android.Support.Design FloatingActionButton.Behavior overrides have same erasure
Status: ASSIGNED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Staging (addons.xamstage.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2015-10-12 15:20 UTC by Jon Douglas [MSFT]
Modified: 2018-03-14 19:09 UTC (History)
4 users (show)

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

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 for Bug 34777 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

Description Jon Douglas [MSFT] 2015-10-12 15:20:33 UTC
*Description

Given that an Android developer wants to override the Behavior of a FloatingActionButton, one might try to override the respective methods of the FloatingActionButton.Behavior class:

EX:

public class ScrollAwareFABBehavior : FloatingActionButton.Behavior
{
    public ScrollAwareFABBehavior(Context context, IAttributeSet attrs) {
    }

    public override bool OnStartNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View directTargetChild, View target, int nestedScrollAxes) {
        return nestedScrollAxes == ViewCompat.ScrollAxisVertical ||
            base.OnStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
    }

    public override void OnNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        base.OnNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);

        var fab = (FloatingActionButton)child;

        if (dyConsumed > 0 && fab.Visibility == ViewStates.Visible) {
            fab.Hide();
        } else if (dyConsumed < 0 && fab.Visibility != ViewStates.Visible) {
            fab.Show();
        }
    }

}

However this does not compile because of the following reasons:

Error		error: name clash: onNestedScroll(CoordinatorLayout,View,View,int,int,int,int) in ScrollAwareFABBehavior and onNestedScroll(CoordinatorLayout,V,View,int,int,int,int) in Behavior have the same erasure, yet neither overrides the other
	public void onNestedScroll (android.support.design.widget.CoordinatorLayout p0, android.view.View p1, android.view.View p2, int p3, int p4, int p5, int p6)
  where V is a type-variable:
    V extends View declared in class Behavior	App1SupportDesign	C:\Users\Jon\Documents\Visual Studio 2015\Projects\App1SupportDesign\App1SupportDesign\obj\Debug\android\src\md575713273f2d8dff0381300ecfb58f3cb\ScrollAwareFABBehavior.java	42

Error		error: name clash: onStartNestedScroll(CoordinatorLayout,View,View,View,int) in ScrollAwareFABBehavior and onStartNestedScroll(CoordinatorLayout,V,View,View,int) in Behavior have the same erasure, yet neither overrides the other
	public boolean onStartNestedScroll (android.support.design.widget.CoordinatorLayout p0, android.view.View p1, android.view.View p2, android.view.View p3, int p4)
  where V is a type-variable:
    V extends View declared in class Behavior	App1SupportDesign	C:\Users\Jon\Documents\Visual Studio 2015\Projects\App1SupportDesign\App1SupportDesign\obj\Debug\android\src\md575713273f2d8dff0381300ecfb58f3cb\ScrollAwareFABBehavior.java	34

*Reproduction

1. Create a File->New Android Application
2. Add the Xamarin.Android.Support.Design NuGet library to the project
3. Implement the class above "ScrollAwareFABBehavior"
4. Try to build the project and run into the errors above

*Workaround:

One can use the CoordinatorLayout.Behavior as a base class instead as it's the direct parent of FloatingActionButton.Behavior

https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.Behavior.html

*Related Materials:

https://stackoverflow.com/questions/31674372/xamarin-android-name-clash-when-overriding-methods-in-floatingactionbutton-behav

https://forums.xamarin.com/discussion/46837/name-clash-when-overriding-methods-in-floatingactionbutton-behavior

*Version

Xamarin.Android 5.1.7.12

Xamarin.Android.Support.Design 23.0.1.3-rc1
Comment 1 Przemysław Raciborski 2017-03-30 14:33:38 UTC
still exists in 25.2 Design library.
Comment 2 Ruben Macias 2017-04-09 18:43:22 UTC
It would be nice if this would get fixed.  I'm getting a good number of exceptions reported to Insights that is explained in the SO post:

http://stackoverflow.com/questions/39536519/java-lang-illegalargumentexception-rect-should-intersect-with-childs-bounds

The proposed workaround that most seem to agree prevents the crash is here:

http://stackoverflow.com/a/39875070

However, as you see in the proposed workaround, you need to override the following method:

public boolean getInsetDodgeRect(@NonNull CoordinatorLayout parent,
            @NonNull FloatingActionButton child, @NonNull Rect rect)

But this method is defined in FloatingActionButton.Behavior and not CoordinatorLayout.Behavior. So therefore, I can not implement the proposed fix for the errors I'm seeing in production.

Any chance that the priory in this can get bumped?  This was reported in 2015 and while inheriting from CoorindatorLayout.Behavior has worked so far, we're reaching the limits here and need this to be fixed for reasons I've stated above.

Thanks!
Comment 3 João Monteiro 2018-03-14 19:09:14 UTC
Bump! I would be very gratefull if this bug gets fixed, I can't use the workaround because it changes the default behaviour of the AppBarLayout. I really need this fixed... It is open since 2015...

I'm using version 25.0.4 of the design library.