forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 154
Remove ComposeUiFlags.areWindowInsetsRulersEnabled
#3211
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
Open
Vendula Švastalová (svastven)
wants to merge
2
commits into
jb-main
Choose a base branch
from
svastven/CMP-9823
base: jb-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
36 changes: 36 additions & 0 deletions
36
compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/DisableWindowInsetsRulers.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,36 @@ | ||
| /* | ||
| * Copyright 2026 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package androidx.compose.ui | ||
|
|
||
| /** | ||
| * Flag to disable WindowInsetsRulers. Some integrations need to disable WindowInsets Rulers for all | ||
| * Compose roots, so this is a global switch. We don't want them to add a new Compose root and have | ||
| * it suddenly request WindowInsets updates, changing the behavior so that the insets suddenly | ||
| * notify. | ||
| */ | ||
| internal var areWindowInsetsRulersEnabled: Boolean = true | ||
|
|
||
| /** | ||
| * Used to disable [androidx.compose.ui.layout.WindowInsetsRulers]. This can be used when UI never | ||
| * reads WindowInsets across all Compose roots to reduce the overhead of requesting WindowInsets | ||
| * updates. Only call this when no Compose roots will ever need to handle insets over the lifetime of | ||
| * the application. This should be called before the first Compose root is created. | ||
| */ | ||
| @ExperimentalComposeUiApi | ||
| fun disableWindowInsetsRulers() { | ||
| areWindowInsetsRulersEnabled = false | ||
| } | ||
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
87 changes: 87 additions & 0 deletions
87
...se/ui/ui/src/skikoTest/kotlin/androidx/compose/ui/layout/DisableWindowInsetsRulersTest.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,87 @@ | ||
| /* | ||
| * Copyright 2026 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package androidx.compose.ui.layout | ||
|
|
||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.areWindowInsetsRulersEnabled | ||
| import androidx.compose.ui.platform.PlatformInsets | ||
| import androidx.compose.ui.platform.PlatformWindowInsets | ||
| import androidx.compose.ui.test.ExperimentalTestApi | ||
| import androidx.compose.ui.test.InternalTestApi | ||
| import androidx.compose.ui.test.v2.runInternalSkikoComposeUiTest | ||
| import kotlin.test.AfterTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertTrue | ||
|
|
||
| @OptIn(ExperimentalTestApi::class, InternalTestApi::class) | ||
| class DisableWindowInsetsRulersTest { | ||
|
|
||
| @AfterTest | ||
| fun tearDown() { | ||
| areWindowInsetsRulersEnabled = true | ||
| } | ||
|
|
||
| @Test | ||
| fun disableWindowInsetsRulers() { | ||
| androidx.compose.ui.disableWindowInsetsRulers() | ||
|
|
||
| runInternalSkikoComposeUiTest( | ||
| windowInsets = TestWindowInsets(systemBarsInsets = mutableStateOf(PlatformInsets(top = 100))) | ||
| ) { | ||
| var left = 0f | ||
| var top = 0f | ||
| var right = 0f | ||
| var bottom = 0f | ||
|
|
||
| setContent { | ||
| Box( | ||
| Modifier.fillMaxSize().layout { measurable, constraints -> | ||
| val placeable = measurable.measure(constraints) | ||
| layout(placeable.width, placeable.height) { | ||
| placeable.place(0, 0) | ||
| left = WindowInsetsRulers.StatusBars.current.left.current(Float.NaN) | ||
| top = WindowInsetsRulers.StatusBars.current.top.current(Float.NaN) | ||
| right = WindowInsetsRulers.StatusBars.current.right.current(Float.NaN) | ||
| bottom = WindowInsetsRulers.StatusBars.current.bottom.current(Float.NaN) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| waitForIdle() | ||
|
|
||
| assertTrue(left.isNaN()) | ||
| assertTrue(top.isNaN()) | ||
| assertTrue(right.isNaN()) | ||
| assertTrue(bottom.isNaN()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun TestWindowInsets( | ||
| systemBarsInsets: androidx.compose.runtime.State<PlatformInsets> = mutableStateOf(PlatformInsets.Zero) | ||
| ): PlatformWindowInsets = object : PlatformWindowInsets { | ||
| override val statusBars: PlatformInsets get() = PlatformInsets( | ||
| getBottom = { systemBarsInsets.value.bottom }, | ||
| getTop = { systemBarsInsets.value.top }, | ||
| getLeft = { systemBarsInsets.value.left }, | ||
| getRight = { systemBarsInsets.value.right } | ||
| ) | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public API in commonMain is strictly no-go in fork. It will just crash on Android