forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS support
LiveRegion
semantics in a11y (#1258)
## Proposed Changes Add `UIAccessibilityTraitUpdatesFrequently` to elements with associated `SemanticsNode` having a `LiveRegion` property. Don't return a non-null refocused element if it's the same one before the sync unless it needs to happen (during the scroll to trigger private API). This prevents accessibility focus change (forcing it to previous element) if the semantics tree is synced continuously due to bug in iOS (UIAccessibilityFocusedElement returns older value) ## Testing Test: When a focused accessibility element has a `LiveRegion`, it will voice update in a given element. ## Issues Fixed Incorrect refocusing when semantics are synced continuously.
- Loading branch information
1 parent
c1db186
commit f92948f
Showing
4 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...mpp/demo/src/uikitMain/kotlin/androidx/compose/mpp/demo/AccessibilityLiveRegionExample.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,55 @@ | ||
/* | ||
* 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.mpp.demo | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.LiveRegionMode | ||
import androidx.compose.ui.semantics.liveRegion | ||
import androidx.compose.ui.semantics.semantics | ||
import kotlinx.coroutines.delay | ||
|
||
val AccessibilityLiveRegionExample = Screen.Example("Accessibility LiveRegion example") { | ||
var number by remember { mutableStateOf(0) } | ||
|
||
Column(modifier = Modifier.fillMaxSize()) { | ||
Text("Polite:") | ||
Text("Number $number", modifier = Modifier.semantics { | ||
liveRegion = LiveRegionMode.Polite | ||
}) | ||
|
||
Text("Assertive:") | ||
Text("Number $number", modifier = Modifier.semantics { | ||
liveRegion = LiveRegionMode.Assertive | ||
}) | ||
} | ||
|
||
// Update the number every second | ||
LaunchedEffect(Unit) { | ||
while (true) { | ||
number++ | ||
delay(1000) | ||
} | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
.../demo/src/uikitMain/kotlin/androidx/compose/mpp/demo/LazyColumnWithInteropViewsExample.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,46 @@ | ||
/* | ||
* 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.mpp.demo | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.Text | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.interop.UIKitView | ||
import androidx.compose.ui.unit.dp | ||
import platform.UIKit.UILabel | ||
|
||
val LazyColumnWithInteropViewsExample = Screen.Example("LazyColumn with interop views") { | ||
LazyColumn(modifier = Modifier.fillMaxSize()) { | ||
items(100) { | ||
if (it % 2 == 0) { | ||
UIKitView( | ||
factory = { | ||
val view = UILabel() | ||
view.text = "UILabel $it" | ||
view | ||
}, | ||
modifier = Modifier.fillMaxWidth().height(40.dp) | ||
) | ||
} else { | ||
Text("Text $it", Modifier.height(40.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