Skip to content

Commit 9143eb4

Browse files
committed
(iOS) Adjust the placeholder location using textContainerInset
1 parent 46edfce commit 9143eb4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Sources/ResizingTextView/ResizingTextView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public struct ResizingTextView: View, Equatable {
2424
var textContainerInset: UIEdgeInsets?
2525
#endif
2626

27+
@Environment(\.layoutDirection) private var layoutDirection
28+
2729
#if os(macOS)
2830
public static var defaultLabelColor: NSColor {
2931
NSColor.labelColor
@@ -149,11 +151,15 @@ public struct ResizingTextView: View, Equatable {
149151
textContainerInset: textContainerInset
150152
)
151153
if let placeholder {
154+
let isLTR = layoutDirection == .leftToRight
152155
Text(placeholder)
153156
.font(Font(font))
154157
.lineLimit(1)
155158
.foregroundColor(Color(foregroundColor.withAlphaComponent(0.2)))
156-
.padding(.vertical, 8)
159+
.padding(.top, textContainerInset?.top ?? 0)
160+
.padding(isLTR ? .leading : .trailing, textContainerInset?.left ?? 0)
161+
.padding(.bottom, textContainerInset?.bottom ?? 0)
162+
.padding(isLTR ? .trailing : .leading, textContainerInset?.right ?? 0)
157163
.allowsHitTesting(false)
158164
.opacity(text.isEmpty ? 1 : 0)
159165
}

0 commit comments

Comments
 (0)