Skip to content

Commit

Permalink
[FX-1254] Expose showKeyboard() method on ForageElements (#243)
Browse files Browse the repository at this point in the history
## What

- Added `showKeyboard` method to `ForageElement` interface
- Implemented `showKeyboard` method in `ForagePANEditText` and `ForagePINEditText`
- Updated `FlowBalanceFragment` and `FlowTokenizeFragment` to use `showKeyboard` method

## Why

- To provide a way to show the soft keyboard when needed explicitly

## Test Plan

- ❌ I've added unit tests for this change.
- ✅ The reviewer should manually test the changes in this PR.

## Demo
[Show Keyboard Demo.webm](https://github.com/teamforage/forage-android-sdk/assets/12377418/65f68891-839c-4e34-86ed-ca98c2aa38f5)

## How
~This PR is blocked until we hear back from BT about how to support the show-keyboard functionality with BT inputs. Otherwise the behavior will differ based on the backing vault.~
This PR can now be readily merged 🥳
  • Loading branch information
devinmorgan authored Apr 26, 2024
1 parent a2d93ca commit 939931a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion forage-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ dependencies {
api 'com.verygoodsecurity:vgscollect:1.7.3'

// Basis Theory SDK
implementation ('com.github.basis-theory:basistheory-android:2.5.0') {
implementation ('com.github.basis-theory:basistheory-android:4.2.0') {
// Unable to build without excluding this dependency
// based on advice from this thread: https://github.com/gradle/gradle/issues/3065#issuecomment-341418873
exclude group: 'javax.ws.rs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ interface ForageElement<T : ElementState> {
*/
fun setPosForageConfig(posForageConfig: PosForageConfig)

/**
* Explicitly request that the current input method's soft
* input be shown to the user, if needed. This only has an
* effect if the ForageElement is focused, which can be
* done using `.requestFocus()`
*/
fun showKeyboard()

/**
* Clears the text input field of the ForageElement.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.text.InputType
import android.text.method.DigitsKeyListener
import android.util.AttributeSet
import android.util.TypedValue
import android.view.inputmethod.InputMethodManager
import androidx.core.content.getSystemService
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.joinforage.forage.android.ForageConfigNotSetException
Expand Down Expand Up @@ -173,6 +175,11 @@ class ForagePANEditText @JvmOverloads constructor(
}
}

override fun showKeyboard() {
val imm = context.getSystemService<InputMethodManager>()
imm!!.showSoftInput(textInputEditText, 0)
}

override fun initWithForageConfig(forageConfig: ForageConfig, isPos: Boolean) {
// Must initialize DD at the beginning of each render function. DD requires the context,
// so we need to wait until a context is present to run initialization code. However,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class ForagePINEditText @JvmOverloads constructor(
private val vgsVaultWrapper: VGSVaultWrapper
private val forageVaultWrapper: ForageVaultWrapper

override fun showKeyboard() {
if (vault.getVaultType() == VaultType.VGS_VAULT_TYPE) {
vault.getVGSEditText().showKeyboard()
}
if (vault.getVaultType() == VaultType.BT_VAULT_TYPE) {
vault.getTextElement().showKeyboard(0)
}
}

/**
* The `vault` property acts as an abstraction for the actual code
* in ForagePINEditText, allowing it to work with a non-nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ class FlowBalanceFragment : Fragment() {
private lateinit var snap: TextView
private lateinit var nonSnap: TextView

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
foragePinEditText.requestFocus()
// our CI tests fail when we automatically show the keyboard
// because it covers certain elements. So this code is
// commented out by default. Uncomment it to make your
// dev experience slightly better :)
// foragePinEditText.showKeyboard()
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -57,8 +67,6 @@ class FlowBalanceFragment : Fragment() {
)
)

foragePinEditText.requestFocus()

val isFocused: TextView = binding.isFocused
val isComplete: TextView = binding.isComplete
val isEmpty: TextView = binding.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class FlowTokenizeFragment : Fragment() {

private val binding get() = _binding!!

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.tokenizeForagePanEditText.requestFocus()
// our CI tests fail when we automatically show the keyboard
// because it covers certain elements. So this code is
// commented out by default. Uncomment it to make your
// dev experience slightly better :)
// foragePinEditText.showKeyboard()
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down

0 comments on commit 939931a

Please sign in to comment.