Remove swipe actions

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-11-08 17:25:10 +05:30
parent f602fe8d7d
commit be1921240a
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 0 additions and 36 deletions

View file

@ -85,14 +85,12 @@ fun LobstersApp() {
HottestPosts(
posts = hottestPosts,
listState = hottestPostsListState,
saveAction = viewModel::savePost,
overscrollAction = viewModel::getMorePosts,
)
}
composable(Destination.Saved.route) {
SavedPosts(
posts = savedPosts,
saveAction = viewModel::removeSavedPost,
)
}
}

View file

@ -14,7 +14,6 @@ fun HottestPosts(
posts: List<LobstersPost>,
listState: LazyListState,
modifier: Modifier = Modifier,
saveAction: (LobstersPost) -> Unit,
overscrollAction: () -> Unit,
) {
val urlLauncher = UrlLauncherAmbient.current
@ -34,7 +33,6 @@ fun HottestPosts(
post = item,
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
saveAction = saveAction,
)
}
}

View file

@ -6,23 +6,16 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.offsetPx
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyItemScope
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
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.unit.dp
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.titleColor
private enum class SwipeState {
NotSwiped,
FullySwiped,
}
@Composable
fun LazyItemScope.LobstersItem(
post: LobstersPost,
modifier: Modifier = Modifier,
linkOpenAction: (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(
modifier = modifier
.fillParentMaxWidth()
.swipeable(
state = swipeableState,
anchors = anchors,
thresholds = { _, _ -> FractionalThreshold(0.5f) },
orientation = Orientation.Horizontal
)
.offsetPx(swipeableState.offset)
.clickable(
onClick = { linkOpenAction.invoke(post) },
onLongClick = { commentOpenAction.invoke(post) },
@ -145,7 +116,6 @@ fun PreviewLobstersItem() {
post = item,
linkOpenAction = {},
commentOpenAction = {},
saveAction = {},
)
}
}

View file

@ -13,7 +13,6 @@ import dev.msfjarvis.lobsters.ui.urllauncher.UrlLauncherAmbient
fun SavedPosts(
posts: List<LobstersPost>,
modifier: Modifier = Modifier,
saveAction: (LobstersPost) -> Unit
) {
val listState = rememberLazyListState()
val urlLauncher = UrlLauncherAmbient.current
@ -30,7 +29,6 @@ fun SavedPosts(
post = item,
linkOpenAction = { post -> urlLauncher.launch(post.url.ifEmpty { post.commentsUrl }) },
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
saveAction = saveAction,
)
}
}