Skip to content

Commit

Permalink
Fix #4509: Text-based interaction EditText hints sometimes disappear …
Browse files Browse the repository at this point in the history
…when the keyboard is closed (#4556)

* fix unexpected hint problems

* add todos

* lint
  • Loading branch information
JishnuGoyal authored Sep 9, 2022
1 parent a6f856f commit 52f7a2c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ class FractionInputInteractionView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
private val hintText: CharSequence
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
hintText = (hint ?: "")
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

// TODO(#4574): Add tests to verify that the placeholder correctly shows/doesn’t show when expected
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hintText = hint
hideHint()
showSoftKeyboard(v, context)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class MathExpressionInteractionsView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
private var hintText: CharSequence
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
hintText = (hint ?: "")
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

// TODO(#4574): Add tests to verify that the placeholder correctly shows/doesn’t show when expected
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hintText = hint
hideHint()
showSoftKeyboard(v, context)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ class NumericInputInteractionView @JvmOverloads constructor(
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
private val stateKeyboardButtonListener: StateKeyboardButtonListener
private val hintText: CharSequence
private var hintText: CharSequence = ""

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
hintText = (hint ?: "")
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

// TODO(#4574): Add tests to verify that the placeholder correctly shows/doesn’t show when expected
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hintText = hint
hideHint()
showSoftKeyboard(v, context)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ class RatioInputInteractionView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
private val hintText: CharSequence
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
hintText = (hint ?: "")
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

// TODO(#4574): Add tests to verify that the placeholder correctly shows/doesn’t show when expected
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hintText = hint
hideHint()
KeyboardHelper.showSoftKeyboard(v, context)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ class TextInputInteractionView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
private val hintText: CharSequence
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
hintText = (hint ?: "")
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

// TODO(#4574): Add tests to verify that the placeholder correctly shows/doesn’t show when expected
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hintText = hint
hideHint()
showSoftKeyboard(v, context)
} else {
Expand Down

0 comments on commit 52f7a2c

Please sign in to comment.