Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Text Field in Compose

Avatar for Albert Chang Albert Chang
September 15, 2023

Understanding Text Field in Compose

Avatar for Albert Chang

Albert Chang

September 15, 2023
Tweet

Other Decks in Programming

Transcript

  1. Parameters of BasicTextField • String vs. TextFieldValue • Caveats of

    onValueChange • Do not change the input value whenever possible • Do not assume that characters arrive one by one • VisualTransformation • decorationBox
  2. How to create a text fi eld with custom design

    • Need to unify the line height of Latin characters and Japanese characters • Setting line height to 1.5 times of font size should be good enough
  3. Default text style values includeFontP adding alignment trim Before Compose

    1.6 true Proportional Both Compose 1.6+ false Center (Material 2/3 only) None (Material 2/3 only)
  4. Text fi eld state management • Update the state synchronously

    • MutableState is recommended • MutableStateFlow is also okay • Use Dispatcher.Main.immediate (default) • Make sure all transformations are synchronous
  5. New text fi eld API • BasicTextField2 (name is temporary)

    • Will replace current API • Current API has some fundamental design problems and tech debt to be addressed
  6. Design problems of TextFieldValue • Composition can be changed by

    API user • One-frame delay before state change is seen • Complex and error-prone internal state management
  7. BasicTextField2 • Simpler and robuster internal implementation • More intuitive

    API • Easier-to-implement visual transformation • More features • Better performance