@@ -174,6 +174,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
174
174
configureNavigationButtons ( )
175
175
176
176
configureInitialFilterIfNeeded ( )
177
+ listenForAppComingToForeground ( )
177
178
178
179
createButtonCoordinator. add ( to: view, trailingAnchor: view. safeAreaLayoutGuide. trailingAnchor, bottomAnchor: view. safeAreaLayoutGuide. bottomAnchor)
179
180
}
@@ -212,6 +213,12 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
212
213
213
214
override func traitCollectionDidChange( _ previousTraitCollection: UITraitCollection ? ) {
214
215
super. traitCollectionDidChange ( previousTraitCollection)
216
+ toggleCreateButton ( )
217
+ }
218
+
219
+ /// Shows/hides the create button based on the trait collection horizontal size class
220
+ @objc
221
+ private func toggleCreateButton( ) {
215
222
if traitCollection. horizontalSizeClass == . compact {
216
223
createButtonCoordinator. showCreateButton ( for: blog)
217
224
} else {
@@ -379,6 +386,13 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
379
386
filterSettings. setFilterWithPostStatus ( initialFilterWithPostStatus)
380
387
}
381
388
389
+ /// Listens for the app coming to foreground in order to properly set the create button
390
+ private func listenForAppComingToForeground( ) {
391
+ NotificationCenter . default. addObserver ( self ,
392
+ selector: #selector( toggleCreateButton) ,
393
+ name: UIApplication . willEnterForegroundNotification,
394
+ object: nil )
395
+ }
382
396
// Mark - Layout Methods
383
397
384
398
override func willTransition( to newCollection: UITraitCollection , with coordinator: UIViewControllerTransitionCoordinator ) {
0 commit comments