1

I'm trying to design a modifier that can be used in composable where if you click, it'll automatically log something. e.g. Modifier.logClick = then(Modifier.clickable{ //log })

The problem here is that when users apply to composable that come with onClick such as Button, my modifier.logClick{} is then overwritten since internally, onClick() block is getting assigned as Modifier.clickable.

Is there a way that I can achieve what I want gracefully? Maybe such as merging two same modifiers or executing sequentially?

Yao
  • 709
  • 2
  • 11
  • 22
  • check out [this answer](https://stackoverflow.com/a/68878910/3585796) – Phil Dukhov May 10 '22 at 03:19
  • Thanks for sharing. I believe the suggested answer is talking about a very different scenario, where it's trying to consume one click for two different composable while I'm trying to attach/merge 2 clickable modifiers to 1 composable. – Yao May 10 '22 at 16:58
  • I see, you can disable button (or just don't use it at all) so your clickable will be the only touch receiver. – Phil Dukhov May 10 '22 at 17:04
  • For more clarity, what I'm building is a library that offers a custom modifier like `Modifier.logEvent("something")`. So I restrict myself from taking away the functionality user has such as disabling the onClick in Button – Yao May 10 '22 at 17:15
  • I don't see how your scenario is different, with my modifier your log will get the click, print the log, and then the button will get the click and consume it – Phil Dukhov May 10 '22 at 17:17
  • 1
    Thanks for the reference. I am able to get it to work. Although I'm hoping compose can itself gives you some native support as the approach we take requires to copy and paste code including internal objects. Anyway, I upvoted the original answer. – Yao May 10 '22 at 22:39

1 Answers1

0

For anyone who's looking for a solution to a similar problem, please check out this post.

Note that there are a few classes and interfaces are referencing internal function/class such as PressGestureScopeImpl which requires you to make your own copy.

Yao
  • 709
  • 2
  • 11
  • 22