Skip to content

Instantly share code, notes, and snippets.

@sonique6784
Created June 15, 2021 13:13
Show Gist options
  • Save sonique6784/8aa7098074bee3a46294fb6656df1927 to your computer and use it in GitHub Desktop.
Save sonique6784/8aa7098074bee3a46294fb6656df1927 to your computer and use it in GitHub Desktop.
Jetpack Compose: Custom View
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
data class DataCustomView(
val title: String,
val description: String
)
interface MyInterface {
fun onButtonAClicked()
fun onButtonBClicked()
fun onUserSwipe(coordinate: List<Double>)
}
@Composable
fun MyCustomView(
myData: DataCustomView,
myInterface: MyInterface,
modifier: Modifier = Modifier
) {
Column(modifier = modifier) { // <-- provide modifier
Text(myData.title) // <-- use the data class to populate
Text(myData.description)
Button({ myInterface.onButtonAClicked() }) { // <- interface callback/listener
Text("ButtonA")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment