perf(article): hoist accessibility listener to screen level
Each article block registered its own assistive-accessibility listeners, so a long article accumulated one listener pair per block. Register the listeners once per article screen and share the state through a CompositionLocal so the block count no longer grows the listener set.
This commit is contained in:
1 parent
e733a2f3c0
commit
983e28fcf4
2 files changed
+14
-6
No files matched your search
@@ -31,6 +31,8 @@ import com.example.research.BuildConfig
|
||||
|
||||
internal val LocalForceStockArticleLinks = compositionLocalOf { false }
|
||||
|
||||
internal val LocalAssistiveAccessibilityEnabled = compositionLocalOf { false }
|
||||
|
||||
internal val ArticleReferenceAtOffsetAction =
|
||||
SemanticsPropertyKey<(Int) -> Boolean>("ArticleReferenceAtOffsetAction")
|
||||
|
||||
@@ -58,7 +60,7 @@ internal fun ArticleLinkText(
|
||||
modifier: Modifier = Modifier,
|
||||
preferDirectHitTesting: Boolean = false,
|
||||
) {
|
||||
val accessibilityEnabled = rememberAssistiveAccessibilityEnabled()
|
||||
val accessibilityEnabled = LocalAssistiveAccessibilityEnabled.current
|
||||
val inputMode = LocalInputModeManager.current.inputMode
|
||||
val forceStockLinks = LocalForceStockArticleLinks.current
|
||||
val useDirectLinkHitTesting =
|
||||
@@ -136,7 +138,7 @@ internal fun ArticleLinkText(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun rememberAssistiveAccessibilityEnabled(): Boolean {
|
||||
internal fun rememberAssistiveAccessibilityEnabled(): Boolean {
|
||||
val context = LocalContext.current
|
||||
val manager = remember(context) { context.getSystemService<AccessibilityManager>() }
|
||||
var enabled by remember(manager) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
@@ -134,6 +135,7 @@ fun ArticleContent(
|
||||
}
|
||||
}
|
||||
|
||||
val accessibilityEnabled = rememberAssistiveAccessibilityEnabled()
|
||||
val isHeavyArticle = articleState.isHeavy
|
||||
|
||||
val darkTheme = MaterialTheme.colorScheme.background.luminance() < 0.5f
|
||||
@@ -193,10 +195,14 @@ fun ArticleContent(
|
||||
.onSizeChanged { viewportSize = it }
|
||||
.windowInsetsPadding(AppWindowInsets.horizontalSafeDrawing)
|
||||
.padding(end = 16.dp)
|
||||
if (isHeavyArticle) {
|
||||
articleList(articleListModifier)
|
||||
} else {
|
||||
SelectionContainer { articleList(articleListModifier) }
|
||||
CompositionLocalProvider(
|
||||
LocalAssistiveAccessibilityEnabled provides accessibilityEnabled
|
||||
) {
|
||||
if (isHeavyArticle) {
|
||||
articleList(articleListModifier)
|
||||
} else {
|
||||
SelectionContainer { articleList(articleListModifier) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is ArticleState.Error -> {
|
||||
|
||||
Reference in new issue
Block a user