From 040f398b0aafdf9296c01604af62fd9530bd8797 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Sun, 15 Jan 2023 15:46:16 -0500 Subject: [PATCH] Fix crash-on-launch when post list is empty (#241) * Apply a quarter-second delay to the dispatched call * Update change log * Fix nav-back bug when launching to last draft * Improve keyboard present/dismiss animations * Update change log and bump build number --- CHANGELOG.md | 3 +++ Shared/WriteFreely_MultiPlatformApp.swift | 8 ++++---- WriteFreely-MultiPlatform.xcodeproj/project.pbxproj | 8 ++++---- iOS/PostEditor/MultilineTextView.swift | 2 +- iOS/PostEditor/PostTextEditingView.swift | 7 +++++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76288f0..3bcc2fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Mac] Fixed some build warnings in the project. - [Mac] Bumped WriteFreely package to v0.3.6 to handle decoding of fractional seconds in dates. - [iOS] Fixed a bug where posts were always shown in serif, even if the post was published with another font. +- [iOS] Restored the new-draft-on-launch feature and resolves crashing bug. +- [iOS] Fixed a bug that would navigate to a post on launch, then immediately navigate back to the post list. +- [iOS] Fixed some animation glitches when presenting and dismissing the keyboard. ## [1.0.14-ios] - 2022-12-18 diff --git a/Shared/WriteFreely_MultiPlatformApp.swift b/Shared/WriteFreely_MultiPlatformApp.swift index 15a8d88..bb6974a 100644 --- a/Shared/WriteFreely_MultiPlatformApp.swift +++ b/Shared/WriteFreely_MultiPlatformApp.swift @@ -152,13 +152,13 @@ struct WriteFreely_MultiPlatformApp: App { } private func showLastDraftOrCreateNewLocalPost() { - #if os(macOS) if model.editor.lastDraftURL != nil { - self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { + self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage() + } } else { createNewLocalPost() } - #endif } private func createNewLocalPost() { @@ -170,7 +170,7 @@ struct WriteFreely_MultiPlatformApp: App { let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font) withAnimation { // Set it as the selectedPost - DispatchQueue.main.asyncAfter(deadline: .now()) { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { self.model.selectedPost = managedPost } } diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index 37b3129..1ee6bb8 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -1050,7 +1050,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "ActionExtension-iOS/ActionExtension-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 695; + CURRENT_PROJECT_VERSION = 699; DEVELOPMENT_TEAM = TPPAB4YBA6; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "ActionExtension-iOS/Info.plist"; @@ -1081,7 +1081,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "ActionExtension-iOS/ActionExtension-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 695; + CURRENT_PROJECT_VERSION = 699; DEVELOPMENT_TEAM = TPPAB4YBA6; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "ActionExtension-iOS/Info.plist"; @@ -1224,7 +1224,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = "WriteFreely-MultiPlatform (iOS).entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 695; + CURRENT_PROJECT_VERSION = 699; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iOS/Info.plist; @@ -1250,7 +1250,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = "WriteFreely-MultiPlatform (iOS).entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 695; + CURRENT_PROJECT_VERSION = 699; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iOS/Info.plist; diff --git a/iOS/PostEditor/MultilineTextView.swift b/iOS/PostEditor/MultilineTextView.swift index ffffa18..54c79b1 100644 --- a/iOS/PostEditor/MultilineTextView.swift +++ b/iOS/PostEditor/MultilineTextView.swift @@ -41,7 +41,7 @@ private struct UITextViewWrapper: UIViewRepresentable { uiView.font = fontMetrics.scaledFont(for: font) if uiView.window != nil && isEditing { - DispatchQueue.main.async { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.55) { uiView.becomeFirstResponder() } } diff --git a/iOS/PostEditor/PostTextEditingView.swift b/iOS/PostEditor/PostTextEditingView.swift index 7184105..0482f7d 100644 --- a/iOS/PostEditor/PostTextEditingView.swift +++ b/iOS/PostEditor/PostTextEditingView.swift @@ -60,8 +60,8 @@ struct PostTextEditingView: View { } } } - .onChange(of: titleIsFirstResponder, perform: { _ in - self.bodyIsFirstResponder.toggle() + .onChange(of: titleIsFirstResponder, perform: { value in + self.bodyIsFirstResponder = !value }) .onAppear(perform: { switch post.appearance { @@ -75,6 +75,9 @@ struct PostTextEditingView: View { self.titleTextStyle = UIFont(name: appearance.rawValue, size: 26)! self.bodyTextStyle = UIFont(name: appearance.rawValue, size: 17)! }) + .onDisappear { + hideKeyboard() + } } private func didFinishEditingTitle() {