From c984bdcd184b0a413e39f7136657cfef24cfe9b4 Mon Sep 17 00:00:00 2001 From: Devin Morgan Date: Tue, 18 Jun 2024 09:01:56 -0400 Subject: [PATCH] Zero all padding for BT, VGS, and Rosetta elements 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 --- .../ecom/ui/element/ForagePINEditText.kt | 19 +++++++++++++++++++ .../ecom/ui/vault/bt/BTVaultWrapper.kt | 1 - .../ecom/ui/vault/forage/RosettaPinElement.kt | 1 - .../ecom/ui/vault/vgs/VGSVaultWrapper.kt | 2 -- forage-android/src/main/res/values/dimens.xml | 3 +++ .../android/ui/RosettaPinElementTests.kt | 10 +++++----- sample-app/src/main/res/values/dimens.xml | 1 - 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/element/ForagePINEditText.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/element/ForagePINEditText.kt index 8e44f627..6d9a6d1f 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/element/ForagePINEditText.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/element/ForagePINEditText.kt @@ -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) { diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/bt/BTVaultWrapper.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/bt/BTVaultWrapper.kt index 31e5613d..21e22c5e 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/bt/BTVaultWrapper.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/bt/BTVaultWrapper.kt @@ -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) diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/forage/RosettaPinElement.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/forage/RosettaPinElement.kt index 90c98de2..77bd1a20 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/forage/RosettaPinElement.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/forage/RosettaPinElement.kt @@ -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, diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/vgs/VGSVaultWrapper.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/vgs/VGSVaultWrapper.kt index dbc42503..135022d5 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/vgs/VGSVaultWrapper.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/vgs/VGSVaultWrapper.kt @@ -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) @@ -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( diff --git a/forage-android/src/main/res/values/dimens.xml b/forage-android/src/main/res/values/dimens.xml index 3dc298e3..4df4c258 100644 --- a/forage-android/src/main/res/values/dimens.xml +++ b/forage-android/src/main/res/values/dimens.xml @@ -6,4 +6,7 @@ 0dp 0dp 0dp + 0dp + 0dp + 0dp \ No newline at end of file diff --git a/forage-android/src/test/java/com/joinforage/forage/android/ui/RosettaPinElementTests.kt b/forage-android/src/test/java/com/joinforage/forage/android/ui/RosettaPinElementTests.kt index 9c9e7767..7852a284 100644 --- a/forage-android/src/test/java/com/joinforage/forage/android/ui/RosettaPinElementTests.kt +++ b/forage-android/src/test/java/com/joinforage/forage/android/ui/RosettaPinElementTests.kt @@ -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 diff --git a/sample-app/src/main/res/values/dimens.xml b/sample-app/src/main/res/values/dimens.xml index 6a854f82..57d9539a 100644 --- a/sample-app/src/main/res/values/dimens.xml +++ b/sample-app/src/main/res/values/dimens.xml @@ -4,7 +4,6 @@ 16dp 16dp - 2dp 16sp 4dp 4dp