A proof-of-concept text edit component in SwiftUI & CoreText. No UIKit, No AppKit, no UITextView/NSTextView/UITextField involved.
Note Due to SwiftUI limitations (as of May 2021) it's not possible to handle keystrokes just with SwiftUI. To overcome this limitation, the UIKeyboardViewController
is responsible for handling keys and forward to SwiftUI codebase.
If you have questions or want to reach to me, use this thread: https://twitter.com/krzyzanowskim/status/1269402396217745410
Marcin Krzyzanowski @krzyzanowskim
struct TextEditingView: View {
@State private var text = "type here...\n"
@State private var font = UIFont.preferredFont(forTextStyle: .body) as CTFont
@State private var carretWidth = 2.0 as CGFloat
var body: some View {
TextEdit(
text: $text,
font: $font,
carretWidth: $carretWidth
)
}
}
CoreText + SwiftUI.
For fun and profit.
Here are some related projects