Skip to content

Commit 17856f5

Browse files
mice777elizarov
authored andcommitted
Improved Android's onClick
It wrote that there's no "MouseEvent" on Android, actually there is android.view.MotionEvent. This sounds misleading. Here is proposal for improvement to pass through View parameter in onClick.
1 parent ae2791e commit 17856f5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ui/coroutines-guide-ui.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ update the text. Try it. It does not look very good. We'll fix it later.
306306

307307
> On Android, the corresponding extension can be written for `View` class, so that the code
308308
in `setup` function that is shown above can be used without changes. There is no `MouseEvent`
309-
on Android, so it is omitted.
309+
used in OnClickListener on Android, so it is omitted.
310310

311311
```kotlin
312312
fun View.onClick(action: suspend () -> Unit) {
@@ -352,18 +352,18 @@ animation is running. This happens because the actor is busy with an animation a
352352
By default, an actor's mailbox is backed by [RendezvousChannel], whose `offer` operation succeeds only when
353353
the `receive` is active.
354354

355-
> On Android, there is no `MouseEvent`, so we just send a `Unit` to the actor as a signal.
355+
> On Android, there is `View` sent in OnClickListener, so we send the `View` to the actor as a signal.
356356
The corresponding extension for `View` class looks like this:
357357

358358
```kotlin
359-
fun View.onClick(action: suspend () -> Unit) {
359+
fun View.onClick(action: suspend (View) -> Unit) {
360360
// launch one actor
361-
val eventActor = actor<Unit>(UI) {
362-
for (event in channel) action()
361+
val eventActor = actor<View>(UI) {
362+
for (event in channel) action(event)
363363
}
364364
// install a listener to activate this actor
365365
setOnClickListener {
366-
eventActor.offer(Unit)
366+
eventActor.offer(it)
367367
}
368368
}
369369
```

0 commit comments

Comments
 (0)