forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Proposed Changes - Unwrap unnecessary state for `LocalSafeArea`/`LocalLayoutMargins` - Override `LocalSafeArea`/`LocalLayoutMargins` for separate owners. - Replace `IOSInsets` to `PlatformInsets` - [Don't use data classes in an API](https://kotlinlang.org/docs/jvm-api-guidelines-backward-compatibility.html#don-t-use-data-classes-in-an-api) ## Changes in API ```diff -androidx.compose.ui.uikit.IOSInsets +androidx.compose.ui.platform.PlatformInsets ``` ```diff -androidx.compose.ui.uikit.LocalSafeAreaState +androidx.compose.ui.platform.LocalSafeArea ``` ```diff -androidx.compose.ui.uikit.LocalLayoutMarginsState +androidx.compose.ui.platform.LocalLayoutMargins ``` ## Testing ```kt Box(modifier = Modifier .fillMaxSize() .windowInsetsPadding(WindowInsets.systemBars) .background(Color.Green) ) Popup { Box(modifier = Modifier .fillMaxSize() .windowInsetsPadding(WindowInsets.systemBars) .background(Color.Red) ) } ``` Android | iOS (Before) | iOS (After) --- | --- | --- <img src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/8fe492a6-007e-4cbf-9c8a-fa6eea9bb056" height="600"> | <img src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/3168efba-0072-47aa-853a-1c44bd68e4e0" height="600"> | <img src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/3845efe8-eb8e-4c71-87e2-ea44dd73a91e" height="600"> ## Issues Fixed Fixes (partially) JetBrains/compose-multiplatform#3701
- Loading branch information
1 parent
ee1756a
commit 2be70cf
Showing
9 changed files
with
168 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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 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
74 changes: 74 additions & 0 deletions
74
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/PlatformInsets.skiko.kt
This file contains 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,74 @@ | ||
/* | ||
* Copyright 2023 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.platform | ||
|
||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
/** | ||
* This class represents platform insets. | ||
*/ | ||
@ExperimentalComposeUiApi | ||
@Immutable | ||
class PlatformInsets( | ||
@Stable | ||
val top: Dp = 0.dp, | ||
@Stable | ||
val bottom: Dp = 0.dp, | ||
@Stable | ||
val left: Dp = 0.dp, | ||
@Stable | ||
val right: Dp = 0.dp, | ||
) { | ||
companion object { | ||
val Zero = PlatformInsets(0.dp, 0.dp, 0.dp, 0.dp) | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is PlatformInsets) return false | ||
|
||
if (top != other.top) return false | ||
if (bottom != other.bottom) return false | ||
if (left != other.left) return false | ||
if (right != other.right) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = top.hashCode() | ||
result = 31 * result + bottom.hashCode() | ||
result = 31 * result + left.hashCode() | ||
result = 31 * result + right.hashCode() | ||
return result | ||
} | ||
|
||
override fun toString(): String { | ||
return "PlatformInsets(top=$top, bottom=$bottom, left=$left, right=$right)" | ||
} | ||
} | ||
|
||
internal fun PlatformInsets.exclude(insets: PlatformInsets) = PlatformInsets( | ||
left = (left - insets.left).coerceAtLeast(0.dp), | ||
top = (top - insets.top).coerceAtLeast(0.dp), | ||
right = (right - insets.right).coerceAtLeast(0.dp), | ||
bottom = (bottom - insets.bottom).coerceAtLeast(0.dp) | ||
) |
This file contains 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 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 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 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.