Browse Source

ScrollAwareFABBehavior temporary fix.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
e170c2d3e8
  1. 11
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java
  2. 6
      app/src/main/res/layout/activity_topic.xml

11
app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java

@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.utils;
import android.content.Context; import android.content.Context;
import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
@ -14,7 +15,7 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior<FloatingA
@Override @Override
public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child,
final View directTargetChild, final View target, final int nestedScrollAxes) { final View directTargetChild, final View target, final int nestedScrollAxes) {
return true; return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
} }
@Override @Override
@ -24,7 +25,13 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior<FloatingA
final int dxUnconsumed, final int dyUnconsumed) { final int dxUnconsumed, final int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,dxUnconsumed, dyUnconsumed); super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,dxUnconsumed, dyUnconsumed);
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
child.hide(); child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
@Override
public void onHidden(FloatingActionButton fab) {
super.onHidden(fab);
fab.setVisibility(View.INVISIBLE);
}
});
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
child.show(); child.show();
} }

6
app/src/main/res/layout/activity_topic.xml

@ -21,7 +21,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:transitionName="toolbar"
app:popupTheme="@style/ToolbarTheme"> app:popupTheme="@style/ToolbarTheme">
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
@ -44,7 +43,6 @@
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginTop="-2dp" android:layout_marginTop="-2dp"
android:transitionName="bottom_navigation_bar"
app:elevation="8dp"> app:elevation="8dp">
<ImageButton <ImageButton
@ -110,7 +108,9 @@
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="54dp" android:layout_marginBottom="54dp"
android:layout_marginEnd="@dimen/fab_margins" android:layout_marginEnd="@dimen/fab_margins"
android:transitionName="fab" app:borderWidth="0dp"
app:layout_anchor="@id/topic_recycler_view"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior" app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior"
app:srcCompat="@drawable/ic_add_fab"/> app:srcCompat="@drawable/ic_add_fab"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

Loading…
Cancel
Save