Skip to content

Commit 346138c

Browse files
authored
feature: Adds text to CharactersChange (SwiftUIX#366)
* feature: Adds text to CharactersChange * refactor: Changes text to currentText and removes force unwrap
1 parent b8cd3f7 commit 346138c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/Intramodular/Text/CocoaTextField.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct CocoaTextField<Label: View>: View {
1212
typealias Rect = ((_ bounds: CGRect, _ original: CGRect) -> CGRect)
1313

1414
public struct CharactersChange: Hashable {
15+
public let currentText: String
1516
public let range: NSRange
1617
public let replacement: String
1718
}
@@ -143,7 +144,7 @@ fileprivate struct _CocoaTextField<Label: View>: UIViewRepresentable {
143144
shouldChangeCharactersIn range: NSRange,
144145
replacementString string: String
145146
) -> Bool {
146-
configuration.onCharactersChange(.init(range: range, replacement: string))
147+
configuration.onCharactersChange(.init(currentText: textField.text ?? "", range: range, replacement: string))
147148
}
148149

149150
func textFieldShouldReturn(_ textField: UITextField) -> Bool {

0 commit comments

Comments
 (0)