Skip to content

Instantly share code, notes, and snippets.

@syntialai
Last active Jan 10, 2023
Embed
What would you like to do?
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
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.syntia.instagramcompose.domain.model.Post
import com.syntia.instagramcompose.domain.model.Story
import com.syntia.instagramcompose.domain.model.StoryType
import com.syntia.instagramcompose.ui.component.layout.ChildLayout
import com.syntia.instagramcompose.ui.component.layout.VerticalScrollLayout
import com.syntia.instagramcompose.ui.navigation.navigateToSingleProfile
import com.syntia.instagramcompose.ui.theme.InstagramComposeTheme
import com.syntia.instagramcompose.ui.view.component.post.card.PostCard
import com.syntia.instagramcompose.ui.view.component.post.card.listener.PostCardListener
import com.syntia.instagramcompose.ui.view.component.story.StoriesSection
import com.syntia.instagramcompose.util.LoadItemAfterSafeCast
/**
* Usages
*/
@Composable
fun HomeScreen(
modifier: Modifier = Modifier
) {
val context = LocalContext.current
Surface(modifier = modifier.fillMaxWidth()) {
VerticalScrollLayout(
modifier = Modifier,
ChildLayout(
contentType = HomeScreenContents.STORIES_SECTION,
content = {
StoriesSection(
stories = getStories(),
modifier = Modifier.padding(
start = 16.dp,
top = 16.dp,
bottom = 16.dp,
end = 0.dp
)
)
}
),
ChildLayout(
contentType = HomeScreenContents.DIVIDER,
content = {
Divider(
color = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
thickness = 1.dp)
}
),
ChildLayout(
contentType = HomeScreenContents.POST_CARDS,
items = getPosts(),
content = { item ->
LoadItemAfterSafeCast<Post>(item) { safePost ->
PostCard(
post = safePost,
postCardListener = getPostCardListener(context, navController),
modifier = Modifier.padding(vertical = 8.dp))
}
}
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment