mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Set the font in the updateUIView method
Also, wrap becomeFirstResponder in async dispatch This fixes issues when we’re updating the responder chain every time SwiftUI refreshes the view, which can have unpredictable side effects.
This commit is contained in:
parent
acbe4f12a7
commit
52618095f2
@ -17,17 +17,12 @@ private struct UITextViewWrapper: UIViewRepresentable {
|
|||||||
textField.delegate = context.coordinator
|
textField.delegate = context.coordinator
|
||||||
|
|
||||||
textField.isEditable = true
|
textField.isEditable = true
|
||||||
textField.font = UIFont.preferredFont(forTextStyle: .body)
|
|
||||||
textField.isSelectable = true
|
textField.isSelectable = true
|
||||||
textField.isUserInteractionEnabled = true
|
textField.isUserInteractionEnabled = true
|
||||||
textField.isScrollEnabled = false
|
textField.isScrollEnabled = false
|
||||||
textField.backgroundColor = UIColor.clear
|
textField.backgroundColor = UIColor.clear
|
||||||
textField.smartDashesType = .no
|
textField.smartDashesType = .no
|
||||||
|
|
||||||
let font = textStyle
|
|
||||||
let fontMetrics = UIFontMetrics(forTextStyle: .largeTitle)
|
|
||||||
textField.font = fontMetrics.scaledFont(for: font)
|
|
||||||
|
|
||||||
if nil != onDone {
|
if nil != onDone {
|
||||||
textField.returnKeyType = .next
|
textField.returnKeyType = .next
|
||||||
}
|
}
|
||||||
@ -41,8 +36,14 @@ private struct UITextViewWrapper: UIViewRepresentable {
|
|||||||
uiView.text = self.text
|
uiView.text = self.text
|
||||||
}
|
}
|
||||||
|
|
||||||
if uiView.window != nil, isEditing {
|
let font = textStyle
|
||||||
uiView.becomeFirstResponder()
|
let fontMetrics = UIFontMetrics(forTextStyle: .largeTitle)
|
||||||
|
uiView.font = fontMetrics.scaledFont(for: font)
|
||||||
|
|
||||||
|
if uiView.window != nil && isEditing {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
uiView.becomeFirstResponder()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UITextViewWrapper.recalculateHeight(view: uiView, result: $calculatedHeight)
|
UITextViewWrapper.recalculateHeight(view: uiView, result: $calculatedHeight)
|
||||||
|
Loading…
Reference in New Issue
Block a user