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

Commit

Permalink
Optimize IvyModal.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 23, 2022
1 parent 79fb5f9 commit 81338f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import com.ivy.wallet.ui.IvyWalletPreview
import com.ivy.wallet.ui.ivyWalletCtx
import com.ivy.wallet.ui.theme.*
import com.ivy.wallet.ui.theme.components.*
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_KEYBOARD
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_ANIM
import com.ivy.wallet.ui.theme.modal.ModalSave
import com.ivy.wallet.ui.theme.modal.ModalSet
import com.ivy.wallet.ui.theme.modal.edit.AmountModal
Expand Down Expand Up @@ -83,13 +83,13 @@ fun BoxWithConstraintsScope.EditBottomSheet(
targetValue = densityScope {
if (keyboardShown) keyboardOnlyWindowInsets().bottom.toDp() else 0.dp
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
animationSpec = tween(DURATION_MODAL_ANIM)
)
val navBarPadding by animateDpAsState(
targetValue = densityScope {
if (keyboardShown) 0.dp else navigationBarInsets().bottom.toDp()
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
animationSpec = tween(DURATION_MODAL_ANIM)
)

var bottomBarHeight by remember { mutableStateOf(0) }
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.ivy.wallet.ui.ivyWalletCtx
import com.ivy.wallet.ui.theme.Gray
import com.ivy.wallet.ui.theme.components.IvyBasicTextField
import com.ivy.wallet.ui.theme.components.IvyIcon
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_KEYBOARD
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_ANIM
import com.ivy.wallet.ui.theme.transaction.transactions
import com.ivy.wallet.utils.*

Expand Down Expand Up @@ -135,7 +135,7 @@ private fun UI(
targetValue = densityScope {
if (keyboardVisible) keyboardOnlyWindowInsets().bottom.toDp() else 0.dp
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
animationSpec = tween(DURATION_MODAL_ANIM)
)

Spacer(Modifier.height(keyboardShownInsetDp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.ivy.wallet.ui.theme.GradientGreen
import com.ivy.wallet.ui.theme.GradientIvy
import com.ivy.wallet.ui.theme.Ivy
import com.ivy.wallet.ui.theme.White
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_KEYBOARD
import com.ivy.wallet.ui.theme.modal.DURATION_MODAL_ANIM
import com.ivy.wallet.utils.*
import java.util.*

Expand Down Expand Up @@ -72,7 +72,7 @@ fun CurrencyPicker(
targetValue = densityScope {
if (keyboardShown) keyboardOnlyWindowInsets().bottom.toDp() else 0.dp
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
animationSpec = tween(DURATION_MODAL_ANIM)
)

Column(
Expand Down
23 changes: 6 additions & 17 deletions app/src/main/java/com/ivy/wallet/ui/theme/modal/IvyModal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.ivy.frp.view.navigation.Navigation
import com.ivy.frp.view.navigation.navigation
import com.ivy.wallet.ui.IvyWalletPreview
import com.ivy.wallet.ui.ivyWalletCtx
import com.ivy.wallet.ui.theme.Black
import com.ivy.wallet.ui.theme.components.ActionsRow
import com.ivy.wallet.ui.theme.components.CloseButton
import com.ivy.wallet.ui.theme.gradientCutBackgroundTop
Expand All @@ -34,8 +33,8 @@ import java.util.*
import kotlin.math.roundToInt


private const val DURATION_BACKGROUND_BLUR = 400
const val DURATION_MODAL_KEYBOARD = 200
private const val DURATION_BACKGROUND_BLUR_ANIM = 400
const val DURATION_MODAL_ANIM = 200

@Composable
fun BoxScope.IvyModal(
Expand All @@ -62,22 +61,16 @@ fun BoxScope.IvyModal(
targetValue = densityScope {
if (keyboardShown) keyboardOnlyWindowInsets().bottom.toDp() else 0.dp
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
)
val navBarPadding by animateDpAsState(
targetValue = densityScope {
if (keyboardShown) 0.dp else navigationBarInsets().bottom.toDp()
},
animationSpec = tween(DURATION_MODAL_KEYBOARD)
animationSpec = tween(DURATION_MODAL_ANIM)
)
val blurAlpha by animateFloatAsState(
targetValue = if (visible) 1f else 0f,
animationSpec = tween(DURATION_BACKGROUND_BLUR),
animationSpec = tween(DURATION_BACKGROUND_BLUR_ANIM),
visibilityThreshold = 0.01f
)
val modalPercentVisible by animateFloatAsState(
targetValue = if (visible) 1f else 0f,
animationSpec = tween(DURATION_MODAL_KEYBOARD),
animationSpec = tween(DURATION_MODAL_ANIM),
visibilityThreshold = 0.01f
)

Expand Down Expand Up @@ -121,10 +114,6 @@ fun BoxScope.IvyModal(
.fillMaxWidth()
.statusBarsPadding()
.padding(top = 24.dp)
.drawColoredShadow(
color = Black,
alpha = if (UI.colors.isLight) 0.05f else 0.5f,
)
.background(UI.colors.pure, UI.shapes.r2Top)
.consumeClicks()
.thenIf(scrollState != null) {
Expand Down Expand Up @@ -154,7 +143,7 @@ fun BoxScope.IvyModal(
visible = visible,
modalPercentVisible = modalPercentVisible,
keyboardShownInsetDp = keyboardShownInsetDp,
navBarPadding = navBarPadding,
navBarPadding = navigationBarInsets().bottom.toDensityDp(),
onHeightChanged = {
actionsRowHeight = it
},
Expand Down

0 comments on commit 81338f9

Please sign in to comment.