Can someone suggest any good references for converting composable to android views, official documentation is pretty basic. I want to explore the best approaches to do the same .
Copy code
@Composable
fun CustomTextViewCompose(
customText: String
) {
Text(text = customText)
}
--------------------------------
class CustomTextView(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : AbstractComposeView(context, attrs, defStyle) {
var textString by mutableStateOf("")
@Composable
override fun Content() {
CustomTextViewCompose(customText = textString)
}
}
This is a very pretty basic sample , when it comes to button and all you may have to update the text and do other things to , how to handle those scenarious?
a
Adam Powell
04/01/2022, 2:30 PM
You've got the idea. 🙂 Snapshot state backed view properties for anything you would pass as a parameter to the composable
w
wintersoldier
04/01/2022, 3:15 PM
But is there a way to make these state backed properties as mandatory .
For ex
binding.tvCustom.apply{
//here how can I make this property as mandatory //,if I didn’t pass textString how
}.
wintersoldier
04/01/2022, 5:47 PM
@ildar.i [Android], Sorry to tag you , but would like to know if you will be able to help here.
🤷♂️ 1
m
myanmarking
04/01/2022, 6:39 PM
I dont understand the question. Can you reformulate?
a
Adam Powell
04/01/2022, 8:29 PM
no view properties are mandatory in the way composable function parameters are mandatory. The best you'll be able to do is make your state-backed properties nullable and null-check them during composition. If you wanted you could do something like