-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NavigationRail] Navigation rail expansion
PiperOrigin-RevId: 689848271
- Loading branch information
1 parent
2e95296
commit 08c23dc
Showing
9 changed files
with
351 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...va/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_efab_header_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2024 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:id="@+id/cat_navigation_rail_efab_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:clipToPadding="false" | ||
android:clipChildren="false" | ||
android:layout_gravity="top|start"> | ||
<ImageView | ||
android:id="@+id/cat_navigation_rail_expand_button" | ||
android:layout_width="56dp" | ||
android:layout_height="56dp" | ||
android:src="@drawable/ic_drawer_menu_24px" | ||
android:contentDescription="@null" | ||
android:scaleType="center" /> | ||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton | ||
android:id="@+id/cat_navigation_rail_efab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:icon="@drawable/ic_add_24px" | ||
android:text="@string/cat_navigation_rail_efab_text"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
lib/java/com/google/android/material/navigationrail/LabelMoveTransition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.android.material.navigationrail; | ||
|
||
import android.animation.Animator; | ||
import android.animation.ValueAnimator; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.transition.Transition; | ||
import androidx.transition.TransitionValues; | ||
import com.google.android.material.navigation.NavigationBarMenuItemView; | ||
|
||
/** | ||
* A {@link Transition} that animates the {@link NavigationBarMenuItemView} label horizontally when | ||
* the label is fading in. | ||
*/ | ||
class LabelMoveTransition extends Transition { | ||
|
||
private static final String LABEL_VISIBILITY = "NavigationRailLabelVisibility"; | ||
private static final float HORIZONTAL_DISTANCE = -30f; | ||
|
||
@Override | ||
public void captureStartValues(@NonNull TransitionValues transitionValues) { | ||
transitionValues.values.put(LABEL_VISIBILITY, transitionValues.view.getVisibility()); | ||
} | ||
|
||
@Override | ||
public void captureEndValues(@NonNull TransitionValues transitionValues) { | ||
transitionValues.values.put(LABEL_VISIBILITY, transitionValues.view.getVisibility()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Animator createAnimator(@NonNull ViewGroup sceneRoot, | ||
@Nullable TransitionValues startValues, | ||
@Nullable TransitionValues endValues) { | ||
if (startValues == null || endValues == null | ||
|| startValues.values.get(LABEL_VISIBILITY) == null | ||
|| endValues.values.get(LABEL_VISIBILITY) == null) { | ||
return super.createAnimator(sceneRoot, startValues, endValues); | ||
} | ||
// Only animate if the view is appearing | ||
if ((int) startValues.values.get(LABEL_VISIBILITY) != View.GONE | ||
|| (int) endValues.values.get(LABEL_VISIBILITY) != View.VISIBLE) { | ||
return super.createAnimator(sceneRoot, startValues, endValues); | ||
} | ||
View view = endValues.view; | ||
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); | ||
animator.addUpdateListener( | ||
animation -> { | ||
float progress = animation.getAnimatedFraction(); | ||
view.setTranslationX(HORIZONTAL_DISTANCE * (1 - progress)); | ||
}); | ||
return animator; | ||
} | ||
} |
Oops, something went wrong.