mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
Remove swipe actions
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
f602fe8d7d
commit
be1921240a
4 changed files with 0 additions and 36 deletions
|
@ -85,14 +85,12 @@ fun LobstersApp() {
|
||||||
HottestPosts(
|
HottestPosts(
|
||||||
posts = hottestPosts,
|
posts = hottestPosts,
|
||||||
listState = hottestPostsListState,
|
listState = hottestPostsListState,
|
||||||
saveAction = viewModel::savePost,
|
|
||||||
overscrollAction = viewModel::getMorePosts,
|
overscrollAction = viewModel::getMorePosts,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(Destination.Saved.route) {
|
composable(Destination.Saved.route) {
|
||||||
SavedPosts(
|
SavedPosts(
|
||||||
posts = savedPosts,
|
posts = savedPosts,
|
||||||
saveAction = viewModel::removeSavedPost,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ fun HottestPosts(
|
||||||
posts: List<LobstersPost>,
|
posts: List<LobstersPost>,
|
||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
saveAction: (LobstersPost) -> Unit,
|
|
||||||
overscrollAction: () -> Unit,
|
overscrollAction: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val urlLauncher = UrlLauncherAmbient.current
|
val urlLauncher = UrlLauncherAmbient.current
|
||||||
|
@ -34,7 +33,6 @@ fun HottestPosts(
|
||||||
post = item,
|
post = item,
|
||||||
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
|
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
|
||||||
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
|
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
|
||||||
saveAction = saveAction,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,23 +6,16 @@ import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.offsetPx
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.foundation.lazy.LazyColumnFor
|
import androidx.compose.foundation.lazy.LazyColumnFor
|
||||||
import androidx.compose.foundation.lazy.LazyItemScope
|
import androidx.compose.foundation.lazy.LazyItemScope
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.FractionalThreshold
|
|
||||||
import androidx.compose.material.rememberSwipeableState
|
|
||||||
import androidx.compose.material.swipeable
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.ConfigurationAmbient
|
|
||||||
import androidx.compose.ui.platform.DensityAmbient
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.ui.tooling.preview.Preview
|
import androidx.ui.tooling.preview.Preview
|
||||||
|
@ -33,39 +26,17 @@ import dev.msfjarvis.lobsters.model.Submitter
|
||||||
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
|
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
|
||||||
import dev.msfjarvis.lobsters.ui.theme.titleColor
|
import dev.msfjarvis.lobsters.ui.theme.titleColor
|
||||||
|
|
||||||
private enum class SwipeState {
|
|
||||||
NotSwiped,
|
|
||||||
FullySwiped,
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LazyItemScope.LobstersItem(
|
fun LazyItemScope.LobstersItem(
|
||||||
post: LobstersPost,
|
post: LobstersPost,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
linkOpenAction: (LobstersPost) -> Unit,
|
linkOpenAction: (LobstersPost) -> Unit,
|
||||||
commentOpenAction: (LobstersPost) -> Unit,
|
commentOpenAction: (LobstersPost) -> Unit,
|
||||||
saveAction: (LobstersPost) -> Unit,
|
|
||||||
) {
|
) {
|
||||||
val width = with(DensityAmbient.current) {
|
|
||||||
ConfigurationAmbient.current.screenWidthDp.toDp().toPx()
|
|
||||||
}
|
|
||||||
val swipeableState = rememberSwipeableState(SwipeState.NotSwiped)
|
|
||||||
val anchors = mapOf(0f to SwipeState.NotSwiped, width to SwipeState.FullySwiped)
|
|
||||||
if (swipeableState.offset.value >= (width / 2)) {
|
|
||||||
saveAction.invoke(post)
|
|
||||||
swipeableState.animateTo(SwipeState.NotSwiped)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillParentMaxWidth()
|
.fillParentMaxWidth()
|
||||||
.swipeable(
|
|
||||||
state = swipeableState,
|
|
||||||
anchors = anchors,
|
|
||||||
thresholds = { _, _ -> FractionalThreshold(0.5f) },
|
|
||||||
orientation = Orientation.Horizontal
|
|
||||||
)
|
|
||||||
.offsetPx(swipeableState.offset)
|
|
||||||
.clickable(
|
.clickable(
|
||||||
onClick = { linkOpenAction.invoke(post) },
|
onClick = { linkOpenAction.invoke(post) },
|
||||||
onLongClick = { commentOpenAction.invoke(post) },
|
onLongClick = { commentOpenAction.invoke(post) },
|
||||||
|
@ -145,7 +116,6 @@ fun PreviewLobstersItem() {
|
||||||
post = item,
|
post = item,
|
||||||
linkOpenAction = {},
|
linkOpenAction = {},
|
||||||
commentOpenAction = {},
|
commentOpenAction = {},
|
||||||
saveAction = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import dev.msfjarvis.lobsters.ui.urllauncher.UrlLauncherAmbient
|
||||||
fun SavedPosts(
|
fun SavedPosts(
|
||||||
posts: List<LobstersPost>,
|
posts: List<LobstersPost>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
saveAction: (LobstersPost) -> Unit
|
|
||||||
) {
|
) {
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val urlLauncher = UrlLauncherAmbient.current
|
val urlLauncher = UrlLauncherAmbient.current
|
||||||
|
@ -30,7 +29,6 @@ fun SavedPosts(
|
||||||
post = item,
|
post = item,
|
||||||
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
|
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
|
||||||
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
|
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
|
||||||
saveAction = saveAction,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue