material-components / material-components/material-components-android

[TextInputLayout] Prefix not displayed for the first time

Open
#3,070 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: TextField
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:** Prefix not displayed for the first time

In Binding Adapter prefix appeared from second call

```
@BindingAdapter(
value = ["zeroSalaryPlaceholder", "negativeSalaryPrefixByArticle", "negativeSalaryPrefixByArticleLogWorkType"],
requireAll = true
)
fun bindZeroSalaryPlaceholder(
view: OneLineEditableItem,
inputText: String?,
digit: Float?,
logWorkType: LogWorkType?
) =
view.apply {
inputText?.let { enteredText ->
when {
enteredText.isNotEmpty() && ((logWorkType == LogWorkType.Deduction) || (digit != null && digit < 0F)) -> {
setZeroPlaceholder(null)
setTextPrefix("-")
}
enteredText.isEmpty() -> {
setTextPrefix(null)
setZeroPlaceholder(R.string.amount)
}
else -> Unit
}
}
}
```

` fun setTextPrefix(prefix: String?) = binding.apply {
itemOneLineTextLayout.prefixText = prefix
} `

image

image

image

**Expected behavior:** prefix appeared from FIRST call

**Source code:** I think [this code](https://github.com/material-components/material-components-android/blob/ba70cd72d92501d556c3a4dbf01b1446217e4627/lib/java/com/google/android/material/textfield/TextInputLayout.java#L3936) working wrong, because startLayout.getMeasuredWidth() still 0 when we have getPrefixText() not null, that's why prefix not displayed.

**Android API version:** Android API 30

**Material Library version:** 1.8.0-alpha02, 1.8.0-alpha01, 1.7.0

**Device:** Emulator and Physical

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/java/com/google/android/material/textfield/TextInputLayout.java at line 3936 and reproduce the first Binding Adapter call with prefixText set on Android API 30. Trace the initial measurement of startLayout, and consider the issue complete when the prefix is visible on the first call without requiring a second binding update.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.