Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Fix PR #64 by making more open only on swipe down after certain thres…
Browse files Browse the repository at this point in the history
…hold
  • Loading branch information
Iliyan Germanov committed Nov 8, 2021
1 parent 90800bb commit 0f4de73
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package com.ivy.wallet.ui.home

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectVerticalDragGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.insets.navigationBarsPadding
Expand All @@ -34,7 +31,8 @@ import com.ivy.wallet.ui.theme.Theme
import com.ivy.wallet.ui.theme.modal.*
import com.ivy.wallet.ui.theme.transaction.TransactionsDividerLine
import com.ivy.wallet.ui.theme.transaction.transactions
import kotlin.math.roundToInt

private const val SWIPE_DOWN_THRESHOLD_OPEN_MORE_MENU = 200

@ExperimentalAnimationApi
@ExperimentalFoundationApi
Expand Down Expand Up @@ -166,25 +164,26 @@ private fun BoxWithConstraintsScope.UI(
mutableStateOf(null)
}
var expanded by remember { mutableStateOf(false) }
val offset by remember { mutableStateOf(Offset.Zero) }

var headerSwipeOffset by remember { mutableStateOf(0f) }

Column(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding()
.offset {
IntOffset(offset.x.roundToInt(), offset.y.roundToInt())
}
.navigationBarsPadding()
.pointerInput(Unit) {
detectDragGestures(
onDragStart = { },
detectVerticalDragGestures(
onDragEnd = {
expanded = true
headerSwipeOffset = 0f
},
onDragCancel = { },
onDrag = { _: PointerInputChange, _: Offset ->
onVerticalDrag = { _, dragAmount ->
//dragAmount: positive when scrolling down; negative when scrolling up
headerSwipeOffset += dragAmount

if (headerSwipeOffset > SWIPE_DOWN_THRESHOLD_OPEN_MORE_MENU) {
expanded = true
}
}
)
}
Expand Down

0 comments on commit 0f4de73

Please sign in to comment.