Last active
April 14, 2020 15:10
-
-
Save prafullakumar/324980d96e19e39d162c36cc31933fff to your computer and use it in GitHub Desktop.
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
struct TextView: UIViewRepresentable { | |
//enum to define keyboard or input view handeling will be done in coorinator later | |
enum PickerType { | |
case keyboard(type: UIKeyboardType) | |
case datePicker(minDate: Date, maxDate: Date) | |
case customList(list: [String]) | |
} | |
var pickerType: TextView.PickerType | |
@Binding var text: String //get set text | |
let placeholder: String | |
func makeUIView(context: Context) -> UITextField { | |
let textField = UITextField() | |
textField.delegate = context.coordinator | |
textField.placeholder = placeholder | |
textField.frame.size.height = 40 | |
textField.borderStyle = .roundedRect | |
textField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | |
return textField | |
} | |
func updateUIView(_ uiView: UITextField, context: Context) { | |
switch pickerType { | |
case .datePicker: | |
uiView.text = text | |
case .customList: | |
uiView.text = text | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment