feat: smooth navbar indicator
This commit is contained in:
parent
94e3dff909
commit
89aaef8355
2 changed files with 81 additions and 71 deletions
|
@ -13,7 +13,7 @@ class TripleNavAdapter(
|
|||
private val nav3: AnimatedBottomBar,
|
||||
anime: Boolean,
|
||||
format: String,
|
||||
isVertical: Boolean = false
|
||||
private val isScreenVertical: Boolean = false
|
||||
) {
|
||||
var selected: Int = 0
|
||||
var selectionListener: ((Int, Int) -> Unit)? = null
|
||||
|
@ -31,16 +31,12 @@ class TripleNavAdapter(
|
|||
}
|
||||
val commentTab = nav3.createTab(R.drawable.ic_round_comment_24, R.string.comments, R.id.comment)
|
||||
nav1.addTab(infoTab)
|
||||
nav2.addTab(watchTab)
|
||||
nav3.addTab(commentTab)
|
||||
nav1.visibility = ViewGroup.VISIBLE
|
||||
nav2.visibility = ViewGroup.VISIBLE
|
||||
nav3.visibility = ViewGroup.VISIBLE
|
||||
if (!isVertical) {
|
||||
nav1.indicatorColor = Color.TRANSPARENT
|
||||
nav2.indicatorColor = Color.TRANSPARENT
|
||||
nav3.indicatorColor = Color.TRANSPARENT
|
||||
} else {
|
||||
if (isScreenVertical) {
|
||||
nav2.visibility = ViewGroup.GONE
|
||||
nav3.visibility = ViewGroup.GONE
|
||||
nav1.addTab(watchTab)
|
||||
nav1.addTab(commentTab)
|
||||
nav1.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
|
@ -50,19 +46,14 @@ class TripleNavAdapter(
|
|||
nav3.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
}
|
||||
nav1.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
lastTab: AnimatedBottomBar.Tab?,
|
||||
newIndex: Int,
|
||||
newTab: AnimatedBottomBar.Tab
|
||||
) {
|
||||
selected = 0
|
||||
deselectOthers(selected)
|
||||
selectionListener?.invoke(selected, newTab.id)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
nav1.indicatorColor = Color.TRANSPARENT
|
||||
nav2.indicatorColor = Color.TRANSPARENT
|
||||
nav3.indicatorColor = Color.TRANSPARENT
|
||||
nav2.visibility = ViewGroup.VISIBLE
|
||||
nav3.visibility = ViewGroup.VISIBLE
|
||||
nav2.addTab(watchTab)
|
||||
nav3.addTab(commentTab)
|
||||
nav2.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
|
@ -88,6 +79,21 @@ class TripleNavAdapter(
|
|||
}
|
||||
})
|
||||
}
|
||||
nav1.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
lastTab: AnimatedBottomBar.Tab?,
|
||||
newIndex: Int,
|
||||
newTab: AnimatedBottomBar.Tab
|
||||
) {
|
||||
if (!isScreenVertical) {
|
||||
selected = 0
|
||||
deselectOthers(selected)
|
||||
} else selected = newIndex
|
||||
selectionListener?.invoke(selected, newTab.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun deselectOthers(selected: Int) {
|
||||
if (selected == 0) {
|
||||
|
@ -105,13 +111,17 @@ class TripleNavAdapter(
|
|||
}
|
||||
|
||||
fun selectTab(tab: Int) {
|
||||
selected = tab
|
||||
if (!isScreenVertical) {
|
||||
when (tab) {
|
||||
0 -> nav1.selectTabAt(0)
|
||||
1 -> nav2.selectTabAt(0)
|
||||
2 -> nav3.selectTabAt(0)
|
||||
}
|
||||
selected = tab
|
||||
deselectOthers(selected)
|
||||
} else {
|
||||
nav1.selectTabAt(selected)
|
||||
}
|
||||
}
|
||||
|
||||
fun setVisibility(visibility: Int) {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:fitsSystemWindows="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="false">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/mediaAppBar"
|
||||
|
@ -235,8 +235,8 @@
|
|||
android:id="@+id/mediaViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:layout_marginBottom="72dp"
|
||||
android:nestedScrollingEnabled="true"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -251,15 +251,15 @@
|
|||
android:id="@+id/mediaTab1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="72dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/colorSurface"
|
||||
android:padding="0dp"
|
||||
app:abb_animationInterpolator="@anim/over_shoot"
|
||||
app:abb_indicatorAppearance="round"
|
||||
app:abb_indicatorLocation="top"
|
||||
app:abb_selectedTabType="text"
|
||||
app:abb_textAppearance="@style/NavBarText"
|
||||
|
||||
|
||||
app:itemActiveIndicatorStyle="@style/BottomNavBar"
|
||||
app:itemIconTint="@color/tab_layout_icon"
|
||||
app:itemRippleColor="#00000000"
|
||||
|
@ -271,15 +271,15 @@
|
|||
android:id="@+id/mediaTab2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="72dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/colorSurface"
|
||||
android:padding="0dp"
|
||||
app:abb_animationInterpolator="@anim/over_shoot"
|
||||
app:abb_indicatorAppearance="round"
|
||||
app:abb_indicatorLocation="top"
|
||||
app:abb_selectedTabType="text"
|
||||
app:abb_textAppearance="@style/NavBarText"
|
||||
|
||||
|
||||
app:itemActiveIndicatorStyle="@style/BottomNavBar"
|
||||
app:itemIconTint="@color/tab_layout_icon"
|
||||
app:itemRippleColor="#00000000"
|
||||
|
@ -291,15 +291,15 @@
|
|||
android:id="@+id/mediaTab3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="72dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/colorSurface"
|
||||
android:padding="0dp"
|
||||
app:abb_animationInterpolator="@anim/over_shoot"
|
||||
app:abb_indicatorAppearance="round"
|
||||
app:abb_indicatorLocation="top"
|
||||
app:abb_selectedTabType="text"
|
||||
app:abb_textAppearance="@style/NavBarText"
|
||||
|
||||
|
||||
app:itemActiveIndicatorStyle="@style/BottomNavBar"
|
||||
app:itemIconTint="@color/tab_layout_icon"
|
||||
app:itemRippleColor="#00000000"
|
||||
|
@ -375,6 +375,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="16dp"
|
||||
android:visibility="gone"/>
|
||||
android:visibility="gone" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue