Skip to content

Commit c0231d7

Browse files
afohrmandrchen
authored andcommitted
[FloatingToolbar] Add motion for horizontal and vertical configurations of the floating toolbar.
PiperOrigin-RevId: 695232457
1 parent 655dba1 commit c0231d7

9 files changed

+704
-12
lines changed

catalog/java/io/material/catalog/floatingtoolbar/res/layout/cat_floating_toolbar_fragment.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
~ See the License for the specific language governing permissions and
1414
~ limitations under the License.
1515
-->
16-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
<androidx.coordinatorlayout.widget.CoordinatorLayout
17+
xmlns:android="http://schemas.android.com/apk/res/android"
1718
xmlns:app="http://schemas.android.com/apk/res-auto"
1819
android:layout_width="match_parent"
1920
android:layout_height="match_parent">
@@ -126,4 +127,4 @@
126127
<include layout="@layout/cat_floating_toolbar_content" />
127128
</LinearLayout>
128129
</com.google.android.material.floatingtoolbar.FloatingToolbarLayout>
129-
</FrameLayout>
130+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

lib/java/com/google/android/material/behavior/HideBottomViewOnScrollBehavior.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
/**
4444
* The {@link Behavior} for a View within a {@link CoordinatorLayout} to hide the view off the
4545
* bottom of the screen when scrolling down, and show it when scrolling up.
46+
*
47+
* @deprecated Use {@link HideViewOnScrollBehavior} instead.
48+
* <p>TODO(b/378132394): Migrate usages of this class to {@link HideViewOnScrollBehavior}.
4649
*/
50+
@Deprecated
4751
public class HideBottomViewOnScrollBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
4852

