mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 03:45:33 -04:00
#2186 scrolling finally works for reader with two bars
This commit is contained in:
parent
0c400205ab
commit
48e6ed28d1
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.nav.helper
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.bottomappbar.BottomAppBar
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import org.kiwix.kiwixmobile.R
|
||||
|
||||
class ScrollingViewWithBottomNavigationBehavior(context: Context, attrs: AttributeSet) :
|
||||
AppBarLayout.ScrollingViewBehavior(context, attrs) {
|
||||
// We add a bottom margin to avoid the bottom navigation bar
|
||||
private var bottomMargin = 0
|
||||
|
||||
override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean =
|
||||
super.layoutDependsOn(parent, child, dependency) || dependency is BottomNavigationView
|
||||
|
||||
override fun onDependentViewChanged(
|
||||
parent: CoordinatorLayout,
|
||||
child: View,
|
||||
dependency: View
|
||||
): Boolean {
|
||||
val result = super.onDependentViewChanged(parent, child, dependency)
|
||||
val readerBottomAppBar: BottomAppBar? = child.findViewById(R.id.bottom_toolbar)
|
||||
if (readerBottomAppBar != null) {
|
||||
val navBarYPosition = dependency.y
|
||||
val coordinatorHeight = parent.height
|
||||
val readerNavNewMargin = (coordinatorHeight - navBarYPosition).toInt()
|
||||
if (dependency is BottomNavigationView && readerNavNewMargin != bottomMargin) {
|
||||
bottomMargin = readerNavNewMargin
|
||||
val layout = readerBottomAppBar.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layout.bottomMargin = bottomMargin
|
||||
readerBottomAppBar.requestLayout()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun onDependentViewRemoved(parent: CoordinatorLayout, child: View, dependency: View) {
|
||||
super.onDependentViewRemoved(parent, child, dependency)
|
||||
}
|
||||
}
|
@ -22,28 +22,32 @@
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1">
|
||||
android:orientation="vertical">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="org.kiwix.kiwixmobile.main.NavigationHostFragment"
|
||||
<org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_weight="1"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_dodgeInsetEdges="bottom"
|
||||
app:navGraph="@navigation/kiwix_nav_graph"
|
||||
tools:ignore="FragmentTagUsage" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
|
||||
app:menu="@menu/menu_bottom_nav" />
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="org.kiwix.kiwixmobile.main.NavigationHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_behavior=".nav.helper.ScrollingViewWithBottomNavigationBehavior"
|
||||
app:layout_dodgeInsetEdges="bottom"
|
||||
app:navGraph="@navigation/kiwix_nav_graph"
|
||||
tools:ignore="FragmentTagUsage" />
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
|
||||
app:menu="@menu/menu_bottom_nav" />
|
||||
</org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user