@@ -201,6 +201,39 @@ class EdgeToEdgeHandler @Inject constructor() {
201201 ViewCompat .requestApplyInsets(view)
202202 }
203203
204+ /* *
205+ * Combines [applyHorizontalSystemBarInsets] and [applyNavigationBarInsetsAsMargin] in a single listener, for
206+ * when both are needed on the *same* view: only one [androidx.core.view.OnApplyWindowInsetsListener] can be
207+ * attached per view, so calling both separately on the same view would silently drop the first one.
208+ *
209+ * @param view The view to pad on the left/right edges and set the bottom margin on; must use [ViewGroup.MarginLayoutParams].
210+ */
211+ fun applyHorizontalInsetsAndNavigationBarMargin (view : View ) {
212+ val initialLeft = view.paddingLeft
213+ val initialRight = view.paddingRight
214+ val initialBottomMargin = (view.layoutParams as ? ViewGroup .MarginLayoutParams )?.bottomMargin ? : 0
215+ view.applyInsets { insets ->
216+ val barsAndCutout = insets.getInsets(
217+ WindowInsetsCompat .Type .navigationBars() or WindowInsetsCompat .Type .displayCutout(),
218+ )
219+ view.updatePadding(
220+ left = initialLeft + barsAndCutout.left,
221+ right = initialRight + barsAndCutout.right,
222+ )
223+
224+ val bottom = insets.getInsets(
225+ WindowInsetsCompat .Type .navigationBars() or WindowInsetsCompat .Type .displayCutout() or WindowInsetsCompat .Type .ime(),
226+ ).bottom
227+ (view.layoutParams as ? ViewGroup .MarginLayoutParams )?.let { lp ->
228+ val newMargin = initialBottomMargin + bottom
229+ if (lp.bottomMargin != newMargin) {
230+ lp.bottomMargin = newMargin
231+ view.requestLayout()
232+ }
233+ }
234+ }
235+ }
236+
204237 /* *
205238 * Pads [view] on all four edges by the system-bar (status + navigation), display-cutout and IME insets, in a
206239 * single listener. Use for a screen whose root carries a full-bleed background and has no separate toolbar:
0 commit comments