Skip to content

Commit fdb429e

Browse files
authored
Merge pull request #65 from rk-helper/main
Centered texting
2 parents 93a6be4 + 6afc414 commit fdb429e

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

freewrite/ContentView.swift

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ struct ContentView: View {
382382
return colorScheme == .light ? Color.primary : Color.white
383383
}
384384

385+
@State private var viewHeight: CGFloat = 0
386+
385387
var body: some View {
386388
let buttonBackground = colorScheme == .light ? Color.white : Color.black
387389
let navHeight: CGFloat = 68
@@ -394,24 +396,27 @@ struct ContentView: View {
394396
Color(colorScheme == .light ? .white : .black)
395397
.ignoresSafeArea()
396398

397-
TextEditor(text: Binding(
398-
get: { text },
399-
set: { newValue in
400-
// Ensure the text always starts with two newlines
401-
if !newValue.hasPrefix("\n\n") {
402-
text = "\n\n" + newValue.trimmingCharacters(in: .newlines)
403-
} else {
404-
text = newValue
399+
400+
TextEditor(text: Binding(
401+
get: { text },
402+
set: { newValue in
403+
// Ensure the text always starts with two newlines
404+
if !newValue.hasPrefix("\n\n") {
405+
text = "\n\n" + newValue.trimmingCharacters(in: .newlines)
406+
} else {
407+
text = newValue
408+
}
405409
}
406-
}
407-
))
410+
))
408411
.background(Color(colorScheme == .light ? .white : .black))
409412
.font(.custom(selectedFont, size: fontSize))
410413
.foregroundColor(colorScheme == .light ? Color(red: 0.20, green: 0.20, blue: 0.20) : Color(red: 0.9, green: 0.9, blue: 0.9))
411414
.scrollContentBackground(.hidden)
412415
.scrollIndicators(.never)
413416
.lineSpacing(lineHeight)
414417
.frame(maxWidth: 650)
418+
419+
415420
.id("\(selectedFont)-\(fontSize)-\(colorScheme)")
416421
.padding(.bottom, bottomNavOpacity > 0 ? navHeight : 0)
417422
.ignoresSafeArea()
@@ -426,13 +431,20 @@ struct ContentView: View {
426431
Text(placeholderText)
427432
.font(.custom(selectedFont, size: fontSize))
428433
.foregroundColor(colorScheme == .light ? .gray.opacity(0.5) : .gray.opacity(0.6))
429-
// .padding(.top, 8)
430-
// .padding(.leading, 8)
434+
// .padding(.top, 8)
435+
// .padding(.leading, 8)
431436
.allowsHitTesting(false)
432437
.offset(x: 5, y: placeholderOffset)
433438
}
434439
}, alignment: .topLeading
435440
)
441+
.onGeometryChange(for: CGFloat.self) { proxy in
442+
proxy.size.height
443+
} action: { height in
444+
viewHeight = height
445+
}
446+
.contentMargins(.bottom, viewHeight / 4)
447+
436448

437449
VStack {
438450
Spacer()
@@ -1399,4 +1411,4 @@ extension NSView {
13991411

14001412
#Preview {
14011413
ContentView()
1402-
}
1414+
}

0 commit comments

Comments
 (0)