Reputation: 1522
We are planning to redesign some layouts in the SDK. Right now we use XML and allow the client's app to override the layouts, by them simply copying our XML files and applying customization, without modifying the IDs of the elements. Now, I am not sure how would it be possible to do something similar with Jetpack compose.
I am looking the following approach from our IOS SDK to be implemented in the Android:
Would it be possible with Jetpack Compose? I would assume you can also expose interfaces and then client apps provide the layout structure. However, we would not like to let the client app to handle the state. We would like for them to use Jetpack compose only for the layout display.
Upvotes: 0
Views: 365
Reputation: 87804
You can mark your view lambda arguments with @Composable
, so those can be used as view builders:
@Composable
fun SdkView(
title: @Composable () -> Unit,
content: @Composable (SomeState) -> Unit,
) {
// here you can use rememberSaveable or view model instead to get more reliable state storage
val state = remember { SomeState() }
Column {
title()
content(state)
}
}
@Composable
fun ClientView(
) {
SdkView(
title = {
Text("Hello")
},
content = { state ->
// build view depending on state
}
)
}
Upvotes: 1