4953
/**
50-
* Interface definition for a listener to be notified when the bottom view scroll state
51-
* changes.
54+
* Interface definition for a listener to be notified when the bottom view scroll state changes.
5255
*/
5356
public interface OnScrollStateChangedListener {
5457

@@ -79,9 +82,8 @@ public interface OnScrollStateChangedListener {
7982

8083
/** State of the bottom view when it's scrolled down. */
8184
public static final int STATE_SCROLLED_DOWN = 1;
82-
/**
83-
* State of the bottom view when it's scrolled up.
84-
*/
85+
86+
/** State of the bottom view when it's scrolled up. */
8587
public static final int STATE_SCROLLED_UP = 2;
8688

8789
private int height = 0;
@@ -183,7 +185,7 @@ public boolean isScrolledUp() {
183185
* screen.
184186
*/
185187
public void slideUp(@NonNull V child) {
186-
slideUp(child, /*animate=*/ true);
188+
slideUp(child, /* animate= */ true);
187189
}
188190

189191
/**
@@ -220,7 +222,7 @@ public boolean isScrolledDown() {
220222
* the screen.
221223
*/
222224
public void slideDown(@NonNull V child) {
223-
slideDown(child, /*animate=*/ true);
225+
slideDown(child, /* animate= */ true);
224226
}
225227

226228
/**
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.material.behavior;
18+
19+
import android.view.View;
20+
import android.view.ViewGroup.MarginLayoutParams;
21+
import android.view.ViewPropertyAnimator;
22+
import androidx.annotation.NonNull;
23+
import androidx.coordinatorlayout.widget.CoordinatorLayout;
24+
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
25+
26+
/**
27+
* The {@link Behavior} for a View within a {@link CoordinatorLayout} to hide the view off of the
28+
* bottom of the screen when scrolling down, and show it when scrolling up.
29+
*/
30+
final class HideBottomViewOnScrollDelegate extends HideViewOnScrollDelegate {
31+
32+
HideBottomViewOnScrollDelegate() {}
33+
34+
@Override
35+
int getViewEdge() {
36+
return HideOnScrollView.EDGE_BOTTOM;
37+
}
38+
39+
@Override
40+
<V extends View> int getSize(@NonNull V child, @NonNull MarginLayoutParams paramsCompat) {
41+
return child.getMeasuredHeight() + paramsCompat.bottomMargin;
42+
}
43+
44+
@Override
45+
<V extends View> void setAdditionalHiddenOffset(
46+
@NonNull V child, int size, int additionalHiddenOffset) {
47+
child.setTranslationY(size + additionalHiddenOffset);
48+
}
49+
50+
@Override
51+
int getTargetTranslation() {
52+
return 0;
53+
}
54+
55+
@Override
56+
<V extends View> void setViewTranslation(@NonNull V child, int targetTranslation) {
57+
child.setTranslationY(targetTranslation);
58+
}
59+
60+
@Override
61+
<V extends View> ViewPropertyAnimator getViewTranslationAnimator(
62+
@NonNull V child, int targetTranslation) {
63+
return child.animate().translationY(targetTranslation);
64+
}
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.material.behavior;
18+
19+
import android.view.View;
20+
import android.view.ViewGroup.MarginLayoutParams;
21+
import android.view.ViewPropertyAnimator;
22+
import androidx.annotation.NonNull;
23+
import androidx.coordinatorlayout.widget.CoordinatorLayout;
24+
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
25+
26+
/**
27+
* The {@link Behavior} for a View within a {@link CoordinatorLayout} to hide the view off of the
28+
* left side of the screen when scrolling down, and show it when scrolling up.
29+
*/
30+
final class HideLeftViewOnScrollDelegate extends HideViewOnScrollDelegate {
31+
32+
HideLeftViewOnScrollDelegate() {}
33+
34+
@Override
35+
int getViewEdge() {
36+
return HideOnScrollView.EDGE_LEFT;
37+
}
38+
39+
@Override
40+
<V extends View> int getSize(@NonNull V child, @NonNull MarginLayoutParams paramsCompat) {
41+
return child.getMeasuredWidth() + paramsCompat.leftMargin;
42+
}
43+
44+
@Override
45+
<V extends View> void setAdditionalHiddenOffset(
46+
@NonNull V child, int size, int additionalHiddenOffset) {
47+
child.setTranslationX(size - additionalHiddenOffset);
48+
}
49+
50+
@Override
51+
int getTargetTranslation() {
52+
return 0;
53+
}
54+
55+
@Override
56+
<V extends View> void setViewTranslation(@NonNull V child, int targetTranslation) {
57+
child.setTranslationX(-targetTranslation);
58+
}
59+
60+
@Override
61+
<V extends View> ViewPropertyAnimator getViewTranslationAnimator(
62+
@NonNull V child, int targetTranslation) {
63+
return child.animate().translationX(-targetTranslation);
64+
}
65+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.material.behavior;
18+
19+
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
20+
21+
import androidx.annotation.IntDef;
22+
import androidx.annotation.RestrictTo;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
25+
26+
/**
27+
* Class for constants and {@code IntDefs} to be shared between the different {@link
28+
* HideViewOnScrollBehavior} variations.
29+
*/
30+
final class HideOnScrollView {
31+
32+
/** The sheet slides out from the right edge of the screen. */
33+
static final int EDGE_RIGHT = 0;
34+
35+
/** The sheet slides out from the bottom edge of the screen. */
36+
static final int EDGE_BOTTOM = 1;
37+
38+
/** The sheet slides out from the left edge of the screen. */
39+
static final int EDGE_LEFT = 2;
40+
41+
/**
42+
* The edge of the screen that a sheet slides out from.
43+
*
44+
* @hide
45+
*/
46+
@RestrictTo(LIBRARY_GROUP)
47+
@IntDef({EDGE_RIGHT, EDGE_BOTTOM, EDGE_LEFT})
48+
@Retention(RetentionPolicy.SOURCE)
49+
@interface ViewEdge {}
50+
51+
private HideOnScrollView() {}
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.material.behavior;
18+
19+
import android.view.View;
20+
import android.view.ViewGroup.MarginLayoutParams;
21+
import android.view.ViewPropertyAnimator;
22+
import androidx.annotation.NonNull;
23+
import androidx.coordinatorlayout.widget.CoordinatorLayout;
24+
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
25+
26+
/**
27+
* The {@link Behavior} for a View within a {@link CoordinatorLayout} to hide the view off of the
28+
* right of the screen when scrolling down, and show it when scrolling up.
29+
*/
30+
final class HideRightViewOnScrollDelegate extends HideViewOnScrollDelegate {
31+
32+
HideRightViewOnScrollDelegate() {}
33+
34+
@Override
35+
int getViewEdge() {
36+
return HideOnScrollView.EDGE_RIGHT;
37+
}
38+
39+
@Override
40+
<V extends View> int getSize(@NonNull V child, @NonNull MarginLayoutParams paramsCompat) {
41+
return child.getMeasuredWidth() + paramsCompat.rightMargin;
42+
}
43+
44+
@Override
45+
<V extends View> void setAdditionalHiddenOffset(
46+
@NonNull V child, int size, int additionalHiddenOffset) {
47+
child.setTranslationX(size + additionalHiddenOffset);
48+
}
49+
50+
@Override
51+
int getTargetTranslation() {
52+
return 0;
53+
}
54+
55+
@Override
56+
<V extends View> void setViewTranslation(@NonNull V child, int targetTranslation) {
57+
child.setTranslationX(targetTranslation);
58+
}
59+
60+
@Override
61+
<V extends View> ViewPropertyAnimator getViewTranslationAnimator(
62+
@NonNull V child, int targetTranslation) {
63+
return child.animate().translationX(targetTranslation);
64+
}
65+
}

0 commit comments

Comments
 (0)