Skip to content

Commit 396eeee

Browse files
authored
Refactor FXIOS-14339 ⁃ LegacyTabScrollController should use Notifiable protocol (#31150)
* FXIOS-14339 #31068 ⁃ LegacyTabScrollController should use Notifiable protocol * Listen to willTerminateNotification
1 parent b7362bb commit 396eeee

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

firefox-ios/Client/Frontend/Browser/TabScrollController/LegacyTabScrollController.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ protocol LegacyTabScrollProvider: TabScrollHandlerProtocol {
2626
@MainActor
2727
final class LegacyTabScrollController: NSObject,
2828
SearchBarLocationProvider,
29-
LegacyTabScrollProvider {
29+
LegacyTabScrollProvider,
30+
Notifiable {
3031
private struct UX {
3132
static let abruptScrollEventOffset: CGFloat = 200
3233
static let toolbarBaseAnimationDuration: CGFloat = 0.2
@@ -262,10 +263,13 @@ final class LegacyTabScrollController: NSObject,
262263
}
263264

264265
private func setupNotifications() {
265-
NotificationCenter.default.addObserver(self,
266-
selector: #selector(applicationWillTerminate(_:)),
267-
name: UIApplication.willTerminateNotification,
268-
object: nil)
266+
startObservingNotifications(
267+
withNotificationCenter: NotificationCenter.default,
268+
forObserver: self,
269+
observing: [
270+
UIApplication.willTerminateNotification
271+
]
272+
)
269273
}
270274

271275
func configureToolbarViews(overKeyboardContainer: BaseAlphaStackView?,
@@ -292,8 +296,7 @@ final class LegacyTabScrollController: NSObject,
292296
}
293297
}
294298

295-
@objc
296-
private func applicationWillTerminate(_ notification: Notification) {
299+
private func applicationWillTerminate() {
297300
// Ensures that we immediately de-register KVO observations for content size changes in
298301
// webviews if the app is about to terminate.
299302
observedScrollViews.forEach({ stopObserving(scrollView: $0) })
@@ -447,6 +450,19 @@ final class LegacyTabScrollController: NSObject,
447450
self?.reload()
448451
}
449452
}
453+
454+
// MARK: - Notifiable
455+
456+
public func handleNotifications(_ notification: Notification) {
457+
switch notification.name {
458+
case UIApplication.willTerminateNotification:
459+
ensureMainThread {
460+
self.applicationWillTerminate
461+
}
462+
default:
463+
return
464+
}
465+
}
450466
}
451467

452468
// MARK: - Private

0 commit comments

Comments
 (0)