Skip to content
Open
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
25 changes: 18 additions & 7 deletions ios/CarouselInAppContentBlockViewProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,19 @@ public class CarouselInAppContentBlockViewProxy: UIView, DefaultContentBlockCaro
}

private func notifyDimensChanged(width: CGFloat, height: CGFloat) {
eventEmitter?.emitDimensChanged(
width: Double(width),
height: Double(height)
)
onMain { [weak self] in
self?.eventEmitter?.emitDimensChanged(
width: Double(width),
height: Double(height)
)
}
}

private func notifyContentBlockCarouselEvent(_ event: ContentBlockCarouselEvent) {
eventEmitter?.emitContentBlockEvent(data: event.toDictionary() as NSDictionary)
let data = event.toDictionary() as NSDictionary
onMain { [weak self] in
self?.eventEmitter?.emitContentBlockEvent(data: data)
}
}

private func notifyContentFilterRequest(input: [ExponeaSDK.InAppContentBlockResponse]) {
Expand All @@ -274,7 +279,10 @@ public class CarouselInAppContentBlockViewProxy: UIView, DefaultContentBlockCaro
return
}

eventEmitter?.emitDataRequest(data: ["requestType": "filter", "data": jsonString] as NSDictionary)
let payload: NSDictionary = ["requestType": "filter", "data": jsonString]
onMain { [weak self] in
self?.eventEmitter?.emitDataRequest(data: payload)
}
}

private func notifyContentSortRequest(input: [ExponeaSDK.InAppContentBlockResponse]) {
Expand All @@ -293,6 +301,9 @@ public class CarouselInAppContentBlockViewProxy: UIView, DefaultContentBlockCaro
return
}

eventEmitter?.emitDataRequest(data: ["requestType": "sort", "data": jsonString] as NSDictionary)
let payload: NSDictionary = ["requestType": "sort", "data": jsonString]
onMain { [weak self] in
self?.eventEmitter?.emitDataRequest(data: payload)
}
}
}
8 changes: 8 additions & 0 deletions ios/DictionaryExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import Foundation

func onMain(_ block: @escaping () -> Void) {
if Thread.isMainThread {
block()
} else {
DispatchQueue.main.async(execute: block)
}
}

/// Error types for Exponea configuration
public enum ExponeaDataError: Error {
case invalidType(for: String)
Expand Down
5 changes: 3 additions & 2 deletions ios/ExponeaBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,9 @@ public class ExponeaRNVersion: NSObject, ExponeaVersionProvider {
}

private func sendEventToJS(name: String, body: Any?) {
// Use RCTEventEmitter to send events to JavaScript
eventEmitter?.sendEvent(withName: name, body: body)
onMain { [weak self] in
self?.eventEmitter?.sendEvent(withName: name, body: body)
}
}

private func convertToJSONString(_ dict: [AnyHashable: Any]) throws -> String {
Expand Down
15 changes: 10 additions & 5 deletions ios/InAppContentBlocksPlaceholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public class InAppContentBlocksPlaceholder: UIView, InAppContentBlockCallbackTyp
}

private func notifyDimensChanged(width: CGFloat, height: CGFloat) {
eventEmitter?.emitDimensChanged(
width: Double(width),
height: Double(height)
)
onMain { [weak self] in
self?.eventEmitter?.emitDimensChanged(
width: Double(width),
height: Double(height)
)
}
}

private func notifyInAppContentBlockEvent(
Expand Down Expand Up @@ -137,7 +139,10 @@ public class InAppContentBlocksPlaceholder: UIView, InAppContentBlockCallbackTyp
data["errorMessage"] = errorMessage
}

eventEmitter?.emitContentBlockEvent(data: data as NSDictionary)
let eventData = data as NSDictionary
onMain { [weak self] in
self?.eventEmitter?.emitContentBlockEvent(data: eventData)
}
}

public func onMessageShown(placeholderId: String, contentBlock: ExponeaSDK.InAppContentBlockResponse) {
Expand Down