From 105772422bceaa7858b598ffff41656dd978bbce Mon Sep 17 00:00:00 2001 From: Kyle Van Essen Date: Thu, 29 Aug 2024 14:45:27 -0700 Subject: [PATCH] Remove magic keyboard observer initialization --- BlueprintUILists.podspec | 4 +- CHANGELOG.md | 2 + Demo/Sources/AppDelegate.swift | 3 + ListableUI.podspec | 4 +- .../KeyboardObserver/KeyboardObserver.swift | 9 ++- .../SetupKeyboardObserverOnAppStartup.m | 66 ------------------- Package.swift | 1 - Podfile.lock | 4 +- 8 files changed, 17 insertions(+), 76 deletions(-) delete mode 100644 ListableUI/Sources/KeyboardObserver/SetupKeyboardObserverOnAppStartup.m diff --git a/BlueprintUILists.podspec b/BlueprintUILists.podspec index 6f9887415..59f1c14f3 100644 --- a/BlueprintUILists.podspec +++ b/BlueprintUILists.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.dependency 'ListableUI' s.dependency 'BlueprintUI', *BLUEPRINT_VERSION - s.source_files = 'BlueprintUILists/Sources/**/*.{swift}' + s.source_files = 'BlueprintUILists/Sources/**/*.swift' s.pod_target_xcconfig = { 'APPLICATION_EXTENSION_API_ONLY' => 'YES', @@ -27,7 +27,7 @@ Pod::Spec.new do |s| # These tests can only be run locally, because they depend on local pods. s.test_spec 'Tests' do |test_spec| - test_spec.source_files = 'BlueprintUILists/Tests/**/*.{swift}' + test_spec.source_files = 'BlueprintUILists/Tests/**/*.swift' test_spec.ios.resource_bundle = { 'BlueprintUIListsResources' => 'BlueprintUILists/Tests/Resources/**/*.*' } test_spec.dependency 'BlueprintUICommonControls', *BLUEPRINT_VERSION diff --git a/CHANGELOG.md b/CHANGELOG.md index 44ad8987a..2f9d70e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Removed +- Removed "magic" behavior that automatically loaded our internal keyboard observer. You must now manually call `ListView.configure(with:)` early in your application's lifecycle. + ### Changed ### Misc diff --git a/Demo/Sources/AppDelegate.swift b/Demo/Sources/AppDelegate.swift index e5cb1aef2..ea0d6c23c 100644 --- a/Demo/Sources/AppDelegate.swift +++ b/Demo/Sources/AppDelegate.swift @@ -7,6 +7,7 @@ // import UIKit +import ListableUI @UIApplicationMain @@ -16,6 +17,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + ListView.configure(with: application) + let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = DemoNavigationController() diff --git a/ListableUI.podspec b/ListableUI.podspec index 3f28e9433..0622963e2 100644 --- a/ListableUI.podspec +++ b/ListableUI.podspec @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.swift_versions = [LISTABLE_SWIFT_VERSION] - s.source_files = 'ListableUI/Sources/**/*.{swift,h,m}' + s.source_files = 'ListableUI/Sources/**/*.swift' s.resource_bundle = { 'ListableUIResources' => 'ListableUI/Resources/**/*' } s.weak_framework = 'SwiftUI' @@ -27,7 +27,7 @@ Pod::Spec.new do |s| # These tests can only be run locally, because they depend on local pods. s.test_spec 'Tests' do |test_spec| - test_spec.source_files = 'ListableUI/Tests/**/*.{swift}' + test_spec.source_files = 'ListableUI/Tests/**/*.swift' test_spec.ios.resource_bundle = { 'ListableUITestsResources' => 'ListableUI/Tests/Resources/**/*.*' } test_spec.framework = 'XCTest' diff --git a/ListableUI/Sources/KeyboardObserver/KeyboardObserver.swift b/ListableUI/Sources/KeyboardObserver/KeyboardObserver.swift index a49d5ddda..ae7f7edb9 100644 --- a/ListableUI/Sources/KeyboardObserver/KeyboardObserver.swift +++ b/ListableUI/Sources/KeyboardObserver/KeyboardObserver.swift @@ -297,10 +297,13 @@ extension KeyboardObserver { print( """ - LISTABLE WARNING: The shared instance of the `KeyboardObserver` was not instantiated - during app startup. While not fatal, this could result in a list being created - that does not properly position itself to account for the keyboard, if the list is created + LISTABLE WARNING: The shared instance of the `KeyboardObserver` was not instantiated \ + during app startup. While not fatal, this could result in a list being created \ + that does not properly position itself to account for the keyboard, if the list is created \ while the keyboard is already visible. + + Please ensure you invoke `ListView.configure(with: application)` before the first `ListView` \ + is placed on screen to ensure proper keyboard handling. """ ) } diff --git a/ListableUI/Sources/KeyboardObserver/SetupKeyboardObserverOnAppStartup.m b/ListableUI/Sources/KeyboardObserver/SetupKeyboardObserverOnAppStartup.m deleted file mode 100644 index 5abce4c74..000000000 --- a/ListableUI/Sources/KeyboardObserver/SetupKeyboardObserverOnAppStartup.m +++ /dev/null @@ -1,66 +0,0 @@ -// -// SetupKeyboardObserverOnAppStartup.m -// ListableUI -// -// Created by Kyle Van Essen on 8/24/20. -// - -@import Foundation; -@import UIKit; - -#if __has_include () - #import -#elif __has_include ("ListableUI-Swift.h") - #import "ListableUI-Swift.h" -#endif - - -@interface __LST_SetupKeyboardObserverOnAppStartup : NSObject -@end - - -@implementation __LST_SetupKeyboardObserverOnAppStartup - -/// Register for `applicationDidFinishLaunching`, so we can set up -/// our keyboard observer to always know when the keyboard is visible. -/// Yes, I know, and I am sorry. -+ (void)load { - if (self != __LST_SetupKeyboardObserverOnAppStartup.class) { - return; - } - - [self sharedInstance]; -} - -+ (instancetype)sharedInstance; -{ - static __LST_SetupKeyboardObserverOnAppStartup *loader = nil; - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - loader = [[__LST_SetupKeyboardObserverOnAppStartup alloc] init]; - }); - - return loader; -} - -- (instancetype)init; -{ - self = [super init]; - NSParameterAssert(self); - - [NSNotificationCenter.defaultCenter addObserver:self - selector:@selector(applicationDidFinishLaunchingNotification) - name:UIApplicationDidFinishLaunchingNotification - object:nil]; - - return self; -} - -- (void)applicationDidFinishLaunchingNotification NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead."); -{ - /// Application has now finished launching, so set up the keyboard - [ListView configureWithApplication:UIApplication.sharedApplication]; -} - -@end diff --git a/Package.swift b/Package.swift index 701ff6352..1bafeb23d 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,6 @@ let package = Package( name: "ListableUI", path: "ListableUI", exclude: [ - "Sources/KeyboardObserver/SetupKeyboardObserverOnAppStartup.m", "Sources/Layout/Paged/PagedAppearance.monopic", "Sources/ContentBounds/ListContentBounds.monopic", "Sources/Layout/Table/TableAppearance.monopic", diff --git a/Podfile.lock b/Podfile.lock index ca33e8d1a..3910dbbf4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -46,9 +46,9 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BlueprintUI: 1818f187a6be6c69266a4e30f03a6ad7755530e9 BlueprintUICommonControls: 6ceffc16822dea3d1910029aa87eed7a386e4e3b - BlueprintUILists: 799f21a75c76968f84ab768dcba0950ff53e23f8 + BlueprintUILists: 5b96041d96e22a3f7d26398ae402f43124ba74da EnglishDictionary: 2cf40d33cc1b68c4152a1cc69561aaf6e4ba0209 - ListableUI: 04974e3cc04a2df7f93242b489431ea86e69329b + ListableUI: 5a583f04682acba8b773416d19dcba2f4bdb4404 Snapshot: 574e65b08c02491a541efbd2619c92cc26514d1c PODFILE CHECKSUM: 2b979d4f2436d28af7c87b125b646836119b89b7