Skip to content

Commit d13f764

Browse files
committed
review comments
1 parent f3631bf commit d13f764

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

app/src/main/java/com/duckduckgo/app/systemsearch/SystemSearchActivity.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,21 @@ class SystemSearchActivity : DuckDuckGoActivity() {
214214
/**
215215
* One inset listener per view (each apply* replaces any prior listener on that view), and only on
216216
* the views that survive [configureOmnibar] (which removes the unused omnibar app bar):
217-
* - sides go on [ActivitySystemSearchBinding.rootView] in both modes
218-
* - top omnibar: status -> appBarLayout, nav + IME -> content (scrolling list)
219-
* - bottom omnibar: status -> content; nav + IME -> rootView bottom margin, so the whole root
220-
* (including the fixed-height appBarLayoutBottom) rises above the keyboard/gesture nav - padding
221-
* the fixed-height bar directly would just squeeze its content instead of moving it
217+
* - top omnibar: sides -> rootView, status -> appBarLayout, nav + IME -> content (scrolling list)
218+
* - bottom omnibar: status -> content; sides + nav + IME -> rootView bottom margin (single combined
219+
* listener - rootView can't take both [EdgeToEdgeHandler.applyHorizontalSystemBarInsets] and
220+
* [EdgeToEdgeHandler.applyNavigationBarInsetsAsMargin] separately, the second would drop the first),
221+
* so the whole root (including the fixed-height appBarLayoutBottom) rises above the keyboard/gesture
222+
* nav - padding the fixed-height bar directly would just squeeze its content instead of moving it
222223
*/
223224
private fun configureEdgeToEdgeInsets(isOmnibarAtTop: Boolean) {
224-
edgeToEdgeHandler.applyHorizontalSystemBarInsets(binding.rootView)
225225
if (isOmnibarAtTop) {
226+
edgeToEdgeHandler.applyHorizontalSystemBarInsets(binding.rootView)
226227
edgeToEdgeHandler.applyStatusBarInsets(binding.appBarLayout)
227228
edgeToEdgeHandler.applyScrollableNavigationBarInsets(binding.content)
228229
} else {
229230
edgeToEdgeHandler.applyStatusBarInsets(binding.content)
230-
edgeToEdgeHandler.applyNavigationBarInsetsAsMargin(binding.rootView)
231+
edgeToEdgeHandler.applyHorizontalInsetsAndNavigationBarMargin(binding.rootView)
231232
}
232233
}
233234

common/common-utils/src/main/java/com/duckduckgo/common/utils/edgetoedge/EdgeToEdgeHandler.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)