Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/AirshipPluginLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import AirshipFrameworkProxy

@objc(AirshipPluginLoader)
@MainActor
public class AirshipPluginLoader: NSObject, AirshipPluginLoaderProtocol {
@objc
public static var disabled: Bool = false

public static func onLoad() {
if (!disabled) {
AirshipReactNative.shared.onLoad()
Expand Down
69 changes: 37 additions & 32 deletions ios/AirshipReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import AirshipFrameworkProxy
import React

@objc
public class AirshipReactNative: NSObject {
public final class AirshipReactNative: NSObject, Sendable {

@objc
public static let pendingEventsEventName = "com.airship.pending_events"

Expand All @@ -18,19 +18,16 @@ public class AirshipReactNative: NSObject {
public static let pendingEmbeddedUpdated = "com.airship.iax.pending_embedded_updated"

private let serialQueue = AirshipAsyncSerialQueue()
var lock = AirshipLock()
var pendingPresentationRequests: [String: PresentationOptionsOverridesRequest] = [:]
private let _pendingPresentationRequests = AirshipAtomicValue<[String: PresentationOptionsOverridesRequest]>([:])
private let _overridePresentationOptionsEnabled = AirshipAtomicValue<Bool>(false)

@objc
public var overridePresentationOptionsEnabled: Bool = false {
didSet {
if (!overridePresentationOptionsEnabled) {
lock.sync {
self.pendingPresentationRequests.values.forEach { request in
request.result(options: nil)
}
self.pendingPresentationRequests.removeAll()
}
public var overridePresentationOptionsEnabled: Bool {
get { _overridePresentationOptionsEnabled.value }
set {
_overridePresentationOptionsEnabled.value = newValue
if (!newValue) {
self.clearPendingPresentationRequests()
}
}
}
Expand All @@ -48,10 +45,11 @@ public class AirshipReactNative: NSObject {

@objc
public func setNotifier(_ notifier: ((String, [String: Any]) -> Void)?) {
let wrappedNotifier = AirshipUnsafeSendableWrapper(notifier)
self.serialQueue.enqueue { @MainActor in
if let notifier = notifier {
if wrappedNotifier.value != nil {
await self.eventNotifier.setNotifier {
notifier(AirshipReactNative.pendingEventsEventName, [:])
wrappedNotifier.value?(AirshipReactNative.pendingEventsEventName, [:])
}

if AirshipProxyEventEmitter.shared.hasAnyEvents() {
Expand All @@ -76,10 +74,13 @@ public class AirshipReactNative: NSObject {
}

let requestID = UUID().uuidString
self.lock.sync {
self.pendingPresentationRequests[requestID] = request
self._pendingPresentationRequests.update {
var requests = $0
requests[requestID] = request
return requests
}
notifier(

wrappedNotifier.value?(
AirshipReactNative.overridePresentationOptionsEventName,
[
"pushPayload": requestPayload,
Expand All @@ -90,25 +91,29 @@ public class AirshipReactNative: NSObject {
} else {
await self.eventNotifier.setNotifier(nil)
AirshipProxy.shared.push.presentationOptionOverrides = nil

self.lock.sync {
self.pendingPresentationRequests.values.forEach { request in
request.result(options: nil)
}
self.pendingPresentationRequests.removeAll()
}
self.clearPendingPresentationRequests()
}
}
}

@objc
public func presentationOptionOverridesResult(requestID: String, presentationOptions: [String]?) {
lock.sync {
pendingPresentationRequests[requestID]?.result(optionNames: presentationOptions)
pendingPresentationRequests[requestID] = nil
_pendingPresentationRequests.update {
var requests = $0
requests[requestID]?.result(optionNames: presentationOptions)
requests[requestID] = nil
return requests
}
}

private func clearPendingPresentationRequests() {
_pendingPresentationRequests.update { requests in
requests.values.forEach { request in
request.result(options: nil)
}
return [:]
}
}


@MainActor
func onLoad() {
Expand Down Expand Up @@ -767,8 +772,8 @@ extension AirshipReactNative: AirshipProxyDelegate {


private actor EventNotifier {
private var notifier: (() -> Void)?
func setNotifier(_ notifier: (() -> Void)?) {
private var notifier: (@Sendable () -> Void)?
func setNotifier(_ notifier: (@Sendable () -> Void)?) {
self.notifier = notifier
}

Expand Down
6 changes: 2 additions & 4 deletions ios/MessageWebViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public protocol MessageWebViewWrapperDelegate {
}

@objc(RNAirshipMessageWebViewWrapper)
@MainActor
public class MessageWebViewWrapper: NSObject {
private let innerWrapper: _MessageWebViewWrapper

Expand All @@ -36,7 +37,6 @@ public class MessageWebViewWrapper: NSObject {
}
}

@MainActor
@objc
public func loadMessage(messageID: String?) {
self.innerWrapper.loadMessage(messageID: messageID)
Expand All @@ -49,7 +49,7 @@ public class MessageWebViewWrapper: NSObject {
}


class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, NativeBridgeDelegate {
class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, @preconcurrency NativeBridgeDelegate {

public weak var delegate: MessageWebViewWrapperDelegate? = nil

Expand Down Expand Up @@ -93,8 +93,6 @@ class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, NativeBridg
}
}



@MainActor
private func startLoad(messageID: String) async {
var message: MessageCenterMessage? = nil
Expand Down
1 change: 1 addition & 0 deletions react-native-airship.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
s.exclude_files = "ios/generated/**/*"
s.private_header_files = "ios/**/*.h"
s.swift_version = "6.0"

install_modules_dependencies(s)

Expand Down