Skip to content

Instantly share code, notes, and snippets.

@mnirfan
Last active March 20, 2025 08:31
Show Gist options
  • Select an option

  • Save mnirfan/9b069334263476336a439a48a1e150dd to your computer and use it in GitHub Desktop.

Select an option

Save mnirfan/9b069334263476336a439a48a1e150dd to your computer and use it in GitHub Desktop.
add click listener
package com.nurulirfan.lynx.accessibilityelements
import android.content.Context
import android.view.View
+import android.view.accessibility.AccessibilityEvent
+import com.lynx.tasm.event.LynxCustomEvent
import com.lynx.tasm.behavior.LynxContext
import com.lynx.tasm.behavior.ui.view.AndroidView
import com.lynx.tasm.behavior.ui.view.UISimpleView
...
class RadioButton(context: LynxContext) : UISimpleView<AndroidView>(context) {
override fun createView(context: Context?): AndroidView {
return AndroidView(context).apply {
...
importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
tag = RadioButtonState(false, false, "")
+
+ setOnClickListener {
+ if (mDisabled) {
+ return@setOnClickListener
+ }
+
+ val isSelected = !mChecked
+
+ // Notify accessibility services about the change
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED)
+
+ emitEvent("change", mapOf("checked" to isSelected))
+ }
}
}
+ private fun emitEvent(name: String, value: Map<String, Any>?) {
+ val detail = LynxCustomEvent(sign, name)
+ value?.forEach { (key, v) ->
+ detail.addDetail(key, v)
+ }
+ lynxContext.eventEmitter.sendCustomEvent(detail)
+ }
+
override fun onLayoutUpdated() {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment