https://kotlinlang.org logo
Title
d

dan.the.man

08/20/2022, 9:19 PM
If I have something like
@Composable
fun showList(actions:MutableSharedFlow<Action>){
    val scope = rememberCoroutineScope()
            Box(contentAlignment = Alignment.Center) {
                Column(Modifier.clickable {
                    scope.launch { actions.emit(NewEvent())}
This works, but if I navigate back to the page, and repeat the action, the event fires 2x, and then 3x if I navigate back etc. What am I missing here? Changing it to a method that's passed in instead of creating a lambda results in what I'd expect
@Composable
fun showList(actions:(Action) -> Unit){
    val scope = rememberCoroutineScope()
            Box(contentAlignment = Alignment.Center) {
                Column(Modifier.clickable {
                   actions(NewEvent())
^ that works, I guess it has to do with stable?
z

Zach Klippenstein (he/him) [MOD]

08/21/2022, 7:01 PM
Which version of compose, and how are you implementing navigation?
d

dan.the.man

08/21/2022, 7:02 PM
should be the latest, 1.2.1
z

Zach Klippenstein (he/him) [MOD]

08/21/2022, 7:04 PM
How are you doing nav?
d

dan.the.man

08/21/2022, 7:05 PM
Fragments that hold compose,
fun showFragment(fragment: Fragment){
        supportFragmentManager.beginTransaction().replace(R.id.content, fragment, null).addToBackStack(null)).commit()
    }
With one activity
override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireContext()).apply {
            setContent {
                MyScreen(viewModel){
                    sendAction(it)
                }
            }
        }
Is the current iteration, before I was passing the SharedFlow in here
z

Zach Klippenstein (he/him) [MOD]

08/21/2022, 7:07 PM
I have no idea off the top of my head, but @Leland Richardson [G] just rewrote all the underlying infra that modifiers rely on so I would test this on the next release and see if you can still repro (should be 1.3 beta 1 I think)
d

dan.the.man

08/21/2022, 7:07 PM
interesting I'll give that a try in a bit ty
l

Leland Richardson [G]

08/21/2022, 9:04 PM
I dont think my changes will have any effect
I would file a bug
i think it is relayed to the lambda getting memoized in one case and not the other but it shouldn't effect behavior like that