Skip to content

Commit 4a3874a

Browse files
Embed text editor fields into ScrollView (#227)
* Embed text editor fields into ScrollView * Bump version/build number and update change log * Fix truncated post badges on status change When going from a shorter label (e.g., ‘LOCAL’) to a longer one (e.g., ‘PUBLISHED’), the SwiftUI render loop would not expand the size of the post badge to fit the extra characters, so on change it would be truncated (e.g., read ‘PUBL…’). This change fixes the bug.
1 parent 884da07 commit 4a3874a

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- [Mac] New drafts are created in the currently-selected blog, rather than being created in Drafts (or "Anonymous" for Write.as accounts).
2222
- [Mac] Updated the URL and minimum version of the WriteFreely Swift package.
2323
- [Mac] Upgraded the Sparkle package to v2.
24-
- [Mac] The app now prompts you to reach out to our user forums if it detects a crash
24+
- [Mac] The app now prompts you to reach out to our user forums if it detects a crash.
25+
- [iOS] The post editor now scrolls in its entirety, including the title field.
2526

2627
### Fixed
2728

Shared/PostList/PostStatusBadgeView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct PostStatusBadgeView: View {
1414
.padding(EdgeInsets(top: 2.5, leading: 7.5, bottom: 2.5, trailing: 7.5))
1515
.background(badgeColor)
1616
.clipShape(RoundedRectangle(cornerRadius: 5.0, style: .circular))
17+
.frame(width: .infinity)
1718
}
1819

1920
func setupBadgeProperties(for status: PostStatus) -> (String, Color) {

WriteFreely-MultiPlatform.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@
10541054
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
10551055
CODE_SIGN_ENTITLEMENTS = "ActionExtension-iOS/ActionExtension-iOS.entitlements";
10561056
CODE_SIGN_STYLE = Automatic;
1057-
CURRENT_PROJECT_VERSION = 676;
1057+
CURRENT_PROJECT_VERSION = 679;
10581058
DEVELOPMENT_TEAM = TPPAB4YBA6;
10591059
GENERATE_INFOPLIST_FILE = YES;
10601060
INFOPLIST_FILE = "ActionExtension-iOS/Info.plist";
@@ -1066,7 +1066,7 @@
10661066
"@executable_path/Frameworks",
10671067
"@executable_path/../../Frameworks",
10681068
);
1069-
MARKETING_VERSION = 1.0.11;
1069+
MARKETING_VERSION = 1.0.12;
10701070
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform.ActionExtension-iOS";
10711071
PRODUCT_NAME = "$(TARGET_NAME)";
10721072
SDKROOT = iphoneos;
@@ -1085,7 +1085,7 @@
10851085
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
10861086
CODE_SIGN_ENTITLEMENTS = "ActionExtension-iOS/ActionExtension-iOS.entitlements";
10871087
CODE_SIGN_STYLE = Automatic;
1088-
CURRENT_PROJECT_VERSION = 676;
1088+
CURRENT_PROJECT_VERSION = 679;
10891089
DEVELOPMENT_TEAM = TPPAB4YBA6;
10901090
GENERATE_INFOPLIST_FILE = YES;
10911091
INFOPLIST_FILE = "ActionExtension-iOS/Info.plist";
@@ -1097,7 +1097,7 @@
10971097
"@executable_path/Frameworks",
10981098
"@executable_path/../../Frameworks",
10991099
);
1100-
MARKETING_VERSION = 1.0.11;
1100+
MARKETING_VERSION = 1.0.12;
11011101
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform.ActionExtension-iOS";
11021102
PRODUCT_NAME = "$(TARGET_NAME)";
11031103
SDKROOT = iphoneos;
@@ -1228,7 +1228,7 @@
12281228
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12291229
CODE_SIGN_ENTITLEMENTS = "WriteFreely-MultiPlatform (iOS).entitlements";
12301230
CODE_SIGN_STYLE = Automatic;
1231-
CURRENT_PROJECT_VERSION = 676;
1231+
CURRENT_PROJECT_VERSION = 679;
12321232
DEVELOPMENT_TEAM = TPPAB4YBA6;
12331233
ENABLE_PREVIEWS = YES;
12341234
INFOPLIST_FILE = iOS/Info.plist;
@@ -1237,7 +1237,7 @@
12371237
"$(inherited)",
12381238
"@executable_path/Frameworks",
12391239
);
1240-
MARKETING_VERSION = 1.0.11;
1240+
MARKETING_VERSION = 1.0.12;
12411241
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform";
12421242
PRODUCT_NAME = "WriteFreely-MultiPlatform";
12431243
SDKROOT = iphoneos;
@@ -1254,7 +1254,7 @@
12541254
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12551255
CODE_SIGN_ENTITLEMENTS = "WriteFreely-MultiPlatform (iOS).entitlements";
12561256
CODE_SIGN_STYLE = Automatic;
1257-
CURRENT_PROJECT_VERSION = 676;
1257+
CURRENT_PROJECT_VERSION = 679;
12581258
DEVELOPMENT_TEAM = TPPAB4YBA6;
12591259
ENABLE_PREVIEWS = YES;
12601260
INFOPLIST_FILE = iOS/Info.plist;
@@ -1263,7 +1263,7 @@
12631263
"$(inherited)",
12641264
"@executable_path/Frameworks",
12651265
);
1266-
MARKETING_VERSION = 1.0.11;
1266+
MARKETING_VERSION = 1.0.12;
12671267
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform";
12681268
PRODUCT_NAME = "WriteFreely-MultiPlatform";
12691269
SDKROOT = iphoneos;

