Skip to content

Commit e5b3977

Browse files
committed
Improve the bottom UI to snap to bottom nav bar
(in cases where there's sufficient space available)
1 parent 46ff422 commit e5b3977

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/src/main/java/app/grapheneos/camera/ui/activities/MainActivity.kt

+9-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import androidx.core.content.ContextCompat
6161
import androidx.core.view.ViewCompat
6262
import androidx.core.view.WindowInsetsCompat
6363
import androidx.core.view.WindowInsetsControllerCompat
64+
import androidx.core.view.marginTop
6465
import androidx.core.view.updateLayoutParams
6566
import androidx.core.view.updateMargins
6667
import app.grapheneos.camera.App
@@ -1043,17 +1044,22 @@ open class MainActivity : AppCompatActivity(),
10431044
tabLayout.height -
10441045
10 * resources.displayMetrics.density.toInt()
10451046

1047+
// When there's no extra space in 16:9 for even the bottom nav bar to be present without
1048+
// obscuring the preview or if there's sufficient space for the entire bottom UI to exist
1049+
val shouldSnapAboveBottomNav = extraHeight169 < bottomNavigationBarPadding
1050+
|| extraHeight169 >= (threeButtons.height + tabLayout.height + tabLayout.marginTop)
1051+
10461052
tabLayout.layoutParams =
10471053
(tabLayout.layoutParams as ViewGroup.MarginLayoutParams).let {
10481054

10491055
it.setMargins(
10501056
it.leftMargin,
10511057
it.topMargin,
10521058
it.rightMargin,
1053-
if (extraHeight169 > 0) {
1054-
extraHeight169
1055-
} else {
1059+
if (shouldSnapAboveBottomNav) {
10561060
bottomNavigationBarPadding
1061+
} else {
1062+
extraHeight169
10571063
}
10581064
)
10591065

0 commit comments

Comments
 (0)