-
Notifications
You must be signed in to change notification settings - Fork 0
Fix PostDetailsPage's Bookmark and WhichPage position #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
caleb-bit
wants to merge
14
commits into
main
Choose a base branch
from
caleb/PostDetailsPageTitle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc0070c
Fix sheetHeightFromBottom calculation
caleb-bit 14cded4
Increase distance from bottom
caleb-bit 00f4c9b
Add `Recent` pagination
thisjustin123 3fb7223
Use filter endpoint instead of local filtering
thisjustin123 555232c
Make recent tab function private
thisjustin123 f40c4f8
Merge branch 'justin/home-pagination' of https://github.com/cuappdev/…
caleb-bit 1adf34f
final fix
caleb-bit e9ad353
Fix height
caleb-bit 00a50e8
merge
caleb-bit b353dc0
Merge branch 'main' of https://github.com/cuappdev/resell-android int…
caleb-bit 90ea826
Manually revert files to main versions
caleb-bit 1954b08
Just add one space to some files
caleb-bit cf9a909
Clean up
caleb-bit 8bd0da4
Disable gestures on the bookmark row
caleb-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,16 +20,13 @@ import androidx.compose.foundation.layout.width | |
| import androidx.compose.foundation.pager.HorizontalPager | ||
| import androidx.compose.foundation.pager.rememberPagerState | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.BottomSheetDefaults | ||
| import androidx.compose.material3.BottomSheetScaffold | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.Icon | ||
| 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.BlurredEdgeTreatment.Companion.Rectangle | ||
|
|
@@ -38,11 +35,11 @@ import androidx.compose.ui.draw.clip | |
| import androidx.compose.ui.graphics.Brush | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.ImageBitmap | ||
| import androidx.compose.ui.input.pointer.PointerEventPass | ||
| import androidx.compose.ui.input.pointer.PointerInputChange | ||
| import androidx.compose.ui.input.pointer.pointerInput | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.layout.onGloballyPositioned | ||
| import androidx.compose.ui.layout.positionInRoot | ||
| import androidx.compose.ui.platform.LocalConfiguration | ||
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
|
|
@@ -64,7 +61,6 @@ import com.cornellappdev.resell.android.util.clickableNoIndication | |
| import com.cornellappdev.resell.android.util.defaultHorizontalPadding | ||
| import com.cornellappdev.resell.android.viewmodel.pdp.PostDetailViewModel | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun PostDetailPage( | ||
| postDetailViewModel: PostDetailViewModel = hiltViewModel(), | ||
|
|
@@ -137,37 +133,67 @@ private fun Content( | |
| onUserClick: () -> Unit = {}, | ||
| showContact: Boolean = false, | ||
| ) { | ||
| var sheetHeightFromBottom by remember { mutableStateOf(0.dp) } | ||
| val pagerState = rememberPagerState(pageCount = { images.size }) | ||
|
|
||
| // Derive peekHeight as screen height minus image height: | ||
| val screenHeight = LocalConfiguration.current.screenHeightDp.dp | ||
|
|
||
| // TODO the plus at the end seems wrong. Test on other devices. | ||
| val peekHeight = screenHeight - imageHeight + 96.dp | ||
| val peekHeight = screenHeight - imageHeight + 180.dp | ||
|
|
||
| Box( | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) { | ||
| BottomSheetScaffold( | ||
| sheetContainerColor = Color.Transparent, | ||
| sheetShadowElevation = 0.dp, | ||
| sheetDragHandle = { | ||
| Column( | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| verticalArrangement = Arrangement.spacedBy(24.dp) | ||
| ) { | ||
| Box( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .gesturesDisabled() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not sure why you're completely disabling gestures here. This seems like it prevents me from bookmarking the item. |
||
| ) { | ||
| WhichPage( | ||
| pagerState = pagerState, | ||
| modifier = Modifier | ||
| .align(Alignment.BottomCenter) | ||
| ) | ||
|
|
||
| BookmarkFAB( | ||
| selected = bookmarked, | ||
| onClick = onBookmarkClick, | ||
| modifier = Modifier | ||
| .align(Alignment.BottomStart) | ||
| ) | ||
| } | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .clip(RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp)) | ||
| .background(color = Color.White), | ||
| horizontalArrangement = Arrangement.Center, | ||
| ) { | ||
| BottomSheetDefaults.DragHandle() | ||
| } | ||
| } | ||
| }, | ||
| sheetContent = { | ||
| BottomSheetContent( | ||
| profilePictureUrl = userPfp, | ||
| username = username, | ||
| title = title, | ||
| price = price, | ||
| description = description, | ||
| onHeightChanged = { | ||
| sheetHeightFromBottom = it | ||
| }, | ||
| onSimilarClick = onSimilarClick, | ||
| profilePictureUrl = userPfp, | ||
| username = username, | ||
| similarImageUrls = similarImageUrls, | ||
| onSimilarClick = onSimilarClick, | ||
| onUserClick = onUserClick | ||
| ) | ||
| }, | ||
| sheetPeekHeight = peekHeight, | ||
| sheetContainerColor = Color.White, | ||
| sheetShadowElevation = 12.dp, | ||
| containerColor = Color.White, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
|
|
@@ -177,7 +203,7 @@ private fun Content( | |
| state = pagerState, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .background(IconInactive), | ||
| .background(IconInactive) | ||
| ) { | ||
| Column(modifier = Modifier.fillMaxHeight()) { | ||
| PdpImageBlurredBackground( | ||
|
|
@@ -213,25 +239,21 @@ private fun Content( | |
| state = contactButtonState | ||
| ) | ||
| } | ||
|
|
||
| WhichPage( | ||
| pagerState = pagerState, | ||
| modifier = Modifier | ||
| .padding(bottom = sheetHeightFromBottom) | ||
| .align(Alignment.BottomCenter) | ||
| ) | ||
|
|
||
| BookmarkFAB( | ||
| selected = bookmarked, | ||
| onClick = onBookmarkClick, | ||
| modifier = Modifier | ||
| .align(Alignment.BottomStart) | ||
| .defaultHorizontalPadding() | ||
| .padding(bottom = sheetHeightFromBottom) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| fun Modifier.gesturesDisabled() = | ||
| pointerInput(Unit) { | ||
| awaitPointerEventScope { | ||
| while (true) { | ||
| awaitPointerEvent(pass = PointerEventPass.Initial) | ||
| .changes | ||
| .forEach(PointerInputChange::consume) | ||
| } | ||
| } | ||
| } | ||
Mihilih marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @Composable | ||
| private fun PdpImageBlurredBackground( | ||
| imageHeight: Dp, | ||
|
|
@@ -303,14 +325,12 @@ private fun BottomSheetContent( | |
| username: String, | ||
| paddingTop: Dp = 116.dp, | ||
| similarImageUrls: ResellApiResponse<List<String>>, | ||
| onHeightChanged: (Dp) -> Unit, | ||
| onSimilarClick: (Int) -> Unit, | ||
| onUserClick: () -> Unit, | ||
| ) { | ||
|
|
||
| // Get screen height | ||
| val screenHeight = LocalConfiguration.current.screenHeightDp.dp | ||
| val density = LocalDensity.current | ||
|
|
||
| // Calculate maximum height for the sheet content based on padding from top | ||
| val maxSheetHeight = screenHeight - paddingTop | ||
|
|
@@ -324,20 +344,7 @@ private fun BottomSheetContent( | |
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .defaultHorizontalPadding() | ||
| .onGloballyPositioned { layoutCoordinates -> | ||
| val textPosition = layoutCoordinates.positionInRoot().y | ||
| val textHeight = layoutCoordinates.size.height | ||
|
|
||
| val screenHeightPx = with(density) { screenHeight.toPx() } | ||
|
|
||
| // Calculate distance from bottom in px and convert to dp | ||
| val distanceFromBottomPx = screenHeightPx - (textPosition + textHeight) | ||
| val textDistanceFromBottom = with(density) { distanceFromBottomPx.toDp() } | ||
|
|
||
| // Tell the parent that the height has changed. | ||
| onHeightChanged(textDistanceFromBottom + 170.dp) | ||
| }, | ||
| .defaultHorizontalPadding(), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.