iOS/PostEditor/PostBodyTextView.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ class PostBodyCoordinator: NSObject, UITextViewDelegate, NSLayoutManagerDelegate
2121
_text = text
2222
_isFirstResponder = isFirstResponder
2323
self.lineSpacingMultiplier = lineSpacingMultiplier
24+
25+
super.init()
26+
27+
updateSize()
28+
}
29+
30+
func updateSize() {
31+
DispatchQueue.main.async {
32+
guard let view = self.textView else { return }
33+
let size = view.sizeThatFits(view.bounds.size)
34+
if self.postBodyTextView.height != size.height {
35+
self.postBodyTextView.height = size.height
36+
}
37+
}
2438
}
2539

2640
func textViewDidChange(_ textView: UITextView) {
@@ -34,6 +48,14 @@ class PostBodyCoordinator: NSObject, UITextViewDelegate, NSLayoutManagerDelegate
3448
self.didBecomeFirstResponder = false
3549
}
3650

51+
func layoutManager(
52+
_ layoutManager: NSLayoutManager,
53+
didCompleteLayoutFor textContainer: NSTextContainer?,
54+
atEnd layoutFinishedFlag: Bool
55+
) {
56+
updateSize()
57+
}
58+
3759
func layoutManager(
3860
_ layoutManager: NSLayoutManager,
3961
lineSpacingAfterGlyphAt glyphIndex: Int,
@@ -59,6 +81,7 @@ class PostBodyCoordinator: NSObject, UITextViewDelegate, NSLayoutManagerDelegate
5981
struct PostBodyTextView: UIViewRepresentable {
6082
@Binding var text: String
6183
@Binding var textStyle: UIFont
84+
@Binding var height: CGFloat
6285
@Binding var isFirstResponder: Bool
6386
@State var lineSpacing: CGFloat
6487

iOS/PostEditor/PostTextEditingView.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ struct PostTextEditingView: View {
88
@State private var appearance: PostAppearance = .serif
99
@State private var titleTextStyle: UIFont = UIFont(name: "Lora-Regular", size: 26)!
1010
@State private var titleTextHeight: CGFloat = 50
11+
@State private var bodyTextHeight: CGFloat = 50
1112
@State private var titleIsFirstResponder: Bool = true
1213
@State private var bodyTextStyle: UIFont = UIFont(name: "Lora-Regular", size: 17)!
1314
@State private var bodyIsFirstResponder: Bool = false
1415
private let lineSpacingMultiplier: CGFloat = 0.5
16+
private let textEditorHeight: CGFloat = 50
1517

1618
init(
1719
post: ObservedObject<WFAPost>,
@@ -25,15 +27,22 @@ struct PostTextEditingView: View {
2527
}
2628

2729
var titleFieldHeight: CGFloat {
28-
let minHeight: CGFloat = 50
30+
let minHeight: CGFloat = textEditorHeight
2931
if titleTextHeight < minHeight {
3032
return minHeight
3133
}
3234
return titleTextHeight
3335
}
36+
var bodyFieldHeight: CGFloat {
37+
let minHeight: CGFloat = textEditorHeight
38+
if bodyTextHeight < minHeight {
39+
return minHeight
40+
}
41+
return bodyTextHeight
42+
}
3443

3544
var body: some View {
36-
VStack {
45+
ScrollView(.vertical) {
3746
ZStack(alignment: .topLeading) {
3847
if post.title.count == 0 {
3948
Text("Title (optional)")
@@ -74,9 +83,11 @@ struct PostTextEditingView: View {
7483
PostBodyTextView(
7584
text: $post.body,
7685
textStyle: $bodyTextStyle,
86+
height: $bodyTextHeight,
7787
isFirstResponder: $bodyIsFirstResponder,
7888
lineSpacing: horizontalSizeClass == .compact ? lineSpacingMultiplier / 2 : lineSpacingMultiplier
7989
)
90+
.frame(height: bodyFieldHeight)
8091
.accessibilityLabel(Text("Body"))
8192
.accessibilityHint(Text("Add or edit the body of your post"))
8293
.onChange(of: post.body) { _ in

0 commit comments

Comments
 (0)