Skip to content

1.5.33-beta

Compare
Choose a tag to compare
@raamcosta raamcosta released this 22 Jan 21:24
· 454 commits to main since this release
10a6b5e

- Feature - Destination Wrappers

With this feature, you can set a number of wrapper composables to your screens, extracting common logic or UI you need in multiple screens.
Imagine you have a number of screens that should be behind a PIN. How would you implement that so that you don't repeat yourself and you avoid adding complexity to each of these screens?

Well, after this update you can do this:

@Destination(
    wrappers = [PinEntryWrapper::class] // 👈 
)
@Composable
fun YourScreen() { //...

And define what your wrapper does like:

object PinEntryWrapper : DestinationWrapper {

    @Composable
    override fun <T> DestinationScope<T>.Wrap(
        screenContent: @Composable () -> Unit
    ) {
        val vm = viewModel<PinEntryWrapperViewModel>()
        val correctPinEntered by vm.correctPinEntered.collectAsState()

        if (pinEnteredCorrectly) {
            screenContent()
        } else {
            // SHOW YOUR PIN ENTRY HERE
        }
    }
}

And now you have a reusable piece of logic and UI which can be easily reused in how many screens you need and with very little intrusion to the screen itself! 🙌
The DestinationScope receiver of the Wrap function will give you anything you might need here including the destination
being wrapped at the moment (since you can Wrap multiple ones), its arguments, dependencies (provided via dependencyContainerBuilder etc.

- Fixed #339

Full Changelog: 1.5.32-beta...1.5.33-beta