mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: hide navigation bar on bottom sheet scroll
This commit is contained in:
parent
0101e0685b
commit
43e47080b2
3 changed files with 38 additions and 17 deletions
|
|
@ -147,6 +147,8 @@ public class MainActivity extends BaseActivity {
|
|||
|
||||
private final BottomSheetBehavior.BottomSheetCallback bottomSheetCallback =
|
||||
new BottomSheetBehavior.BottomSheetCallback() {
|
||||
int navigationHeight;
|
||||
|
||||
@Override
|
||||
public void onStateChanged(@NonNull View view, int state) {
|
||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||
|
|
@ -169,15 +171,32 @@ public class MainActivity extends BaseActivity {
|
|||
|
||||
@Override
|
||||
public void onSlide(@NonNull View view, float slideOffset) {
|
||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||
if (playerBottomSheetFragment != null) {
|
||||
float condensedSlideOffset = Math.max(0.0f, Math.min(0.2f, slideOffset - 0.2f)) / 0.2f;
|
||||
playerBottomSheetFragment.getPlayerHeader().setAlpha(1 - condensedSlideOffset);
|
||||
playerBottomSheetFragment.getPlayerHeader().setVisibility(condensedSlideOffset > 0.99 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
animateBottomSheet(slideOffset);
|
||||
animateBottomNavigation(slideOffset, navigationHeight);
|
||||
}
|
||||
};
|
||||
|
||||
private void animateBottomSheet(float slideOffset) {
|
||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||
if (playerBottomSheetFragment != null) {
|
||||
float condensedSlideOffset = Math.max(0.0f, Math.min(0.2f, slideOffset - 0.2f)) / 0.2f;
|
||||
playerBottomSheetFragment.getPlayerHeader().setAlpha(1 - condensedSlideOffset);
|
||||
playerBottomSheetFragment.getPlayerHeader().setVisibility(condensedSlideOffset > 0.99 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateBottomNavigation(float slideOffset, int navigationHeight) {
|
||||
if (slideOffset < 0) return;
|
||||
|
||||
if (navigationHeight == 0) {
|
||||
navigationHeight = bind.bottomNavigation.getHeight();
|
||||
}
|
||||
|
||||
float slideY = navigationHeight - navigationHeight * (1 - slideOffset);
|
||||
|
||||
bind.bottomNavigation.setTranslationY(slideY);
|
||||
}
|
||||
|
||||
private void initNavigation() {
|
||||
bottomNavigationView = findViewById(R.id.bottom_navigation);
|
||||
navHostFragment = (NavHostFragment) fragmentManager.findFragmentById(R.id.nav_host_fragment);
|
||||
|
|
|
|||
|
|
@ -24,19 +24,20 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:behavior_hideable="true"
|
||||
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
|
||||
app:behavior_peekHeight="@dimen/bottom_sheet_behavior_peek_height"
|
||||
app:layout_behavior="@string/bottom_sheet_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:visibility="gone"
|
||||
app:menu="@menu/bottom_nav_menu" />
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:visibility="gone"
|
||||
app:menu="@menu/bottom_nav_menu" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/offline_mode_text_view"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<resources>
|
||||
<dimen name="appbar_header_height">296dp</dimen>
|
||||
<dimen name="activity_margin_content">24dp</dimen>
|
||||
<dimen name="bottom_sheet_behavior_peek_height">136dp</dimen>
|
||||
<dimen name="bottom_sheet_peek_height">56dp</dimen>
|
||||
<dimen name="global_padding_bottom">128dp</dimen>
|
||||
<dimen name="global_padding_bottom">164dp</dimen>
|
||||
<dimen name="radius">2dp</dimen>
|
||||
<dimen name="dots_height">2dp</dimen>
|
||||
<dimen name="downloaded_item_padding">12dp</dimen>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue