Skip to content
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

Workaround a11y issue with popups #792

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import java.awt.Point
import java.awt.Rectangle
import java.awt.event.FocusListener
import java.util.Locale
import java.util.concurrent.atomic.AtomicBoolean
import javax.accessibility.Accessible
import javax.accessibility.AccessibleAction
import javax.accessibility.AccessibleComponent
Expand All @@ -64,6 +65,7 @@ import javax.swing.text.AttributeSet
import kotlin.math.roundToInt
import org.jetbrains.skia.BreakIterator
import javax.swing.text.SimpleAttributeSet
import org.jetbrains.skiko.nativeInitializeAccessible

private fun <T> SemanticsConfiguration.getFirstOrNull(key: SemanticsPropertyKey<List<T>>): T? {
return getOrNull(key)?.firstOrNull()
Expand All @@ -78,8 +80,17 @@ internal class ComposeAccessible(
var semanticsNode: SemanticsNode,
val controller: AccessibilityControllerImpl? = null
) : Accessible {
private val isNativelyInitialized = AtomicBoolean(false)

val accessibleContext: ComposeAccessibleComponent by lazy { ComposeAccessibleComponent() }
override fun getAccessibleContext(): AccessibleContext = accessibleContext

override fun getAccessibleContext(): AccessibleContext {
Walingar marked this conversation as resolved.
Show resolved Hide resolved
// see doc for [nativeInitializeAccessible] for details, why this initialization is needed
if (isNativelyInitialized.compareAndSet(false, true)) {
nativeInitializeAccessible(this)
}
return accessibleContext
}

open inner class ComposeAccessibleComponent : AccessibleContext(), AccessibleComponent, AccessibleAction {
val textSelectionRange
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ moshi = "1.13.0"
protobuf = "3.21.8"
paparazzi = "1.0.0"
paparazziNative = "2022.1.1-canary-f5f9f71"
skiko = "0.7.77"
skiko = "0.7.79"
sqldelight = "1.3.0"
retrofit = "2.7.2"
wire = "4.5.1"
Expand Down