-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UIViewRepresentable(PlantUMLTextFieldWithCustomKeyboard) fo…
…r managing inputView
- Loading branch information
1 parent
e62e205
commit beb3a38
Showing
7 changed files
with
147 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLTextField+Representable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Bartolomeo Sorrentino on 18/09/22. | ||
// | ||
|
||
import UIKit | ||
import SwiftUI | ||
|
||
public struct PlantUMLTextFieldWithCustomKeyboard : UIViewRepresentable { | ||
|
||
public typealias UIViewType = UITextField | ||
|
||
private let textField = UITextField() | ||
|
||
public init() { | ||
|
||
} | ||
|
||
public func makeCoordinator() -> PlantUMLTextFieldWithCustomKeyboard.Coordinator { | ||
Coordinator(textfield: self) | ||
} | ||
|
||
public func makeUIView(context: Context) -> UITextField { | ||
|
||
textField.delegate = context.coordinator | ||
return textField | ||
} | ||
|
||
public func updateUIView(_ uiView: UITextField, context: Context) { | ||
|
||
} | ||
|
||
|
||
public class Coordinator: NSObject, UITextFieldDelegate { | ||
|
||
private let parent : PlantUMLTextFieldWithCustomKeyboard | ||
|
||
public init(textfield : PlantUMLTextFieldWithCustomKeyboard) { | ||
self.parent = textfield | ||
} | ||
|
||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLTextField.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// PlantUMLTextField.swift | ||
// PlantUML | ||
// | ||
// Created by Bartolomeo Sorrentino on 06/09/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct PlantUMLTextField: View { | ||
|
||
public typealias ChangeHandler = ( String ) -> Void | ||
|
||
@ObservedObject var customKeyboard: CustomKeyboardObject | ||
|
||
@State var value: String | ||
|
||
@FocusState private var isFocused: Bool | ||
|
||
var onChange:ChangeHandler | ||
|
||
public init( value: String, customKeyboard: CustomKeyboardObject, onChange: @escaping ChangeHandler ) { | ||
self.value = value | ||
self.customKeyboard = customKeyboard | ||
self.onChange = onChange | ||
} | ||
|
||
public var body: some View { | ||
|
||
VStack { | ||
|
||
HStack(spacing: 15) { | ||
|
||
TextField( "", text: $value ) | ||
.keyboardType(.asciiCapableNumberPad) | ||
.textInputAutocapitalization(.never) | ||
.font(Font.system(size: 15).monospaced()) | ||
.submitLabel(.done) | ||
.focused($isFocused) | ||
.onChange(of: value, perform: onChange ) | ||
// .introspectTextField { textField in | ||
// print( "==> introspectTextField: \(value)" ) | ||
// } | ||
|
||
|
||
if( isFocused ) { | ||
ShowKeyboardAccessoryButton( show: $customKeyboard.showKeyboard ) | ||
} | ||
} | ||
|
||
} | ||
.edgesIgnoringSafeArea(.all) | ||
|
||
} | ||
} | ||
|
||
struct PlantUMLTextField_Previews: PreviewProvider { | ||
|
||
struct PlantUMLTextFieldProxy : View { | ||
@ObservedObject var customKeyboard = CustomKeyboardObject() | ||
|
||
public var body : some View { | ||
PlantUMLTextField(value: "test", customKeyboard: customKeyboard, onChange: { (v) in } ) | ||
} | ||
} | ||
|
||
static var previews: some View { | ||
PlantUMLTextFieldProxy() | ||
} | ||
|
||
} |