Can I wrap Jetpack Compose inside an Android Custo...
# compose
e
Can I wrap Jetpack Compose inside an Android Custom View like below?
Copy code
class CustomView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0)
    : View(context, attrs, defStyleAttr) {

    // Some Jetpack Compose drawn item

}
I have also check in https://stackoverflow.com/q/69987040/3286489
d
You have to inherit from
AbstractComposeView
and override
Content
function
e
@Chris Fillmore, thanks. The link only mentioned putting the Compose in Activity/Fragment/ViewHolder…. but not in a View. Maybe I miss something?
d
Copy code
class CustomView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0)
    : AbstractComposeView(context, attrs, defStyleAttr) {

    @Composable
    override fun Content {
    //compose code here
    }

}
🤩 1
☝️ 1
e
That looks promising… @Dmitrii Smirnov. Let me check that out 🙌 … Thank you so much!! 🙏