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

View File

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