-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification when
registerBridgeComponents
is called
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// HotwireNotifications.swift | ||
// HotwireNative | ||
// | ||
// Created by Fernando Olivares on 20/10/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
extension NSNotification.Name { | ||
static let didRegisterBridgeComponents = NSNotification.Name("HotwireNativeDidRegisterBridgeComponents") | ||
} | ||
|
||
extension NotificationCenter { | ||
func removeObservation(_ observationToken: NSObjectProtocol?) { | ||
guard let observationToken else { return } | ||
removeObserver(observationToken) | ||
} | ||
|
||
func removeObservations(_ observationTokens: [NSObjectProtocol?]) { | ||
for observationToken in observationTokens.compactMap({ $0 }) { | ||
removeObserver(observationToken) | ||
} | ||
} | ||
} | ||
|
||
extension NotificationCenter { | ||
|
||
func postDidRegisterBridgeComponents() { | ||
post(name: .didRegisterBridgeComponents, object: nil) | ||
} | ||
|
||
func observeDidRegisterBridgeComponents(reaction: @escaping () -> Void) -> NSObjectProtocol { | ||
addObserver(forName: .didRegisterBridgeComponents, object: nil, queue: .main) { _ in | ||
reaction() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters