2020
2121import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
2222import static androidx .core .content .ContextCompat .getSystemService ;
23- import static com .google .android .material .behavior .HideOnScrollView .EDGE_BOTTOM ;
24- import static com .google .android .material .behavior .HideOnScrollView .EDGE_LEFT ;
25- import static com .google .android .material .behavior .HideOnScrollView .EDGE_RIGHT ;
2623
2724import android .animation .Animator ;
2825import android .animation .AnimatorListenerAdapter ;
4643import androidx .coordinatorlayout .widget .CoordinatorLayout .LayoutParams ;
4744import androidx .core .view .ViewCompat ;
4845import com .google .android .material .animation .AnimationUtils ;
49- import com .google .android .material .behavior .HideOnScrollView .ViewEdge ;
5046import com .google .android .material .motion .MotionUtils ;
47+ import java .lang .annotation .Retention ;
48+ import java .lang .annotation .RetentionPolicy ;
5149import java .util .LinkedHashSet ;
5250
5351/**
5452 * The {@link Behavior} for a View within a {@link CoordinatorLayout} to hide the view off of the
5553 * edge of the screen when scrolling down, and show it when scrolling up.
5654 *
57- * <p>Supports hiding the View off of three screen edges: {@link HideOnScrollView #EDGE_RIGHT},
58- * {@link HideOnScrollView#EDGE_BOTTOM} and {@link HideOnScrollView #EDGE_LEFT}.
55+ * <p>Supports hiding the View off of three screen edges: {@link #EDGE_RIGHT}, {@link #EDGE_BOTTOM },
56+ * and {@link #EDGE_LEFT}.
5957 *
6058 * <p>If Touch Exploration is enabled, the hide on scroll behavior should be disabled until Touch
6159 * Exploration is disabled. Ensure that the content is not obscured due to disabling this behavior
@@ -99,6 +97,25 @@ public interface OnScrollStateChangedListener {
9997 @ Nullable private TimeInterpolator enterAnimInterpolator ;
10098 @ Nullable private TimeInterpolator exitAnimInterpolator ;
10199
100+ /** The sheet slides out from the right edge of the screen. */
101+ public static final int EDGE_RIGHT = 0 ;
102+
103+ /** The sheet slides out from the bottom edge of the screen. */
104+ public static final int EDGE_BOTTOM = 1 ;
105+
106+ /** The sheet slides out from the left edge of the screen. */
107+ public static final int EDGE_LEFT = 2 ;
108+
109+ /**
110+ * The edge of the screen that a sheet slides out from.
111+ *
112+ * @hide
113+ */
114+ @ RestrictTo (LIBRARY_GROUP )
115+ @ IntDef ({EDGE_RIGHT , EDGE_BOTTOM , EDGE_LEFT })
116+ @ Retention (RetentionPolicy .SOURCE )
117+ @interface ViewEdge {}
118+
102119 /** State of the view when it's scrolled out. */
103120 public static final int STATE_SCROLLED_OUT = 1 ;
104121
@@ -120,25 +137,42 @@ public interface OnScrollStateChangedListener {
120137 private int additionalHiddenOffset = 0 ;
121138 @ Nullable private ViewPropertyAnimator currentAnimator ;
122139
140+ private boolean viewEdgeOverride = false ;
141+
123142 public HideViewOnScrollBehavior () {}
124143
144+ public HideViewOnScrollBehavior (@ ViewEdge int viewEdge ) {
145+ this ();
146+
147+ setViewEdge (viewEdge );
148+ }
149+
125150 public HideViewOnScrollBehavior (@ NonNull Context context , @ Nullable AttributeSet attrs ) {
126151 super (context , attrs );
127152 }
128153
129154 private void setViewEdge (@ NonNull V view , int layoutDirection ) {
155+ if (viewEdgeOverride ) {
156+ return ;
157+ }
158+
130159 LayoutParams params = (LayoutParams ) view .getLayoutParams ();
131160 int viewGravity = params .gravity ;
132161
133162 if (isGravityBottom (viewGravity )) {
134- setViewEdge (EDGE_BOTTOM );
163+ setViewEdgeInternal (EDGE_BOTTOM );
135164 } else {
136165 viewGravity = Gravity .getAbsoluteGravity (viewGravity , layoutDirection );
137- setViewEdge (isGravityLeft (viewGravity ) ? EDGE_LEFT : EDGE_RIGHT );
166+ setViewEdgeInternal (isGravityLeft (viewGravity ) ? EDGE_LEFT : EDGE_RIGHT );
138167 }
139168 }
140169
141170 public void setViewEdge (@ ViewEdge int viewEdge ) {
171+ viewEdgeOverride = true ;
172+ setViewEdgeInternal (viewEdge );
173+ }
174+
175+ private void setViewEdgeInternal (@ ViewEdge int viewEdge ) {
142176 if (hideOnScrollViewDelegate == null || hideOnScrollViewDelegate .getViewEdge () != viewEdge ) {
143177 switch (viewEdge ) {
144178 case EDGE_RIGHT :
0 commit comments