Created
June 15, 2021 13:13
-
-
Save sonique6784/8aa7098074bee3a46294fb6656df1927 to your computer and use it in GitHub Desktop.
Jetpack Compose: Custom View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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