Skip to content

Instantly share code, notes, and snippets.

@alexstyl
Last active April 3, 2022 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexstyl/3b0780a927938b8079595a2983abb848 to your computer and use it in GitHub Desktop.
Save alexstyl/3b0780a927938b8079595a2983abb848 to your computer and use it in GitHub Desktop.
// instead of a LinearLayout (horizontal) use:
Row {
Text("Main Header")
Spacer(Modifier.weight(1f))
Text("23 mins ago")
}
// instead of FrameLayout use:
Box {
Image(
painter = painterResource(R.drawable.landscape_horizontal),
contentDescription = null
)
Text(
"Preview",
modifier = Modifier
.padding(4.dp)
.clip(RoundedCornerShape(14.dp))
.background(Color.DarkGray)
.padding(
horizontal = 8.dp,
vertical = 4.dp
)
.align(Alignment.BottomEnd),
color = Color.White
)
}
// instead of RecyclerView (vertical) use:
Box {
val desertNames = listOf("...")
LazyColumn(Modifier.fillMaxSize()) {
stickyHeader {
Text(
"Desert names",
modifier = Modifier
.fillMaxWidth()
.shadow(4.dp)
.background(Color.White)
.padding(
vertical = 20.dp,
horizontal = 16.dp
)
)
}
desertNames.forEach { item ->
item {
Text(
item,
modifier = Modifier.padding(
vertical = 20.dp,
horizontal = 16.dp
)
)
}
}
}
// suggested parameter ordering
@Composable
fun MyComposable(
requiredValue: String,
modifier: Modifier = Modifier,
onClick: () -> Unit,
optionalValue: String = "",
content: @Composable () -> Unit
) {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment