Skip to content

Commit

Permalink
Merge pull request #2 from manuel-martos/master
Browse files Browse the repository at this point in the history
Simplify the FooterBarBehavior.
  • Loading branch information
devunwired committed May 5, 2016
2 parents 40477f0 + 2f26ade commit b569fd1
Showing 1 changed file with 4 additions and 35 deletions.
Expand Up @@ -4,6 +4,7 @@
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.example.android.coordinatedeffort.widget.FooterBarLayout;
Expand All @@ -13,12 +14,6 @@
* and match its offset for a corresponding footer.
*/
public class FooterBarBehavior extends CoordinatorLayout.Behavior<FooterBarLayout> {

//Track offset for determining dependency changes
private int mDependencyOffset;
//Track initial layout position to properly offset child
private int mChildInitialOffset;

//Required to instantiate as a default behavior
public FooterBarBehavior() {
}
Expand All @@ -42,34 +37,8 @@ public boolean layoutDependsOn(CoordinatorLayout parent,
public boolean onDependentViewChanged(CoordinatorLayout parent,
FooterBarLayout child,
View dependency) {
//Check if the view position has actually changed
if (mDependencyOffset != dependency.getTop()) {
mDependencyOffset = dependency.getTop();

child.offsetTopAndBottom(
mChildInitialOffset - child.getTop() - mDependencyOffset);
//Notify that we changed our attached child
return true;
}

return false;
}

//This is called on each layout request.
@Override
public boolean onLayoutChild(CoordinatorLayout parent,
FooterBarLayout child,
int layoutDirection) {
//Lay out the view ourselves to hang to the bottom
child.layout(parent.getLeft(),
parent.getBottom() - child.getMeasuredHeight(),
parent.getRight(),
parent.getBottom());

//Gather initial state
mChildInitialOffset = child.getTop();

//Tell the framework not to bother
int offset = -dependency.getTop();
child.setTranslationY(offset);
return true;
}
}
}

0 comments on commit b569fd1

Please sign in to comment.