Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Composable
- fun ContentList(modifier: Modifier) {
- //List of Users
- val list = listOf(
- ProfileData("Person", "", null, null, null, null),
- ProfileData("Person 2", "", null, null, null, null),
- ProfileData("Person 3", "", null, null, null, null),
- ProfileData("Person 4", "", null, null, null, null),
- ProfileData("Person 5", "", null, null, null, null),
- )
- //current user
- var current by remember {
- mutableIntStateOf(0)
- }
- //animate state
- var animState by remember { mutableStateOf(ProfileAnim.Enter) }
- //animate
- val transition = updateTransition(animState, label = "offset")
- val offset by transition.animateIntOffset(transitionSpec = {
- when {
- ProfileAnim.Down isTransitioningTo ProfileAnim.Default ->
- tween(durationMillis = 200)
- ProfileAnim.Up isTransitioningTo ProfileAnim.Default ->
- tween(durationMillis = 200)
- else ->
- tween(durationMillis = 500)
- }
- }, label = "offset") { state ->
- when (state) {
- ProfileAnim.Default -> IntOffset(-1500, 0)
- ProfileAnim.Enter -> IntOffset(0, 0)
- ProfileAnim.Down -> IntOffset(0, 2000)
- ProfileAnim.Up -> IntOffset(0, -2000)
- }
- }
- //is animation running
- val isAnimationEnded = transition.isRunning
- Log.d("LOGG", animState.name)
- LaunchedEffect(isAnimationEnded) {
- if ((animState == ProfileAnim.Up || animState == ProfileAnim.Down ) && !isAnimationEnded) {
- animState = ProfileAnim.Default
- }
- if(animState == ProfileAnim.Default && !isAnimationEnded){
- current++
- animState = ProfileAnim.Enter
- }
- }
- //checking direction of gesture
- var dragDirection by remember { mutableFloatStateOf(0f) }
- Box(modifier = modifier
- .background(color = Color.Gray)
- .pointerInput(Unit) {
- detectVerticalDragGestures(onVerticalDrag = { _, dragAmount ->
- dragDirection = dragAmount
- }, onDragEnd = {
- if (dragDirection < 0) {
- animState = ProfileAnim.Up
- } else if (dragDirection > 0) {
- animState = ProfileAnim.Down
- }
- })
- }
- .background(Color.Blue)
- ) {
- Box(modifier = Modifier
- .fillMaxSize()
- .offset {
- offset
- }, contentAlignment = Alignment.Center) {
- UserProfile(profileData = list[current])
- }
- }
- }
- enum class ProfileAnim {
- Default,
- Enter,
- Up,
- Down
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement