Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the bottom UI to snap to bottom nav bar when necessary #517

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.marginTop
import androidx.core.view.updateLayoutParams
import androidx.core.view.updateMargins
import app.grapheneos.camera.App
Expand Down Expand Up @@ -1043,17 +1044,22 @@ open class MainActivity : AppCompatActivity(),
tabLayout.height -
10 * resources.displayMetrics.density.toInt()

// When there's no extra space in 16:9 for even the bottom nav bar to be present without
// obscuring the preview or if there's sufficient space for the entire bottom UI to exist
val shouldSnapAboveBottomNav = extraHeight169 < bottomNavigationBarPadding
|| extraHeight169 >= (threeButtons.height + tabLayout.height + tabLayout.marginTop)

tabLayout.layoutParams =
(tabLayout.layoutParams as ViewGroup.MarginLayoutParams).let {

it.setMargins(
it.leftMargin,
it.topMargin,
it.rightMargin,
if (extraHeight169 > 0) {
extraHeight169
} else {
if (shouldSnapAboveBottomNav) {
bottomNavigationBarPadding
} else {
extraHeight169
}
)

Expand Down