Skip to content

Commit

Permalink
Zero all padding for BT, VGS, and Rosetta elements
Browse files Browse the repository at this point in the history
Forage needs to transparently route traffic to different vault providers
based on availability. We were facing a problem where swapping out vault
providers was _not_ transparent in the case where `inputHeight` and
`inputWidth` attributes were not supplied to `ForagePINEditText`.

Our investigation made clear that the VGS and BT had different default
paddings. This commit, therefore, zeros out all of the default paddings.
This gives us the desired outcome of routing to different vaults
transparent.

The complexity of this issue came from VGS setting their default
paddings in XML styles and BT setting their default styles at a
relatively late point in their text element's life cycle.

Signed-off-by: Devin Morgan <[email protected]>
  • Loading branch information
devinmorgan committed Jun 18, 2024
1 parent 2f01a4e commit c984bdc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ class ForagePINEditText @JvmOverloads constructor(
logger: Log
): AbstractVaultSubmitter = vault.getVaultSubmitter(envConfig, logger)

override fun onFinishInflate() {
super.onFinishInflate()

// we use post to make sure that this zero-ing out
// happens after all of BT's code executes. We need
// the zero-ing out to "win"
post {
// zero out the padding for Basis Theory element
// we expressly need to wait for after the BT
// Element has inflated before we can do this
// else an exception is thrown.
// also worth noting that the VGS padding is
// zero-d out in the dimens.xml file
val btFrame = btVaultWrapper.getTextElement()
val btTextElement = btFrame.getChildAt(0)
btTextElement.setPadding(0, 0, 0, 0)
}
}

override var typeface: Typeface?
get() = if (vault == btVaultWrapper) btVaultWrapper.typeface else rosettaPinElement.typeface
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ internal class BTVaultWrapper @JvmOverloads constructor(
textSize = getDimension(com.joinforage.forage.android.R.styleable.ForagePINEditText_textSize, -1f)
textColor = getColor(com.joinforage.forage.android.R.styleable.ForagePINEditText_textColor, Color.BLACK)
var customBackground = GradientDrawable().apply {
setPaddingRelative(20, 20, 20, 20)
shape = GradientDrawable.RECTANGLE
cornerRadii = floatArrayOf(boxCornerRadiusTopStart, boxCornerRadiusTopStart, boxCornerRadiusTopEnd, boxCornerRadiusTopEnd, boxCornerRadiusBottomStart, boxCornerRadiusBottomStart, boxCornerRadiusBottomEnd, boxCornerRadiusBottomEnd)
setStroke(5, boxStrokeColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ internal class RosettaPinElement @JvmOverloads constructor(
setHintTextColor(hintTextColor)

val customBackground = GradientDrawable().apply {
setPaddingRelative(20, 20, 20, 20)
shape = GradientDrawable.RECTANGLE
cornerRadii = floatArrayOf(
boxCornerRadiusTopStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ internal class VGSVaultWrapper @JvmOverloads constructor(
}

val customBackground = GradientDrawable().apply {
setPaddingRelative(20, 20, 20, 20)
shape = GradientDrawable.RECTANGLE
cornerRadii = floatArrayOf(boxCornerRadiusTopStart, boxCornerRadiusTopStart, boxCornerRadiusTopEnd, boxCornerRadiusTopEnd, boxCornerRadiusBottomStart, boxCornerRadiusBottomStart, boxCornerRadiusBottomEnd, boxCornerRadiusBottomEnd)
setStroke(5, boxStrokeColor)
Expand All @@ -90,7 +89,6 @@ internal class VGSVaultWrapper @JvmOverloads constructor(
setFieldName(ForageConstants.VGS.PIN_FIELD_NAME)
setMaxLength(4)
setInputType(android.text.InputType.TYPE_CLASS_NUMBER or android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD)
setPadding(20, 20, 20, 20)
}
// enforce that PINs must be 4 digits to be vali
_internalEditText.appendRule(
Expand Down
3 changes: 3 additions & 0 deletions forage-android/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<dimen name="forage_logo_top_margin">0dp</dimen>
<dimen name="forage_logo_right_margin">0dp</dimen>
<dimen name="forage_logo_bottom_margin">0dp</dimen>
<dimen name="half_vgsfield_padding">0dp</dimen>
<dimen name="vgsfield_padding">0dp</dimen>
<dimen name="default_vertical_field">0dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ class RosettaPinElementTests {
}

@Test
fun `has padding of 20 by default`() {
fun `has padding of 0 by default`() {
val editText = rosettaPinElement.getTextElement()
assertEquals(20, editText.paddingLeft)
assertEquals(20, editText.paddingTop)
assertEquals(20, editText.paddingRight)
assertEquals(20, editText.paddingBottom)
assertEquals(0, editText.paddingLeft)
assertEquals(0, editText.paddingTop)
assertEquals(0, editText.paddingRight)
assertEquals(0, editText.paddingBottom)
}

@Test
Expand Down
1 change: 0 additions & 1 deletion sample-app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<dimen name="activity_vertical_margin">16dp</dimen>

<dimen name="pin_field_margin">16dp</dimen>
<dimen name="vgs_field_vertical_padding">2dp</dimen>
<dimen name="pin_text_size">16sp</dimen>
<dimen name="corner_radius">4dp</dimen>
<dimen name="box_corner_radius_top_start">4dp</dimen>
Expand Down

0 comments on commit c984bdc

Please sign in to comment.