Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Last active April 14, 2020 15:10
Show Gist options
  • Save prafullakumar/324980d96e19e39d162c36cc31933fff to your computer and use it in GitHub Desktop.
Save prafullakumar/324980d96e19e39d162c36cc31933fff to your computer and use it in GitHub Desktop.
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