Feat: Expandable navigation rail on focus

This commit is contained in:
firelight
2025-08-21 03:51:52 +02:00
committed by GitHub
parent 6cc8b01119
commit 693f69f25f
3 changed files with 36 additions and 3 deletions

View File

@@ -1709,6 +1709,35 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
}
}
val rail = binding?.navRailView
if (rail != null && isLayout(TV)) {
val focus = mutableSetOf<Int>()
for (id in arrayOf(
R.id.navigation_home,
R.id.navigation_library,
R.id.navigation_search,
R.id.navigation_downloads,
R.id.navigation_settings
)) {
rail.findViewById<View?>(id)?.onFocusChangeListener =
View.OnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
focus += id
binding?.navRailView?.labelVisibilityMode = NavigationRailView.LABEL_VISIBILITY_LABELED
binding?.navRailView?.expand()
} else {
focus -= id
v.post {
if(focus.isEmpty()) {
binding?.navRailView?.labelVisibilityMode = NavigationRailView.LABEL_VISIBILITY_UNLABELED
binding?.navRailView?.collapse()
}
}
}
}
}
}
// Navigation button long click functionality to scroll to top
for (view in listOf(binding?.navView, binding?.navRailView)) {
view?.findViewById<View?>(R.id.navigation_home)?.setOnLongClickListener {

View File

@@ -25,14 +25,18 @@
<com.google.android.material.navigationrail.NavigationRailView
android:id="@+id/nav_rail_view"
android:layout_width="62dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="62dp"
android:maxWidth="62dp"
app:expanded="false"
app:expandedMaxWidth="180dp"
app:itemIconTint="@color/item_select_color"
app:itemTextColor="@color/item_select_color"
android:background="?attr/primaryGrayBackground"
android:descendantFocusability="afterDescendants"
app:headerLayout="@layout/rail_header"
app:labelVisibilityMode="unlabeled"
app:labelVisibilityMode="labeled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/bottom_nav_menu"

View File

@@ -23,7 +23,7 @@ kotlinGradlePluginVersion = "2.1.10"
kotlinxCoroutinesCore = "1.10.1"
lifecycleLivedataKtx = "2.8.7"
lifecycleViewmodelKtx = "2.8.7"
material = "1.12.0"
material = "1.14.0-alpha04"
media3 = "1.6.1"
navigationKtx = "2.8.9"
newpipeextractor = "v0.24.6"