player-ui / player

https://player-ui.github.io
MIT License
71 stars 46 forks source link

Create Jetpack Compose Reference Assets #90

Open brocollie08 opened 1 year ago

brocollie08 commented 1 year ago

Currently the Android assets only contain traditional Android view based assets. Alongside the Composable player patternization, it would be good to have a ComposeReferenceAssetsPlugin containing the same reference assets but as composables using the following pattern

open class ComposableAsset<Data> constructor(assetContext: AssetContext, serializer: KSerializer<Data>, private val content: @Composable (AssetContext, Data) -> Unit) : DecodableAsset<Data>(assetContext, serializer) {
    override fun initView(): View = ComposeView(requireContext()).apply {
        setContent {
            content(assetContext, data)
        }
    }

    override fun View.hydrate() {
        require(this is ComposeView)

        setContent {
            content(assetContext, data)
        }
    }

    @Composable public fun compose() {
        content(assetContext, data)
    }
}

Assets should be rendered with the following compose function

@Composable
fun RenderableAsset.compose(modifier: Modifier = Modifier) {
    if (this is ComposableAsset<*>) Box(
        modifier,
        propagateMinConstraints = true,
    ) {
        compose()
    } else AndroidView(factory = ::FrameLayout, modifier) {
        assetContext.withContext(it.context).build().run { render() } into it
    }
}
brocollie08 commented 1 year ago

Relevant https://github.com/player-ui/player/issues/89

OleDakotaJoe commented 1 year ago

Can I take on this issue? would love to get involved with this project

chrischan325 commented 11 months ago

Hi! I would like to take this on

brocollie08 commented 11 months ago

@chrischan325 Hey, thanks for your interest in contributing. Do you have enough context to get started?

chrischan325 commented 11 months ago

@brocollie08 I don't think so, first time looking at this project. Any additional context or helpful details would be great!

brocollie08 commented 11 months ago

I'd recommend first looking through this alongside building the android demo app, get a good sense of how Player works as a whole + android specific assets Once you have a good understanding of the moving pieces, then you can work on the JPC asset portion