更新 UI
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
|
||||
@Composable
|
||||
fun BottomNavigationPlaceholder() {
|
||||
fun BottomNavigationPlaceholder(
|
||||
color: Color? = null
|
||||
) {
|
||||
val navigationBarHeight = with(LocalDensity.current) {
|
||||
WindowInsets.navigationBars.getBottom(this).toDp()
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier.height(navigationBarHeight)
|
||||
modifier = Modifier.height(navigationBarHeight).fillMaxWidth().background(color ?: Color.Transparent)
|
||||
)
|
||||
}
|
||||
@@ -6,20 +6,29 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.ime
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -31,9 +40,15 @@ import androidx.compose.ui.unit.sp
|
||||
@Preview
|
||||
@Composable
|
||||
fun CommentModalContent() {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
val insets = WindowInsets
|
||||
val imePadding = insets.ime.getBottom(density = LocalDensity.current)
|
||||
var bottomPadding by remember { mutableStateOf(0.dp) }
|
||||
LaunchedEffect(imePadding) {
|
||||
bottomPadding = imePadding.dp
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.height(500.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@@ -58,7 +73,7 @@ fun CommentModalContent() {
|
||||
.padding(horizontal = 16.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
CommentsSection()
|
||||
CommentsSection{}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
|
||||
@@ -125,11 +125,9 @@ fun NavigationController(navController: NavHostController) {
|
||||
OfficialPhotographer()
|
||||
}
|
||||
composable(route = "Post") {
|
||||
Box(
|
||||
modifier = Modifier.padding(bottom = navigationBarHeight)
|
||||
) {
|
||||
|
||||
PostPage()
|
||||
}
|
||||
|
||||
}
|
||||
composable(route = "ModificationList") {
|
||||
ModificationListScreen()
|
||||
|
||||
@@ -29,6 +29,7 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -279,7 +280,10 @@ fun MomentBottomOperateRowGroup(modifier: Modifier) {
|
||||
if (showCommentModal) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = { showCommentModal = false },
|
||||
containerColor = Color.White
|
||||
containerColor = Color.White,
|
||||
sheetState = rememberModalBottomSheetState(
|
||||
skipPartiallyExpanded = true
|
||||
)
|
||||
) {
|
||||
CommentModalContent()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
@@ -18,7 +20,9 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -34,6 +38,14 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -45,6 +57,7 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
fun makeMockImages(): List<PostImage> {
|
||||
return listOf(
|
||||
@@ -53,40 +66,49 @@ fun makeMockImages(): List<PostImage> {
|
||||
PostImage(R.drawable.rider_pro_moment_demo_1, "Image 3")
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PostPage() {
|
||||
var showCollapseContent by remember { mutableStateOf(true) }
|
||||
val scrollState = rememberLazyListState()
|
||||
|
||||
StatusBarMaskLayout {
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
bottomBar = {
|
||||
BottomNavigationBar()
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
bottomBar = { BottomNavigationBar() }
|
||||
) {
|
||||
it
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
Header()
|
||||
Column(modifier = Modifier.animateContentSize()) {
|
||||
AnimatedVisibility(visible = showCollapseContent) {
|
||||
// collapse content
|
||||
Column {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f)
|
||||
|
||||
) {
|
||||
PostImageView(makeMockImages())
|
||||
}
|
||||
|
||||
PostDetails()
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
|
||||
) {
|
||||
CommentsSection()
|
||||
|
||||
}
|
||||
|
||||
CommentsSection(scrollState) {
|
||||
showCollapseContent = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -114,19 +136,33 @@ fun Header() {
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(text = "Diego Morata", fontWeight = FontWeight.Bold)
|
||||
Box(modifier = Modifier
|
||||
.height(20.dp).wrapContentWidth()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(20.dp)
|
||||
.wrapContentWidth()
|
||||
.padding(start = 6.dp),
|
||||
contentAlignment = Alignment.Center){
|
||||
Image(modifier = Modifier.height(18.dp),painter = painterResource(id = R.drawable.follow_bg), contentDescription = "")
|
||||
Text(text = "FOLLOW", fontSize = 12.sp, color = Color.White, style = TextStyle(fontWeight = FontWeight.Bold))
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
modifier = Modifier.height(18.dp),
|
||||
painter = painterResource(id = R.drawable.follow_bg),
|
||||
contentDescription = ""
|
||||
)
|
||||
Text(
|
||||
text = "FOLLOW",
|
||||
fontSize = 12.sp,
|
||||
color = Color.White,
|
||||
style = TextStyle(fontWeight = FontWeight.Bold)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class PostImage(
|
||||
val imgRes: Int,
|
||||
val description: String
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun PostImageView(images: List<PostImage>) {
|
||||
@@ -134,7 +170,9 @@ fun PostImageView(images: List<PostImage>) {
|
||||
Column {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.weight(1f).fillMaxWidth()
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
) { page ->
|
||||
Image(
|
||||
painter = painterResource(id = images[page].imgRes),
|
||||
@@ -147,7 +185,8 @@ fun PostImageView(images: List<PostImage>) {
|
||||
// Indicator container
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(8.dp).fillMaxWidth(),
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
images.forEachIndexed { index, _ ->
|
||||
@@ -156,7 +195,11 @@ fun PostImageView(images: List<PostImage>) {
|
||||
.size(8.dp)
|
||||
.clip(CircleShape)
|
||||
|
||||
.background(if (pagerState.currentPage == index) Color.Red else Color.Gray.copy(alpha = 0.5f))
|
||||
.background(
|
||||
if (pagerState.currentPage == index) Color.Red else Color.Gray.copy(
|
||||
alpha = 0.5f
|
||||
)
|
||||
)
|
||||
.padding(4.dp)
|
||||
|
||||
|
||||
@@ -176,6 +219,7 @@ fun PostDetails() {
|
||||
Text(text = "共231条评论")
|
||||
}
|
||||
}
|
||||
|
||||
fun MakeMockComments(): List<Comment> {
|
||||
return listOf(
|
||||
Comment(
|
||||
@@ -207,6 +251,118 @@ fun MakeMockComments(): List<Comment> {
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
date = "3 days ago",
|
||||
likes = 200,
|
||||
replies = emptyList()
|
||||
),
|
||||
Comment(
|
||||
name = "Diego Morata",
|
||||
comment = "这里太适合骑行了",
|
||||
@@ -218,16 +374,30 @@ fun MakeMockComments(): List<Comment> {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CommentsSection() {
|
||||
fun CommentsSection(scrollState: LazyListState = rememberLazyListState(), onWillCollapse: (Boolean) -> Unit) {
|
||||
val items = MakeMockComments()
|
||||
LazyColumn (modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxHeight()) {
|
||||
LazyColumn(
|
||||
state = scrollState, modifier = Modifier
|
||||
.padding(start = 16.dp, end = 16.dp)
|
||||
.fillMaxHeight()
|
||||
) {
|
||||
items(items) { comment ->
|
||||
CommentItem(comment)
|
||||
}
|
||||
}
|
||||
|
||||
// Detect scroll direction and update showCollapseContent
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
LaunchedEffect(scrollState) {
|
||||
coroutineScope.launch {
|
||||
snapshotFlow { scrollState.firstVisibleItemScrollOffset }
|
||||
.collect { offset ->
|
||||
onWillCollapse(offset == 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Comment(
|
||||
val name: String,
|
||||
val comment: String,
|
||||
@@ -276,10 +446,14 @@ fun CommentItem(comment: Comment) {
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BottomNavigationBar() {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.background(Color.White)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp).background(Color.White)
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.background(Color.White)
|
||||
) {
|
||||
// grey round box
|
||||
Box(
|
||||
@@ -317,4 +491,9 @@ fun BottomNavigationBar() {
|
||||
Text(text = "2077")
|
||||
|
||||
}
|
||||
BottomNavigationPlaceholder(
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user