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 1329c764..d53b0f67 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 @@ -4,6 +4,7 @@ import android.app.Application import android.content.Context import android.graphics.Typeface import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatEditText import com.joinforage.forage.android.R import com.joinforage.forage.android.core.services.EnvConfig import com.joinforage.forage.android.core.services.ForageConfig @@ -108,6 +109,32 @@ class ForagePINEditText @JvmOverloads constructor( recycle() } } + + // The following pieces of code are to fix height + // differences in the appearance of Rosetta-backed + // vs BT-backed ForagePINEditText in the case where + // no app:inputHeight or app:inputWidth are set. + + // zero out the padding for Basis Theory element + val btFrame = btVaultWrapper.getTextElement() + val btTextElement = btFrame.getChildAt(0) as AppCompatEditText + btTextElement.setPadding(0, 0, 0, 0) + + // ensure Rosetta's textSize is the same as BTs textSize + // There are three cases: + // 1) using XML layouts and somebody passes app:textSize -> + // both RosettaPinElement and BTVaultWrapper read + // that value and independently set the correct textSize + // 2) using XML layouts and app:textSize is not set -> + // This line of code fixes that issue + // 3) create dynamic instance of ForagePINEditText and + // call setTextSize -> + // setTextSize calls vault.setTextSize so the only + // visible text field will have the correct textSize + // 3) create dynamic instance of ForagePINEditText and + // never call setTextSize -> + // This line of code fixes that issue + rosettaPinElement.setTextSize(btTextElement.textSize) } private fun initWithForageConfig(forageConfig: ForageConfig) { @@ -179,25 +206,6 @@ 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/forage/RosettaPinElement.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/forage/RosettaPinElement.kt index 77bd1a20..18d28da8 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 @@ -87,7 +87,7 @@ internal class RosettaPinElement @JvmOverloads constructor( } override fun setTextSize(textSize: Float) { - _editText.textSize = textSize + _editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize) } override fun setHint(hint: String) { diff --git a/sample-app/src/main/java/com/joinforage/android/example/ui/catalog/CatalogFragment.kt b/sample-app/src/main/java/com/joinforage/android/example/ui/catalog/CatalogFragment.kt index e264adc6..778cd6b1 100644 --- a/sample-app/src/main/java/com/joinforage/android/example/ui/catalog/CatalogFragment.kt +++ b/sample-app/src/main/java/com/joinforage/android/example/ui/catalog/CatalogFragment.kt @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import com.joinforage.android.example.databinding.FragmentCatalogBinding import com.joinforage.forage.android.core.services.ForageConfig +import com.joinforage.forage.android.ecom.ui.element.ForagePINEditText class CatalogFragment : Fragment() { @@ -32,25 +33,28 @@ class CatalogFragment : Fragment() { merchantId = "0123456" ) + // ForagePANEditText can be created via XML layouts or + // dynamically. These different modes of creation are + // a natural point of styling differences to emerge. + // We add a ForagePANEditText to the catalog in the + // hopes that we'll spot these discrepancies + // NOTE: this view is currently unstyled compared to + // the other ForagePINEditText in the catalog which was + // created via XML and has some XML styles associated + // with it. + val dynamicPinEditText = ForagePINEditText(requireContext(), null) + binding.root.addView(dynamicPinEditText) + + dynamicPinEditText.setForageConfig(forageConfig) binding.firstForageEditText.setForageConfig(forageConfig) - binding.secondEditText.setForageConfig(forageConfig) - binding.thirdEditText.setForageConfig(forageConfig) - binding.fourthEditText.setForageConfig(forageConfig) binding.foragePinEditText.setForageConfig(forageConfig) - binding.secondForagePINEditText.setForageConfig(forageConfig) - binding.thirdForagePINEditText.setForageConfig(forageConfig) // NOTE: we call setForageConfig a second time here so that // the CI tests always confirm that running setForageConfig // more than once is OK and does not cause a crash. So, // these duplicate calls are intentional here binding.firstForageEditText.setForageConfig(forageConfig) - binding.secondEditText.setForageConfig(forageConfig) - binding.thirdEditText.setForageConfig(forageConfig) - binding.fourthEditText.setForageConfig(forageConfig) binding.foragePinEditText.setForageConfig(forageConfig) - binding.secondForagePINEditText.setForageConfig(forageConfig) - binding.thirdForagePINEditText.setForageConfig(forageConfig) return root } diff --git a/sample-app/src/main/res/layout/fragment_catalog.xml b/sample-app/src/main/res/layout/fragment_catalog.xml index 227f5428..c34034dc 100644 --- a/sample-app/src/main/res/layout/fragment_catalog.xml +++ b/sample-app/src/main/res/layout/fragment_catalog.xml @@ -7,96 +7,27 @@ android:layout_marginBottom="100dp" tools:context=".ui.catalog.CatalogFragment"> - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> - - - - - - - - - + \ No newline at end of file