Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ Full module documentation: [hexdocs.pm/mob](https://hexdocs.pm/mob).

---

## [Unreleased]

### Added
- `text_field` now accepts a `secure: true` prop. iOS renders the field
as a SwiftUI `SecureField` (masked input) instead of the plain
`TextField`. The prop flows through the existing renderer
passthrough; cleartext still reaches the BEAM via `on_change` so apps
can hash/store the value as normal. Android consumes the same prop
via `PasswordVisualTransformation` once `mob_new`'s `MobBridge.kt.eex`
template is updated in a companion PR — until then the prop is a
graceful no-op on Android (renders as a regular field), no breakage.

Reveal-toggle ("eye" button) is intentionally deferred — its
interaction with SwiftUI focus retention requires a `ZStack`-and-opacity
rebuild of `MobTextField` and warrants its own change.

## [0.6.7]

### Added
Expand Down
1 change: 1 addition & 0 deletions ios/MobNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nonnull)
NSString *keyboardTypeStr; // "default","number","decimal","email","phone","url"
@property(nonatomic, copy, nonnull) NSString *returnKeyStr; // "done","next","go","search","send"
@property(nonatomic, assign) BOOL isSecure; // mask input (SecureField on iOS)
@property(nonatomic, copy, nullable) void (^onFocus)(void);
@property(nonatomic, copy, nullable) void (^onBlur)(void);
@property(nonatomic, copy, nullable) void (^onSubmit)(void);
Expand Down
11 changes: 10 additions & 1 deletion ios/MobRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,17 @@ private struct MobTextField: View {
}
}

@ViewBuilder
private var field: some View {
if node.isSecure {
SecureField(placeholder, text: $text)
} else {
TextField(placeholder, text: $text)
}
}

var body: some View {
TextField(placeholder, text: $text)
field
.focused($isFocused)
.keyboardType(keyboardType)
.submitLabel(submitLabel)
Expand Down
4 changes: 4 additions & 0 deletions ios/mob_nif.m
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ static void mob_send_change_float(int handle, double value) {
if ([returnKey isKindOfClass:[NSString class]])
node.returnKeyStr = returnKey;

id secure = props[@"secure"];
if ([secure isKindOfClass:[NSNumber class]])
node.isSecure = [secure boolValue];

id onFocus = props[@"on_focus"];
if (onFocus && [onFocus isKindOfClass:[NSNumber class]]) {
int handle = [onFocus intValue];
Expand Down
16 changes: 16 additions & 0 deletions test/mob/renderer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,22 @@ defmodule Mob.RendererTest do
assert decoded["props"]["return_key"] == "next"
end

test "secure boolean is passed through unchanged" do
tree = %{type: :text_field, props: %{value: "", secure: true}, children: []}
Renderer.render(tree, :android, MockNIF)
{:set_root, [json]} = Enum.find(MockNIF.calls(), fn {f, _} -> f == :set_root end)
decoded = :json.decode(json)
assert decoded["props"]["secure"] == true
end

test "secure defaults to absent when unset" do
tree = %{type: :text_field, props: %{value: ""}, children: []}
Renderer.render(tree, :android, MockNIF)
{:set_root, [json]} = Enum.find(MockNIF.calls(), fn {f, _} -> f == :set_root end)
decoded = :json.decode(json)
refute Map.has_key?(decoded["props"], "secure")
end

test "register_tap receives {pid, tag} for tagged taps" do
pid = self()
tree = %{type: :button, props: %{text: "Tap", on_tap: {pid, :my_action}}, children: []}
Expand Down