Skip to content

Commit

Permalink
CLTextEditor now uses GeometryReader for measuring max width.....
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangerhards committed Sep 2, 2022
1 parent 4820787 commit 02083ca
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Sources/CleanUI/Views/TextEditors/CLTextEditor.swift
Expand Up @@ -50,17 +50,27 @@ public struct CLTextEditor: View {

public var body: some View {
ZStack(alignment: .topLeading) {
Text(text)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(Color.clear)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
.allowsHitTesting(false)
.frame(minHeight: minHeight, alignment: .topLeading)

if text.isEmpty {
Text(placeholder)
.foregroundColor(.gray)
.opacity(0.6)
.allowsHitTesting(false)
}

TextViewOverlay(text: $text, font: .callout, maxLayoutWidth: UIScreen.main.bounds.size.width, textViewStore: textViewStore, keyboardType: keyboardType, attributes: attributes)
.frame(maxWidth: .infinity, minHeight: minHeight, alignment: .topLeading)
}
.font(.callout)
.overlay(
GeometryReader { geometryReader in
TextViewOverlay(text: $text, font: .callout, maxLayoutWidth: geometryReader.maxWidth, textViewStore: textViewStore, keyboardType: keyboardType, attributes: attributes)
}
)
.onChange(of: text) { value in
if characterLimit != 0 {
if value.count > characterLimit {
Expand Down Expand Up @@ -99,7 +109,7 @@ struct TextViewOverlay: UIViewRepresentable {
textView.keyboardType = keyboardType
textView.textContainer.lineFragmentPadding = 0
textView.adjustsFontForContentSizeCategory = true
textView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)

return textView
}
Expand Down

0 comments on commit 02083ca

Please sign in to comment.