Skip to content

MobBridge.kt.eex: MobTextField honours secure: true - #6

Closed
C-Sinclair wants to merge 1 commit into
GenericJam:masterfrom
C-Sinclair:text-field-secure
Closed

MobBridge.kt.eex: MobTextField honours secure: true#6
C-Sinclair wants to merge 1 commit into
GenericJam:masterfrom
C-Sinclair:text-field-secure

Conversation

@C-Sinclair

Copy link
Copy Markdown
Contributor

Summary

Companion to GenericJam/mob#12 (mob iOS secure: true for text_field). Wires the Android Compose side so text_field secure={true} actually masks input on both platforms.

In MobBridge.kt.eex's MobTextField composable:

  • Read secure: Boolean from the prop bag.
  • Apply PasswordVisualTransformation() when set, VisualTransformation.None otherwise.
  • When secure: true, override keyboardType to KeyboardType.Password (autocorrect off, no suggestions strip). The override rule documented inline — apps wanting numeric-PIN masking on a Number keyboard can layer their own masking; we can revisit based on real demand.
%{type: :text_field, props: %{
  value: assigns.password,
  placeholder: "Password",
  secure: true,
  on_change: {self(), :password_changed}
}}

Cleartext still reaches the BEAM via on_change — the transformation is purely visual. Existing apps generated from prior templates are unaffected; the prop becomes a no-op there. Regenerating or hand-porting MobBridge.kt enables masking.

CHANGELOG / version

Under ## [Unreleased]. No mix.exs bump — follows the repo's ride-along bump pattern (e.g. 2e566d9 Bump to 0.3.5 — fix three template regressions + add tier-1/3 lint suite rolling up three prior feature commits).

Test plan

  • MobNew.Templates.Lint.check_kotlin/1 on the regenerated MobBridge.kt — returns []. All 8 structural checks pass (balanced braces/parens/brackets, no EEx leaks, no duplicate Kotlin imports, etc.).
  • mix test — 230/266 pass (same baseline as master; the 36 pre-existing failures are LiveView-path tests requiring mix archive.install hex phx_new, plus the :requires_android_ndk-tagged clang test).
  • mix format --check-formatted — clean
  • mix credo --strict — clean (129 mods/funs, 0 issues)
  • mix compile --warnings-as-errors — clean
  • Verified end-to-end in a generated app: tap into a secure: true field, type "hunter2" — Compose renders 7 dots, BEAM-side :password assign holds "hunter2", on-screen length label updates live. Same contract as the iOS verification in text_field: secure: true for masked password input mob#12.

Files

  • priv/templates/mob.new/android/app/src/main/java/MobBridge.kt.eex — two new imports (PasswordVisualTransformation, VisualTransformation); isSecure flag in MobTextField; visualTransformation parameter; keyboard-type override
  • CHANGELOG.md — entry under ## [Unreleased]

Apply Compose's `PasswordVisualTransformation()` and switch
`keyboardType` to `KeyboardType.Password` when the BEAM-side
`text_field` carries `secure: true`. Mirrors the iOS-side
`SecureField`-vs-`TextField` swap landing in mob 0.6.x.

Cleartext still reaches the BEAM via `on_change` so apps hash/store
the value as normal — the transformation is purely visual.

`secure: true` overrides any explicit `keyboard:` choice. Numeric
PIN-style masking on a Number keyboard isn't a single-prop combo;
apps that need it can layer their own masking, or we can revisit the
override rule based on real demand.

Verified:
- `MobNew.Templates.Lint.check_kotlin/1` clean on regenerated MobBridge.kt
  (balanced braces/parens/brackets, no EEx leaks, no duplicate imports)
- `mix test` — same 230/266 pass baseline; the 36 pre-existing failures
  (LiveView path missing phx_new locally, clang/NDK test) unchanged
- `mix format`, `mix credo --strict`, `mix compile --warnings-as-errors`
  all clean
@GenericJam

Copy link
Copy Markdown
Owner

Thanks @C-Sinclair — landed as 4a41f47 in mob_new 0.3.8 with your authorship preserved. Paired with mob#12 (iOS SecureField) in mob 0.6.15 so the secure: true contract works across both platforms in the same release.

CHANGELOG entry merged into the [0.3.8] [Unreleased]-renamed section alongside the project_swift_sources hook landing in the same release. Closing since the commit is on master.

@GenericJam GenericJam closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants