Skip to content

Commit

Permalink
PWN-9012 - disable bottom margin for toasts when using them in topup …
Browse files Browse the repository at this point in the history
…wallet bottomsheet
  • Loading branch information
eduardmaximovich committed Jun 21, 2023
1 parent 1710190 commit dc9e4c2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.p2p.wallet.striga.ui
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.google.android.material.snackbar.Snackbar
import org.koin.android.ext.android.inject
import org.p2p.core.common.DrawableContainer
import org.p2p.core.common.TextContainer
Expand All @@ -11,6 +12,7 @@ import org.p2p.uikit.components.finance_block.MainCellModel
import org.p2p.uikit.components.icon_wrapper.IconWrapperCellModel
import org.p2p.uikit.components.left_side.LeftSideCellModel
import org.p2p.uikit.components.right_side.RightSideCellModel
import org.p2p.uikit.natives.showSnackbarShort
import org.p2p.uikit.utils.drawable.DrawableCellModel
import org.p2p.uikit.utils.drawable.shape.shapeCircle
import org.p2p.uikit.utils.drawable.shape.shapeRounded16dp
Expand Down Expand Up @@ -107,6 +109,34 @@ class TopUpWalletBottomSheet :
}
}

override fun showUiKitSnackBar(
message: String?,
messageResId: Int?,
onDismissed: () -> Unit,
actionButtonResId: Int?,
actionBlock: ((Snackbar) -> Unit)?
) {
require(message != null || messageResId != null) {
"Snackbar text must be set from `message` or `messageResId` params"
}
val snackbarText: String = message ?: messageResId?.let(::getString)!!
val root = requireView().rootView
if (actionButtonResId != null && actionBlock != null) {
root.showSnackbarShort(
snackbarText = snackbarText,
actionButtonText = getString(actionButtonResId),
actionButtonListener = actionBlock,
enableBottomNavOffset = false
)
} else {
root.showSnackbarShort(
snackbarText = snackbarText,
onDismissed = onDismissed,
enableBottomNavOffset = false
)
}
}

private fun getFinanceBlock(
titleResId: Int,
subtitleRes: Int,
Expand Down
19 changes: 14 additions & 5 deletions ui-kit/src/main/kotlin/org/p2p/uikit/natives/UiKitSnackbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ fun interface SnackbarActionButtonClickListener {
fun View.showSnackbarShort(
snackbarText: CharSequence,
onDismissed: () -> Unit = {},
style: UiKitSnackbarStyle = UiKitSnackbarStyle.BLACK
style: UiKitSnackbarStyle = UiKitSnackbarStyle.BLACK,
enableBottomNavOffset: Boolean = true
) {
internalMakeSnackbar(
this,
text = snackbarText,
buttonText = null,
buttonAction = null,
duration = Snackbar.LENGTH_SHORT,
style = style
style = style,
enableBottomNavOffset = enableBottomNavOffset
)
.addOnDismissedCallback(onDismissed)
.show()
Expand All @@ -31,6 +33,7 @@ fun View.showSnackbarShort(
snackbarText: CharSequence,
actionButtonText: CharSequence,
actionButtonListener: SnackbarActionButtonClickListener,
enableBottomNavOffset: Boolean = true,
onDismissed: () -> Unit = {},
style: UiKitSnackbarStyle = UiKitSnackbarStyle.BLACK
) {
Expand All @@ -40,7 +43,8 @@ fun View.showSnackbarShort(
buttonText = actionButtonText,
buttonAction = actionButtonListener,
duration = Snackbar.LENGTH_SHORT,
style = style
style = style,
enableBottomNavOffset = enableBottomNavOffset
)
.addOnDismissedCallback(onDismissed)
.show()
Expand Down Expand Up @@ -94,14 +98,19 @@ private fun internalMakeSnackbar(
buttonText: CharSequence?,
buttonAction: SnackbarActionButtonClickListener?,
duration: Int,
style: UiKitSnackbarStyle = UiKitSnackbarStyle.BLACK
style: UiKitSnackbarStyle = UiKitSnackbarStyle.BLACK,
enableBottomNavOffset: Boolean = true
): Snackbar {
return Snackbar.make(view, text, duration).apply {
if (buttonText != null && buttonAction != null) {
setAction(buttonText) { buttonAction.onActionButtonClicked(this) }
}

val bottomMargin = context.resources.getDimension(R.dimen.bottom_navigation_height).toInt()
val bottomMargin = if(enableBottomNavOffset) {
context.resources.getDimension(R.dimen.bottom_navigation_height).toInt()
} else {
0
}
val horizontalMargin = context.resources.getDimension(R.dimen.ui_kit_average_horizontal_margin).toInt()
val parentParams = this.view.layoutParams as MarginLayoutParams
parentParams.setMargins(horizontalMargin, 0, horizontalMargin, bottomMargin)
Expand Down

0 comments on commit dc9e4c2

Please sign in to comment.