Skip to content

Instantly share code, notes, and snippets.

@tzuxlin
Created May 31, 2022 09:46
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.wear.compose.material.*
@Composable
fun LoginScreenTest() {
val scalingLazyListState = rememberScalingLazyListState()
Scaffold(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
positionIndicator = {
if (scalingLazyListState.isScrollInProgress) {
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
}
) {
ScalingLazyColumn(
modifier = Modifier.fillMaxSize(),
state = scalingLazyListState
) {
item {
PageHeader(
text = "Hello",
painter = painterResource(id = R.drawable.ic_splash_icon_logo)
)
}
item {
TextButton(
text = "Test"
) { }
}
item {
TextButton(
text = "Uh-Oh"
) { }
}
item {
TextButton(
text = "Yo"
) { }
}
}
}
}
@Composable
fun PageHeader(text: String, painter: Painter) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Image(
modifier = Modifier
.size(32.dp)
.padding(end = 8.dp),
painter = painter,
contentDescription = ""
)
Text(
text = text,
textAlign = TextAlign.Center,
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
@Composable
fun TextButton(modifier: Modifier = Modifier, text: String, onClick: () -> Unit) {
Button(
modifier = modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
onClick = onClick
) {
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = text,
fontSize = 16.sp,
textAlign = TextAlign.Center
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment