Fix not being able to tap text view placeholders on Compose screen

Fixes #111
This commit is contained in:
Shadowfacts 2020-09-17 18:40:02 -04:00
parent ee90b20f7f
commit 5906c374ba
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 19 additions and 17 deletions

View File

@ -27,13 +27,7 @@ struct ComposeTextView: View {
var body: some View {
ZStack(alignment: .topLeading) {
WrappedTextView(
text: $text,
textDidChange: self.textDidChange,
backgroundColor: backgroundColor,
font: .systemFont(ofSize: fontSize)
)
.frame(height: height ?? minHeight)
Color(backgroundColor)
if text.isEmpty, let placeholder = placeholder {
placeholder
@ -41,6 +35,13 @@ struct ComposeTextView: View {
.foregroundColor(.secondary)
.offset(x: 4, y: 8)
}
WrappedTextView(
text: $text,
textDidChange: self.textDidChange,
font: .systemFont(ofSize: fontSize)
)
.frame(height: height ?? minHeight)
}
}
@ -73,14 +74,13 @@ struct WrappedTextView: UIViewRepresentable {
@Binding var text: String
var textDidChange: ((UITextView) -> Void)?
var backgroundColor = UIColor.secondarySystemBackground
var font = UIFont.systemFont(ofSize: 20)
func makeUIView(context: Context) -> UITextView {
let textView = UITextView()
textView.delegate = context.coordinator
textView.isEditable = true
textView.backgroundColor = backgroundColor
textView.backgroundColor = .clear
textView.font = font
textView.textContainer.lineBreakMode = .byWordWrapping
return textView

View File

@ -20,6 +20,15 @@ struct MainComposeTextView: View {
var body: some View {
ZStack(alignment: .topLeading) {
Color(UIColor.secondarySystemBackground)
if draft.text.isEmpty {
placeholder
.font(.system(size: 20))
.foregroundColor(.secondary)
.offset(x: 4, y: 8)
}
MainComposeWrappedTextView(
text: $draft.text,
visibility: draft.visibility,
@ -28,13 +37,6 @@ struct MainComposeTextView: View {
self.height = max(textView.contentSize.height, minHeight)
}
.frame(height: height ?? minHeight)
if draft.text.isEmpty {
placeholder
.font(.system(size: 20))
.foregroundColor(.secondary)
.offset(x: 4, y: 8)
}
}.onAppear {
if !hasFirstAppeared {
hasFirstAppeared = true
@ -59,7 +61,7 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
let textView = UITextView()
textView.delegate = context.coordinator
textView.isEditable = true
textView.backgroundColor = .secondarySystemBackground
textView.backgroundColor = .clear
textView.font = .systemFont(ofSize: 20)
textView.textContainer.lineBreakMode = .byWordWrapping
context.coordinator.textView = textView