Slide 60
Slide 60 text
@Composable
fun ExampleButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
contentPadding: PaddingValues = ExampleButtonDefaults.ContentPadding,
textStyle: TextStyle = ExampleButtonDefaults.defaultTextStyle,
colors: ExampleButtonColors = ExampleButtonDefaults.filledButtonColors(),
) {
Button(
onClick = onClick,
colors = ButtonDefaults.buttonColors(
containerColor = colors.containerColor().value,
contentColor = colors.contentColor().value,
),
modifier = modifier
.defaultMinSize(minHeight = ExampleButtonDefaults.MinHeight)
) {
Text(
text = text,
style = textStyle,
color = colors.contentColor().value,
modifier = Modifier
.padding(contentPadding)
)
}
}
Defaults 정의 값을
초기화
코틀린의 함수에는 Defaults 정의가 가능한데, 컴포즈에서도 동일하게 사용합니다.
여기서 Defaults를 나눌 때는 크게 2가지가 있는데 누가 보아도 이해할 수 있는 true/false와 같은 기본값, 그리고 Defaults를 통해 명확한 이름을 제공하는 형태가 있습니다.