mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-01 07:08:17 +00:00
34 lines
945 B
Swift
34 lines
945 B
Swift
import SwiftUI
|
|
|
|
extension TextView {
|
|
struct Representable: UIViewRepresentable {
|
|
@Binding var text: NSMutableAttributedString
|
|
@Binding var calculatedHeight: CGFloat
|
|
@Environment(\.sizeCategory) var sizeCategory
|
|
|
|
let keyboard: UIKeyboardType
|
|
var getTextView: ((UITextView) -> Void)?
|
|
|
|
func makeUIView(context: Context) -> UIKitTextView {
|
|
context.coordinator.textView
|
|
}
|
|
|
|
func updateUIView(_: UIKitTextView, context: Context) {
|
|
context.coordinator.update(representable: self)
|
|
if !context.coordinator.didBecomeFirstResponder {
|
|
context.coordinator.textView.becomeFirstResponder()
|
|
context.coordinator.didBecomeFirstResponder = true
|
|
}
|
|
}
|
|
|
|
@discardableResult func makeCoordinator() -> Coordinator {
|
|
Coordinator(
|
|
text: $text,
|
|
calculatedHeight: $calculatedHeight,
|
|
sizeCategory: sizeCategory,
|
|
getTextView: getTextView
|
|
)
|
|
}
|
|
}
|
|
}
|