Skip to content

Commit

Permalink
Closes #90; Create transaction with swipe gesture (might need fine-tu…
Browse files Browse the repository at this point in the history
…ning)
  • Loading branch information
Iliyan Germanov committed Nov 27, 2021
1 parent 32ba7a4 commit 79a176b
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion app/src/main/java/com/ivy/wallet/ui/main/MainBottomBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
Expand All @@ -13,7 +14,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -30,6 +33,7 @@ import com.ivy.wallet.ui.theme.components.IvyIcon
import com.ivy.wallet.ui.theme.components.IvyOutlinedButton
import com.ivy.wallet.ui.theme.modal.AddModalBackHandling
import java.util.*
import kotlin.math.abs
import kotlin.math.roundToInt

val FAB_BUTTON_SIZE = 56.dp
Expand Down Expand Up @@ -126,7 +130,7 @@ fun BoxWithConstraintsScope.BottomBar(
// ------------------------------------ BUTTONS--------------------------------------------------
val fabStartX = ivyContext.screenWidth / 2 - FAB_BUTTON_SIZE.toDensityPx() / 2
val fabStartY = ivyContext.screenHeight - navigationBarInset() -
30.dp.toDensityPx() - FAB_BUTTON_SIZE.toDensityPx()
30.dp.toDensityPx() - FAB_BUTTON_SIZE.toDensityPx()

TransactionButtons(
buttonsShownPercent = buttonsShownPercent,
Expand All @@ -140,6 +144,9 @@ fun BoxWithConstraintsScope.BottomBar(
onAddPlannedPayment = onAddPlannedPayment
)

var dragOffset by remember {
mutableStateOf(Offset.Zero)
}
//+ & x button
IvyCircleButton(
modifier = Modifier
Expand All @@ -155,6 +162,37 @@ fun BoxWithConstraintsScope.BottomBar(
.size(FAB_BUTTON_SIZE)
.rotate(fabRotation)
.zIndex(200f)
.thenIf(tab == MainTab.HOME) {
pointerInput(Unit) {
detectDragGestures(
onDragCancel = {
dragOffset = Offset.Zero
},
onDragEnd = {
dragOffset = Offset.Zero
},
onDrag = { _, dragAmount ->
dragOffset += dragAmount

val horizontalThreshold = 40
when {
abs(dragOffset.x) < horizontalThreshold && dragOffset.y < -50 -> {
//swipe up
onAddExpense()
}
dragOffset.x < -horizontalThreshold && dragOffset.y < -40 -> {
//swipe up left
onAddIncome()
}
dragOffset.x > horizontalThreshold && dragOffset.y < -40 -> {
//swipe up right
onAddTransfer()
}
}
}
)
}
}
.testTag("fab_add"),
backgroundPadding = 8.dp,
icon = R.drawable.ic_add,
Expand Down

0 comments on commit 79a176b

Please sign in to comment.