perf: a11yEventCallbacks
Some checks are pending
Build-Apk / build (push) Waiting to run

This commit is contained in:
lisonge 2024-09-24 13:29:20 +08:00
parent c8a1e00077
commit 0da83e36aa
2 changed files with 6 additions and 2 deletions

View File

@ -76,6 +76,7 @@ class A11yService : AccessibilityService(), OnCreate, OnA11yConnected, OnA11yEve
onA11yConnected()
}
override val a11yEventCallbacks = mutableListOf<(AccessibilityEvent) -> Unit>()
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
if (event == null || !event.isUseful()) return
onA11yEvent(event)

View File

@ -43,12 +43,15 @@ interface OnDestroy : CanOnCallback {
}
interface OnA11yEvent : CanOnCallback {
val a11yEventCallbacks: MutableList<(AccessibilityEvent) -> Unit>
get() = getCallbacks(6)
fun onA11yEvent(f: (AccessibilityEvent) -> Unit) {
getCallbacks<(AccessibilityEvent) -> Unit>(6).add(f)
a11yEventCallbacks.add(f)
}
fun onA11yEvent(event: AccessibilityEvent) {
getCallbacks<(AccessibilityEvent) -> Unit>(6).forEach { it(event) }
a11yEventCallbacks.forEach { it(event) }
}
}