mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +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 =
|
private final BottomSheetBehavior.BottomSheetCallback bottomSheetCallback =
|
||||||
new BottomSheetBehavior.BottomSheetCallback() {
|
new BottomSheetBehavior.BottomSheetCallback() {
|
||||||
|
int navigationHeight;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged(@NonNull View view, int state) {
|
public void onStateChanged(@NonNull View view, int state) {
|
||||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||||
|
|
@ -169,6 +171,12 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlide(@NonNull View view, float slideOffset) {
|
public void onSlide(@NonNull View view, float slideOffset) {
|
||||||
|
animateBottomSheet(slideOffset);
|
||||||
|
animateBottomNavigation(slideOffset, navigationHeight);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void animateBottomSheet(float slideOffset) {
|
||||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||||
if (playerBottomSheetFragment != null) {
|
if (playerBottomSheetFragment != null) {
|
||||||
float condensedSlideOffset = Math.max(0.0f, Math.min(0.2f, slideOffset - 0.2f)) / 0.2f;
|
float condensedSlideOffset = Math.max(0.0f, Math.min(0.2f, slideOffset - 0.2f)) / 0.2f;
|
||||||
|
|
@ -176,7 +184,18 @@ public class MainActivity extends BaseActivity {
|
||||||
playerBottomSheetFragment.getPlayerHeader().setVisibility(condensedSlideOffset > 0.99 ? View.GONE : View.VISIBLE);
|
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() {
|
private void initNavigation() {
|
||||||
bottomNavigationView = findViewById(R.id.bottom_navigation);
|
bottomNavigationView = findViewById(R.id.bottom_navigation);
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,21 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:behavior_hideable="true"
|
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" />
|
app:layout_behavior="@string/bottom_sheet_behavior" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
||||||
|
|
||||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
android:id="@+id/bottom_navigation"
|
android:id="@+id/bottom_navigation"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="80dp"
|
||||||
android:paddingStart="24dp"
|
android:paddingStart="24dp"
|
||||||
android:paddingEnd="24dp"
|
android:paddingEnd="24dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:menu="@menu/bottom_nav_menu" />
|
app:menu="@menu/bottom_nav_menu" />
|
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/offline_mode_text_view"
|
android:id="@+id/offline_mode_text_view"
|
||||||
style="@style/NoConnectionTextView"
|
style="@style/NoConnectionTextView"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="appbar_header_height">296dp</dimen>
|
<dimen name="appbar_header_height">296dp</dimen>
|
||||||
<dimen name="activity_margin_content">24dp</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="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="radius">2dp</dimen>
|
||||||
<dimen name="dots_height">2dp</dimen>
|
<dimen name="dots_height">2dp</dimen>
|
||||||
<dimen name="downloaded_item_padding">12dp</dimen>
|
<dimen name="downloaded_item_padding">12dp</dimen>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue