Skip to content
Draft
Show file tree
Hide file tree
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 @@ -9,6 +9,7 @@ import androidx.annotation.LayoutRes
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import com.google.android.material.snackbar.Snackbar
Expand Down Expand Up @@ -49,12 +50,21 @@ object EdgeToEdge {
}
}

@JvmStatic
fun Snackbar.applyBottomInsets() {
fun Snackbar.applyBottomInsets(anchorView: View?) {
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
view.translationY = -windowInsets.keyboardSafeOffset().toFloat()
view.post {
val anchorOffset = if (anchorView != null && anchorView.isVisible) {
val lp = anchorView.layoutParams as? ViewGroup.MarginLayoutParams
anchorView.height + (lp?.bottomMargin ?: 0)
} else {
0
}

view.translationY = -maxOf(windowInsets.keyboardSafeOffset(), anchorOffset).toFloat()
}
windowInsets
}

ViewCompat.requestApplyInsets(view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ object SnackbarUtils {
view.findViewById<TextView>(R.id.snackbar_text)
textView.isSingleLine = false

if (anchorView?.visibility != View.GONE) {
this.anchorView = anchorView
}

if (displayDismissButton) {
view.findViewById<Button>(R.id.snackbar_action).let {
val dismissButton = ImageView(view.context).apply {
Expand Down Expand Up @@ -134,7 +130,7 @@ object SnackbarUtils {
}
}

applyBottomInsets()
applyBottomInsets(anchorView)
}.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void handleOnBackPressed() {
view,
getString(org.odk.collect.strings.R.string.finalized_form_edit_started),
SnackbarUtils.DURATION_LONG,
null,
view.findViewById(R.id.buttonholder),
null,
true
);
Expand Down