forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fixes Dialog position when platformLayers=false. We applied same logic as for Desktop sourceSet with `PlatformWindowContext` Co-authored-by: Ivan Matkov <ivan.matkov@jetbrains.com>
- Loading branch information
1 parent
1fb68c7
commit bdb31bf
Showing
5 changed files
with
147 additions
and
61 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...se/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/PlatformWindowContext.uikit.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,81 @@ | ||
/* | ||
* Copyright 2024 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.ui.input.pointer.PointerKeyboardModifiers | ||
import androidx.compose.ui.uikit.systemDensity | ||
import androidx.compose.ui.toDpRect | ||
import androidx.compose.ui.unit.IntRect | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.roundToIntRect | ||
import kotlinx.cinterop.useContents | ||
import platform.UIKit.UIView | ||
|
||
/** | ||
* This class copied from Desktop sourceSet. | ||
* Tracking a state of window. | ||
* | ||
* TODO: Extract information about window from [PlatformContext] in skiko source set. | ||
* | ||
*/ | ||
internal class PlatformWindowContext { | ||
private val _windowInfo = WindowInfoImpl() | ||
val windowInfo: WindowInfo get() = _windowInfo | ||
|
||
private var _windowContainer: UIView? = null | ||
|
||
fun setKeyboardModifiers(modifiers: PointerKeyboardModifiers) { | ||
_windowInfo.keyboardModifiers = modifiers | ||
} | ||
|
||
fun setWindowFocused(focused: Boolean) { | ||
_windowInfo.isWindowFocused = focused | ||
} | ||
|
||
fun setWindowContainer(windowContainer: UIView) { | ||
_windowContainer = windowContainer | ||
} | ||
|
||
fun setContainerSize(size: IntSize) { | ||
if (_windowInfo.containerSize != size) { | ||
_windowInfo.containerSize = size | ||
} | ||
} | ||
|
||
/** | ||
* Calculates the bounds of the given [container] within the window. | ||
* It uses [_windowContainer] as a reference for window coordinate space. | ||
* | ||
* @param container The container component whose bounds need to be calculated. | ||
* @return The bounds of the container within the window as an [IntRect] object. | ||
*/ | ||
fun boundsInWindow(container: UIView): IntRect { | ||
val density = container.systemDensity | ||
return if (_windowContainer != null && _windowContainer != container) { | ||
container.convertRect( | ||
rect = container.bounds, | ||
toView = _windowContainer, | ||
) | ||
} else { | ||
container.bounds | ||
}.useContents { | ||
with(density) { | ||
toDpRect().toRect().roundToIntRect() | ||
} | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/uikit/Extensions.uikit.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,33 @@ | ||
/* | ||
* Copyright 2024 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.uikit | ||
|
||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.window.uiContentSizeCategoryToFontScaleMap | ||
import platform.UIKit.UIContentSizeCategoryUnspecified | ||
import platform.UIKit.UIScreen | ||
import platform.UIKit.UITraitEnvironmentProtocol | ||
|
||
internal val UITraitEnvironmentProtocol.systemDensity: Density | ||
get() { | ||
val contentSizeCategory = | ||
traitCollection.preferredContentSizeCategory ?: UIContentSizeCategoryUnspecified | ||
return Density( | ||
density = UIScreen.mainScreen.scale.toFloat(), | ||
fontScale = uiContentSizeCategoryToFontScaleMap[contentSizeCategory] ?: 1.0f | ||
) | ||
} |
Oops, something went wrong.