Skip to content

Instantly share code, notes, and snippets.

View syntialai's full-sized avatar
🏠
Working from home

Syntia syntialai

🏠
Working from home
View GitHub Profile
@syntialai
syntialai / VerticalScrollLayout.kt
Last active January 3, 2023 23:07
Vertical scroll layout composable util
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
data class ChildLayout(
val contentType: String = "",
val content: @Composable (item: Any?) -> Unit = {},
LazyColumn {
items(posts) { post ->
PostCard(post)
}
}
@syntialai
syntialai / PreviewScreen.kt
Last active January 10, 2023 02:50
Jetpack Compose Row/Column example
@Composable
fun PreviewScreen(
screenName: String,
modifier: Modifier = Modifier
) {
Surface(modifier = modifier.fillMaxSize()) {
Column(modifier = modifier.verticalScroll()) {
PreviewAnimation()
Text(
@syntialai
syntialai / HomeScreen.kt
Last active January 10, 2023 02:51
Instagram home screen (Wrong example)
@Composable
fun HomeScreenWrong(modifier: Modifier = Modifier) {
val scrollState = rememberScrollState()
val context = LocalContext.current
Surface(modifier = modifier.fillMaxWidth()) {
Column(modifier = Modifier.verticalScroll(scrollState)) {
LazyRow(modifier = modifier.fillMaxWidth()) {
items(stories) { story ->
@syntialai
syntialai / HomeScreen.kt
Last active January 10, 2023 02:53
Instagram home screen with vertical scroll layout
import android.content.Context
import android.widget.Toast
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@syntialai
syntialai / HomeScreen.kt
Last active March 22, 2024 10:56
Instagram home screen example - compose
@Composable
fun HomeScreen(modifier: Modifier = Modifier) {
val scrollState = rememberScrollState()
val context = LocalContext.current
Surface(modifier = modifier.fillMaxWidth()) {
LazyColumn(modifier = Modifier.verticalScroll(scrollState)) {
// LazyRow still able to be use, since it has different orientation with parent LazyColumn
item {