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

Remove AccessibilitySyncOptions. Make the accessibility tree load lazily. #1780

Merged
merged 2 commits into from
Jan 21, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.AccessibilitySyncOptions
import androidx.compose.ui.uikit.LocalUIViewController
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.ComposeUIViewController
Expand All @@ -55,18 +54,12 @@ import platform.UIKit.sheetPresentationController
val NativePopupWithComposePopupExample = Screen.Example("Native popup with Compose popup") {
val viewController = LocalUIViewController.current

val syncOptions = AccessibilitySyncOptions.WhenRequiredByAccessibilityServices

Column {
Button(onClick = {
val presentedViewController = UIViewController(nibName = null, bundle = null)
presentedViewController.view.backgroundColor = UIColor.yellowColor

val composeViewController = ComposeUIViewController(
configure = {
accessibilitySyncOptions = syncOptions
}
) {
val composeViewController = ComposeUIViewController {
var showComposePopup by remember { mutableStateOf(false) }
var showComposeDialog by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -166,9 +159,7 @@ val NativePopupWithComposePopupExample = Screen.Example("Native popup with Compo

Button(
onClick = {
val composeViewController = ComposeUIViewController(configure = {
accessibilitySyncOptions = syncOptions
}) {
val composeViewController = ComposeUIViewController {
IosDemo("", null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ComponentsAccessibilitySemanticTest {
@Test
fun testButtonNodeActionAndSemantic() = runUIKitInstrumentedTest {
var tapped = false
setContentWithAccessibilityEnabled {
setContent {
Button({ tapped = true }) {
Text("Content")
}
Expand Down Expand Up @@ -115,7 +115,7 @@ class ComponentsAccessibilitySemanticTest {
@Test
fun testProgressNodesSemantic() = runUIKitInstrumentedTest {
var sliderValue = 0.4f
setContentWithAccessibilityEnabled {
setContent {
Column {
Slider(
value = sliderValue,
Expand Down Expand Up @@ -162,7 +162,7 @@ class ComponentsAccessibilitySemanticTest {
@Test
fun testSliderAction() = runUIKitInstrumentedTest {
var sliderValue = 0.4f
setContentWithAccessibilityEnabled {
setContent {
Slider(
value = sliderValue,
onValueChange = { sliderValue = it },
Expand All @@ -182,7 +182,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testToggleAndCheckboxSemantic() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column {
Switch(false, {})
Checkbox(false, {})
Expand Down Expand Up @@ -231,7 +231,7 @@ class ComponentsAccessibilitySemanticTest {
var checkbox by mutableStateOf(false)
var triStateCheckbox by mutableStateOf(ToggleableState.Off)

setContentWithAccessibilityEnabled {
setContent {
Column {
Switch(
checked = switch,
Expand Down Expand Up @@ -271,7 +271,7 @@ class ComponentsAccessibilitySemanticTest {
fun testRadioButtonSelection() = runUIKitInstrumentedTest {
var selectedIndex by mutableStateOf(0)

setContentWithAccessibilityEnabled {
setContent {
Column {
RadioButton(selected = selectedIndex == 0, onClick = { selectedIndex = 0 })
RadioButton(selected = selectedIndex == 1, onClick = { selectedIndex = 1 })
Expand Down Expand Up @@ -342,7 +342,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testImageSemantics() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column {
Image(
ImageBitmap(10, 10),
Expand Down Expand Up @@ -384,7 +384,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testTextSemantics() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column {
Text("Static Text", modifier = Modifier.testTag("Text 1"))
Text("Custom Button", modifier = Modifier.testTag("Text 2").clickable { })
Expand All @@ -409,7 +409,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testDisabledSemantics() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column {
Button({}, enabled = false) {}
TextField("", {}, enabled = false)
Expand Down Expand Up @@ -476,7 +476,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testHeadingSemantics() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Scaffold(topBar = {
TopAppBar {
Text("Header", modifier = Modifier.semantics { heading() })
Expand Down Expand Up @@ -514,7 +514,7 @@ class ComponentsAccessibilitySemanticTest {
)
}

setContentWithAccessibilityEnabled {
setContent {
SelectionContainer {
Column {
Text("Title")
Expand Down Expand Up @@ -547,7 +547,7 @@ class ComponentsAccessibilitySemanticTest {
fun testVisibleNodes() = runUIKitInstrumentedTest {
var alpha by mutableStateOf(0f)

setContentWithAccessibilityEnabled {
setContent {
Text("Hidden", modifier = Modifier.graphicsLayer {
this.alpha = alpha
})
Expand All @@ -569,7 +569,7 @@ class ComponentsAccessibilitySemanticTest {
fun testVisibleNodeContainers() = runUIKitInstrumentedTest {
var alpha by mutableStateOf(0f)

setContentWithAccessibilityEnabled {
setContent {
Column {
Text("Text 1")
Row(modifier = Modifier.graphicsLayer {
Expand Down Expand Up @@ -615,7 +615,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testAccessibilityContainer() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column(modifier = Modifier.testTag("Container")) {
Text("Text 1")
Text("Text 2")
Expand All @@ -638,7 +638,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testAccessibilityInterop() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column(modifier = Modifier.testTag("Container")) {
UIKitView(
factory = {
Expand Down Expand Up @@ -691,7 +691,7 @@ class ComponentsAccessibilitySemanticTest {

@Test
fun testChildrenOfCollapsedNode() = runUIKitInstrumentedTest {
setContentWithAccessibilityEnabled {
setContent {
Column {
Row(modifier = Modifier.testTag("row").clickable {}) {
Text("Foo", modifier = Modifier.testTag("row_title"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LayersAccessibilityTest {
val topPopup = mutableStateOf(false)
val bottomPopup = mutableStateOf(false)
val topPopupFocusable = mutableStateOf(false)
setContentWithAccessibilityEnabled {
setContent {
Text("Root")
if (bottomPopup.value) {
Popup {
Expand Down Expand Up @@ -93,7 +93,7 @@ class LayersAccessibilityTest {
@Test
fun testNodesCoveredByDialog() = runUIKitInstrumentedTest {
val showDialog = mutableStateOf(false)
setContentWithAccessibilityEnabled {
setContent {
Text("Root")
Popup {
Text("Popup")
Expand Down Expand Up @@ -136,7 +136,7 @@ class LayersAccessibilityTest {
fun testLayersAppearanceOrder() = runUIKitInstrumentedTest {
val bottomLayer = mutableStateOf(false)
val middleLayers = mutableStateOf(false)
setContentWithAccessibilityEnabled {
setContent {
Text("Root")
if (bottomLayer.value) {
Popup(properties = PopupProperties(focusable = true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package androidx.compose.ui.test

import androidx.compose.runtime.Composable
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.platform.AccessibilitySyncOptions
import androidx.compose.ui.platform.InfiniteAnimationPolicy
import androidx.compose.ui.scene.ComposeHostingViewController
import androidx.compose.ui.uikit.ComposeUIViewControllerConfiguration
Expand Down Expand Up @@ -96,11 +94,6 @@ internal class UIKitInstrumentedTest {

private val coroutineContext = Dispatchers.Main + infiniteAnimationPolicy

@OptIn(ExperimentalComposeApi::class)
fun setContentWithAccessibilityEnabled(content: @Composable () -> Unit) {
setContent({ accessibilitySyncOptions = AccessibilitySyncOptions.Always }, content)
}

fun setContent(
configure: ComposeUIViewControllerConfiguration.() -> Unit = {},
content: @Composable () -> Unit
Expand Down
Loading