Coder Social home page Coder Social logo

Comments (3)

diegoberaldin avatar diegoberaldin commented on September 26, 2024 3

I had a similar problem or, rather, the same exception in a slightly different scenario.

I had a screen showing a detail about an item which could optionally open a screen to show the detail about a "related" item.

These were two different instances of the same Screen subclass. Without transitions everything worked fine, when adding transitions opening the related screen crashed with the transition was used multiple times error.

Solution: overriding the key property and return a custom unique key, in my case concatenating the item ID was enough since in my context the relation is not reflexive so no two instances of the same screen with the same ID can ever be adjacent.

PS: If the navigation is A -> B -> A (the relation is symmetric) no issue and no crash whatsoever.

from voyager.

j-roskopf avatar j-roskopf commented on September 26, 2024 3

For now, I just ended up doing my own debouncing click operator in my compose

private const val DEBOUNCE_TIME_MILLIS = 1000L

internal interface EventProcessor {
    fun processEvent(event: () -> Unit)

    companion object {
        val buttonClickMap = mutableMapOf<String, EventProcessor>()
    }
}

internal fun EventProcessor.Companion.get(id: String): EventProcessor {
    return buttonClickMap.getOrPut(
        id
    ) {
        EventProcessorImpl()
    }
}

private class EventProcessorImpl : EventProcessor {
    private val now: Long
        get() = Clock.System.now().toEpochMilliseconds()

    private var lastEventTimeMs: Long = 0

    override fun processEvent(event: () -> Unit) {
        if (now - lastEventTimeMs >= DEBOUNCE_TIME_MILLIS) {
            event.invoke()
        }
        lastEventTimeMs = now
    }
}

@Composable
fun debouncedClick(
    id: String = randomUUID(),
    onClick: () -> Unit,
): () -> Unit {
    val multipleEventsCutter = remember { EventProcessor.get(id) }
    val newOnClick: () -> Unit = {
        multipleEventsCutter.processEvent { onClick() }
    }
    return newOnClick
}

Usage:

Button(
    onClick = debouncedClick {
        // clicked
    },
) {
    Text("Button")
}

from voyager.

hypergonial avatar hypergonial commented on September 26, 2024

I ran into this while trying to nest a TabNavigator into a Navigator funnily enough.

from voyager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.