Skip to content

Commit e4790c2

Browse files
committed
Add SecureField
1 parent b0a1dff commit e4790c2

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • AndroidSwiftUICore/Sources/AndroidSwiftUICore/Primitives

AndroidSwiftUICore/Sources/AndroidSwiftUICore/Primitives/Views.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,38 @@ extension TextField: PrimitiveView {
162162
}
163163
}
164164

165+
/// A text field that obscures its contents. Shares the TextField node with a
166+
/// `secure` flag; the interpreter applies a password transformation.
167+
public struct SecureField: View {
168+
169+
internal let placeholder: String
170+
internal let text: Binding<String>
171+
172+
public init<S: StringProtocol>(_ placeholder: S, text: Binding<String>) {
173+
self.placeholder = String(placeholder)
174+
self.text = text
175+
}
176+
177+
public typealias Body = Never
178+
}
179+
180+
extension SecureField: PrimitiveView {
181+
public func _render(in context: ResolveContext) -> RenderNode {
182+
let binding = text
183+
let callbackID = context.callbacks.register(.string { binding.wrappedValue = $0 })
184+
return RenderNode(
185+
type: "TextField",
186+
id: context.path,
187+
props: [
188+
"text": .string(text.wrappedValue),
189+
"placeholder": .string(placeholder),
190+
"onChange": .int(Int(callbackID)),
191+
"secure": .bool(true),
192+
]
193+
)
194+
}
195+
}
196+
165197
/// Eager stand-ins: laziness is an optimization the lazy container path (R7)
166198
/// provides; semantics match the eager stacks.
167199
public typealias LazyVStack = VStack

0 commit comments

Comments
 (0)