-
Notifications
You must be signed in to change notification settings - Fork 15
ADFA-2646 | Fix window insets accumulation and landscape appbar behavior #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbbb087
fix: resolve window insets accumulation on app recreation and landsca…
jatezzz 5d7dff5
Merge branch 'stage' into fix/ADFA-2646-window-insets-accumulation
jatezzz 38021a9
fix: resolve inset handling and swipe-reveal animation issues
jatezzz 4acb29e
Merge branch 'stage' into fix/ADFA-2646-window-insets-accumulation
jatezzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
app/src/main/java/com/itsaky/androidide/utils/WindowInsetsExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package com.itsaky.androidide.utils | ||
|
|
||
| import android.content.res.Configuration | ||
| import android.view.View | ||
| import androidx.core.view.ViewCompat | ||
| import androidx.core.view.WindowInsetsCompat | ||
| import androidx.core.view.doOnAttach | ||
| import androidx.core.view.updatePadding | ||
| import com.itsaky.androidide.R | ||
| import com.itsaky.androidide.databinding.ContentEditorBinding | ||
| import com.blankj.utilcode.util.SizeUtils | ||
| import androidx.core.graphics.Insets | ||
| import android.view.ViewGroup | ||
| import androidx.core.view.updateLayoutParams | ||
|
|
||
| data class InitialPadding(val left: Int, val top: Int, val right: Int, val bottom: Int) | ||
|
|
||
| /** | ||
| * Gets or stores the view's original padding to prevent infinite accumulation when applying insets. | ||
| * | ||
| * @return The original [InitialPadding]. | ||
| */ | ||
| fun View.getOrStoreInitialPadding(): InitialPadding { | ||
| return (getTag(R.id.tag_initial_padding) as? InitialPadding) | ||
| ?: InitialPadding(paddingLeft, paddingTop, paddingRight, paddingBottom).also { | ||
| setTag(R.id.tag_initial_padding, it) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Applies top window insets responsively. Hides the AppBar in landscape mode and adjusts [appbarContent]. | ||
| * Forces an inset request on attach to prevent drawing behind system bars after activity recreation. | ||
| * | ||
| * @param appbarContent The inner content view to pad in landscape mode. | ||
| */ | ||
| fun View.applyResponsiveAppBarInsets(appbarContent: View) { | ||
| ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets -> | ||
| val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
| val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE | ||
|
|
||
| if (isLandscape) { | ||
| view.updatePadding(top = 0) | ||
| appbarContent.updatePadding(top = insets.top) | ||
| } else { | ||
| view.updatePadding(top = insets.top) | ||
| appbarContent.updatePadding(top = 0) | ||
| } | ||
| windowInsets | ||
| } | ||
|
|
||
| doOnAttach { it.requestApplyInsets() } | ||
| } | ||
|
|
||
| /** | ||
| * Applies root system window insets as padding, preserving the view's initial padding. | ||
| * Useful for deeply nested views (like DrawerLayouts) where standard inset listeners fail. | ||
| * | ||
| * @param applyLeft Apply left inset. | ||
| * @param applyTop Apply top inset. | ||
| * @param applyRight Apply right inset. | ||
| * @param applyBottom Apply bottom inset. | ||
| */ | ||
| fun View.applyRootSystemInsetsAsPadding( | ||
| applyLeft: Boolean = false, | ||
| applyTop: Boolean = false, | ||
| applyRight: Boolean = false, | ||
| applyBottom: Boolean = false | ||
| ) { | ||
| val initial = getOrStoreInitialPadding() | ||
|
|
||
| ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets -> | ||
| val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
|
|
||
| view.updatePadding( | ||
| left = initial.left + if (applyLeft) insets.left else 0, | ||
| top = initial.top + if (applyTop) insets.top else 0, | ||
| right = initial.right + if (applyRight) insets.right else 0, | ||
| bottom = initial.bottom + if (applyBottom) insets.bottom else 0 | ||
| ) | ||
| windowInsets | ||
| } | ||
|
|
||
| doOnAttach { it.requestApplyInsets() } | ||
| } | ||
|
|
||
| /** | ||
| * Applies immersive mode insets to editor UI elements that float near system bars. | ||
| * | ||
| * Keeps toggle buttons and bottom sheet aligned with system bars (status/nav). | ||
| */ | ||
| fun ContentEditorBinding.applyImmersiveModeInsets(systemBars: Insets) { | ||
| val baseMargin = SizeUtils.dp2px(16f) | ||
| val isRtl = root.layoutDirection == View.LAYOUT_DIRECTION_RTL | ||
| val endInset = if (isRtl) systemBars.left else systemBars.right | ||
|
|
||
| btnToggleTopBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
| topMargin = baseMargin + systemBars.top | ||
| marginEnd = baseMargin + endInset | ||
| } | ||
|
|
||
| btnToggleBottomBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
| bottomMargin = baseMargin + systemBars.bottom | ||
| marginEnd = baseMargin + endInset | ||
| } | ||
|
|
||
| bottomSheet.updatePadding(top = systemBars.top) | ||
| } | ||
|
|
||
| /** | ||
| * Recomputes bottom sheet offsets based on the current app bar height. | ||
| */ | ||
| fun ContentEditorBinding.refreshBottomSheetAnchor() { | ||
| bottomSheet.setOffsetAnchor(editorAppBarLayout) | ||
| } | ||
|
|
||
| /** | ||
| * Allows the bottom sheet to expand fully (no app bar anchor). | ||
| */ | ||
| fun ContentEditorBinding.resetBottomSheetAnchor() { | ||
| bottomSheet.resetOffsetAnchor() | ||
| } | ||
|
|
||
| /** | ||
| * Applies the correct bottom sheet anchor based on orientation. | ||
| */ | ||
| fun ContentEditorBinding.applyBottomSheetAnchorForOrientation(orientation: Int) { | ||
| if (orientation == Configuration.ORIENTATION_LANDSCAPE) { | ||
| refreshBottomSheetAnchor() | ||
| } else { | ||
| resetBottomSheetAnchor() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <item name="tag_initial_padding" type="id" /> | ||
| </resources> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.