Skip to content

Instantly share code, notes, and snippets.

@omarmiatello
Last active January 25, 2022 18:11
Show Gist options
  • Save omarmiatello/e6800927c7a8e59bb753559355836d80 to your computer and use it in GitHub Desktop.
Save omarmiatello/e6800927c7a8e59bb753559355836d80 to your computer and use it in GitHub Desktop.
package com.github.omarmiatello.composeclub
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Phone
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.github.omarmiatello.composeclub.ui.theme.ComposeClubTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeClubTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
MyComposableScreen()
}
}
}
}
}
object MyWorld {
val items = listOf("A", "B", "C")
}
@Preview
@Composable
fun MyComposableScreen() {
Column {
// Search layout
Row(
verticalAlignment = Alignment.CenterVertically,
) {
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.weight(1f)
)
Button(
onClick = { /* query(text) */ },
modifier = Modifier.padding(horizontal = 8.dp)
) {
Text(text = "Search")
}
}
LazyColumn {
items(MyWorld.items) { item ->
Row(
modifier = Modifier
.clickable { /* ... */ }
.padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Column(
modifier = Modifier
.weight(1f),
) {
Text(
text = "Title $item",
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.h3,
)
Text(
text = "Subtitle $item",
style = MaterialTheme.typography.h5,
)
}
Icon(
imageVector = Icons.Default.Phone,
contentDescription = null,
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment