-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fix a11y wrong bounds calculation #1165
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,23 @@ | |
package androidx.compose.ui.platform | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.geometry.Rect | ||
import androidx.compose.ui.uikit.systemDensity | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.asCGPoint | ||
import androidx.compose.ui.unit.asCGRect | ||
import androidx.compose.ui.unit.asDpOffset | ||
import androidx.compose.ui.unit.toDpOffset | ||
import androidx.compose.ui.unit.toDpRect | ||
import androidx.compose.ui.unit.toOffset | ||
import kotlinx.cinterop.CValue | ||
import kotlinx.cinterop.readValue | ||
import kotlinx.cinterop.useContents | ||
import platform.CoreGraphics.CGRect | ||
import platform.CoreGraphics.CGRectZero | ||
import platform.UIKit.UIView | ||
import platform.UIKit.UIWindow | ||
|
||
/** | ||
* Tracking a state of window. | ||
|
@@ -33,6 +42,9 @@ internal class PlatformWindowContext { | |
private val _windowInfo = WindowInfoImpl() | ||
val windowInfo: WindowInfo get() = _windowInfo | ||
|
||
/** | ||
* A container used for additional layers and as reference for window coordinate space. | ||
*/ | ||
private var _windowContainer: UIView? = null | ||
|
||
fun setWindowFocused(focused: Boolean) { | ||
|
@@ -65,6 +77,36 @@ internal class PlatformWindowContext { | |
) | ||
} | ||
|
||
/** | ||
* Converts the given [Rect] from the coordinate space of the container window to the coordinate | ||
* space of the root UIWindow in which hierarchy with the container window resides. | ||
*/ | ||
fun convertContainerWindowRectToRootWindowCGRect(rect: Rect): CValue<CGRect> { | ||
val windowContainer = _windowContainer ?: return CGRectZero.readValue() | ||
|
||
val windowContainerWindow = windowContainer.window | ||
|
||
fun UIWindow.density(): Density { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to be local function, move to the end of the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to move it in that scope, because that's not a |
||
return Density(screen.scale.toFloat()) | ||
} | ||
|
||
return if (windowContainerWindow == null) { | ||
if (windowContainer is UIWindow) { | ||
// windowContainer is the root window itself | ||
rect.toDpRect(windowContainer.density()).asCGRect() | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
// windowContainer is not attached to any window | ||
CGRectZero.readValue() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we support the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we do. for this class without context from its usages, it means that |
||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. windowContainer.window will be null in case it's true, it's a redundant check. |
||
val cgRect = rect | ||
.toDpRect(windowContainerWindow.density()) | ||
.asCGRect() | ||
|
||
windowContainer.convertRect(cgRect, toView = windowContainerWindow) | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
private fun convertPoint(point: Offset, fromView: UIView, toView: UIView): Offset { | ||
return if (fromView != toView) { | ||
val density = fromView.systemDensity | ||
|
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.
It should return rect from parameters, not zero rect in the case
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.
Same as:
#1165 (comment)