@@ -6,8 +6,8 @@ import AirshipFrameworkProxy
66import React
77
88@objc
9- public class AirshipReactNative : NSObject {
10-
9+ public final class AirshipReactNative : NSObject , Sendable {
10+
1111 @objc
1212 public static let pendingEventsEventName = " com.airship.pending_events "
1313
@@ -18,19 +18,16 @@ public class AirshipReactNative: NSObject {
1818 public static let pendingEmbeddedUpdated = " com.airship.iax.pending_embedded_updated "
1919
2020 private let serialQueue = AirshipAsyncSerialQueue ( )
21- var lock = AirshipLock ( )
22- var pendingPresentationRequests : [ String : PresentationOptionsOverridesRequest ] = [ : ]
23-
21+ private let _pendingPresentationRequests = AirshipAtomicValue < [ String : PresentationOptionsOverridesRequest ] > ( [ : ] )
22+ private let _overridePresentationOptionsEnabled = AirshipAtomicValue < Bool > ( false )
23+
2424 @objc
25- public var overridePresentationOptionsEnabled : Bool = false {
26- didSet {
27- if ( !overridePresentationOptionsEnabled) {
28- lock. sync {
29- self . pendingPresentationRequests. values. forEach { request in
30- request. result ( options: nil )
31- }
32- self . pendingPresentationRequests. removeAll ( )
33- }
25+ public var overridePresentationOptionsEnabled : Bool {
26+ get { _overridePresentationOptionsEnabled. value }
27+ set {
28+ _overridePresentationOptionsEnabled. value = newValue
29+ if ( !newValue) {
30+ self . clearPendingPresentationRequests ( )
3431 }
3532 }
3633 }
@@ -48,10 +45,11 @@ public class AirshipReactNative: NSObject {
4845
4946 @objc
5047 public func setNotifier( _ notifier: ( ( String , [ String : Any ] ) -> Void ) ? ) {
48+ let wrappedNotifier = AirshipUnsafeSendableWrapper ( notifier)
5149 self . serialQueue. enqueue { @MainActor in
52- if let notifier = notifier {
50+ if wrappedNotifier . value != nil {
5351 await self . eventNotifier. setNotifier {
54- notifier ( AirshipReactNative . pendingEventsEventName, [ : ] )
52+ wrappedNotifier . value ? ( AirshipReactNative . pendingEventsEventName, [ : ] )
5553 }
5654
5755 if AirshipProxyEventEmitter . shared. hasAnyEvents ( ) {
@@ -76,10 +74,13 @@ public class AirshipReactNative: NSObject {
7674 }
7775
7876 let requestID = UUID ( ) . uuidString
79- self . lock. sync {
80- self . pendingPresentationRequests [ requestID] = request
77+ self . _pendingPresentationRequests. update {
78+ var requests = $0
79+ requests [ requestID] = request
80+ return requests
8181 }
82- notifier (
82+
83+ wrappedNotifier. value ? (
8384 AirshipReactNative . overridePresentationOptionsEventName,
8485 [
8586 " pushPayload " : requestPayload,
@@ -90,25 +91,29 @@ public class AirshipReactNative: NSObject {
9091 } else {
9192 await self . eventNotifier. setNotifier ( nil )
9293 AirshipProxy . shared. push. presentationOptionOverrides = nil
93-
94- self . lock. sync {
95- self . pendingPresentationRequests. values. forEach { request in
96- request. result ( options: nil )
97- }
98- self . pendingPresentationRequests. removeAll ( )
99- }
94+ self . clearPendingPresentationRequests ( )
10095 }
10196 }
10297 }
10398
10499 @objc
105100 public func presentationOptionOverridesResult( requestID: String , presentationOptions: [ String ] ? ) {
106- lock. sync {
107- pendingPresentationRequests [ requestID] ? . result ( optionNames: presentationOptions)
108- pendingPresentationRequests [ requestID] = nil
101+ _pendingPresentationRequests. update {
102+ var requests = $0
103+ requests [ requestID] ? . result ( optionNames: presentationOptions)
104+ requests [ requestID] = nil
105+ return requests
106+ }
107+ }
108+
109+ private func clearPendingPresentationRequests( ) {
110+ _pendingPresentationRequests. update { requests in
111+ requests. values. forEach { request in
112+ request. result ( options: nil )
113+ }
114+ return [ : ]
109115 }
110116 }
111-
112117
113118 @MainActor
114119 func onLoad( ) {
@@ -767,8 +772,8 @@ extension AirshipReactNative: AirshipProxyDelegate {
767772
768773
769774private actor EventNotifier {
770- private var notifier : ( ( ) -> Void ) ?
771- func setNotifier( _ notifier: ( ( ) -> Void ) ? ) {
775+ private var notifier : ( @ Sendable ( ) -> Void ) ?
776+ func setNotifier( _ notifier: ( @ Sendable ( ) -> Void ) ? ) {
772777 self . notifier = notifier
773778 }
774779
0 commit comments