Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to remove unused/restricted code from the Compose-based bottom sheet dialog fragment implementation.
Changes:
- Replaced
com.google.android.material.internal.ViewUtils.doOnApplyWindowInsetsusage withViewCompat.setOnApplyWindowInsetsListener. - Removed
onViewCreatedlogic that previously configuredBottomSheetBehaviorand safe-area padding.
Comments suppressed due to low confidence (2)
app/src/main/java/one/mixin/android/ui/common/MixinComposeBottomSheetDialogFragment.kt:96
- Removing
onViewCreatedalso removed allBottomSheetBehaviorinitialization (settingpeekHeightviagetBottomSheetHeight, disabling dragging, adding the callback, and applying safe-area bottom padding). After this change,getBottomSheetHeight()is no longer called anywhere andonBottomSheetStateChanged/onBottomSheetSlidehooks will never fire; either restore the behavior setup somewhere appropriate (e.g.,onStart/setupDialog) or remove these now-dead APIs to avoid silent UI regressions.
override fun onStart() {
super.onStart()
dialog?.window?.let { window ->
SystemUIManager.lightUI(
app/src/main/java/one/mixin/android/ui/common/MixinComposeBottomSheetDialogFragment.kt:16
- Some imports here appear unused after removing
onViewCreated(e.g.CoordinatorLayout,WindowInsetsCompat, anddoOnPreDraw). If the project enforces no-unused-imports via lint/formatting, this will fail CI; please remove any unused imports.
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type.systemBars
import androidx.core.view.doOnPreDraw
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets -> | ||
| val insets = windowInsets.getInsets(systemBars()) | ||
| view.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
| updateMargins(top = topMargin + insets.top) |
There was a problem hiding this comment.
updateMargins(top = topMargin + insets.top) will add the system-bar inset on top of the current top margin every time insets are re-applied (e.g., configuration change), causing the margin to grow. Capture and use the initial top margin (like the previous initialMargins.top) or store it once (e.g., via a tag) and always compute initialTop + insets.top.
| ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets -> | |
| val insets = windowInsets.getInsets(systemBars()) | |
| view.updateLayoutParams<ViewGroup.MarginLayoutParams> { | |
| updateMargins(top = topMargin + insets.top) | |
| val initialTopMargin = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0 | |
| ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets -> | |
| val insets = windowInsets.getInsets(systemBars()) | |
| view.updateLayoutParams<ViewGroup.MarginLayoutParams> { | |
| updateMargins(top = initialTopMargin + insets.top) |
| updateMargins(top = topMargin + insets.top) | ||
| } | ||
| windowInsets | ||
| } |
There was a problem hiding this comment.
After setting an OnApplyWindowInsetsListener, the codebase typically calls ViewCompat.requestApplyInsets(view) to ensure the listener runs immediately (see e.g. CreateAccountFragment.applySafeTopPadding and similar). Consider requesting insets here as well; otherwise the top margin update may never run if insets were already applied before this listener was set.
| } | |
| } | |
| ViewCompat.requestApplyInsets(this) |
24a02b3 to
b8a94f1
Compare
No description provided.