Skip to content

Commit 33dd0be

Browse files
authored
Merge pull request #557 from urbanairship/MOBILE-4239
[MOBILE-4239] Fix Airship Actions running
2 parents f5676a2 + fbdb400 commit 33dd0be

File tree

10 files changed

+106
-33
lines changed

10 files changed

+106
-33
lines changed

android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,16 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
455455
}
456456

457457
@ReactMethod
458-
override fun actionRun(name: String?, value: ReadableMap?, promise: Promise) {
458+
override fun addCustomEvent(event: ReadableMap?, promise: Promise) {
459+
promise.resolveResult {
460+
proxy.analytics.addEvent(Utils.convertMap(event).toJsonValue())
461+
}
462+
}
463+
464+
@ReactMethod
465+
override fun actionRun(action: ReadableMap, promise: Promise) {
459466
promise.resolveDeferred<ActionValue> { callback ->
460-
proxy.actions.runAction(requireNotNull(name), Utils.convertMap(value).toJsonValue())
467+
proxy.actions.runAction(requireNotNull(action.getString("name")), Utils.convertDynamic(action.getDynamic("value")))
461468
.addResultCallback { actionResult ->
462469
if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) {
463470
callback(actionResult.value, null)

android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,17 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext
237237
promise: Promise
238238
)
239239

240+
@ReactMethod
241+
@com.facebook.proguard.annotations.DoNotStrip
242+
abstract fun addCustomEvent(
243+
event: ReadableMap?,
244+
promise: Promise
245+
)
246+
240247
@ReactMethod
241248
@com.facebook.proguard.annotations.DoNotStrip
242249
abstract fun actionRun(
243-
name: String?,
244-
value: ReadableMap?,
250+
action: ReadableMap,
245251
promise: Promise
246252
)
247253

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ PODS:
964964
- React-Mapbuffer (0.73.4):
965965
- glog
966966
- React-debug
967-
- react-native-airship (17.2.0):
967+
- react-native-airship (17.2.1):
968968
- AirshipFrameworkProxy (= 5.1.1)
969969
- glog
970970
- RCT-Folly (= 2022.05.16.00)
@@ -1407,7 +1407,7 @@ SPEC CHECKSUMS:
14071407
React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460
14081408
React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab
14091409
React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad
1410-
react-native-airship: ba50cd2630247d4896f65d6aeb9d7e94ec93ee08
1410+
react-native-airship: 876b0976076f1f85a8dc3722669db2702accfe68
14111411
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
14121412
React-nativeconfig: d7af5bae6da70fa15ce44f045621cf99ed24087c
14131413
React-NativeModulesApple: 0123905d5699853ac68519607555a9a4f5c7b3ac

ios/AirshipReactNative.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,14 @@ public extension AirshipReactNative {
328328
// Actions
329329
@objc
330330
public extension AirshipReactNative {
331-
func actionsRun(actionName: String, actionValue: Any?) async throws-> Any? {
331+
func actionsRun(action: [String: Any]) async throws-> Any? {
332+
guard let name = action["name"] as? String else {
333+
throw AirshipErrors.error("missing name")
334+
}
335+
332336
return try await AirshipProxy.shared.action.runAction(
333-
actionName,
334-
value: try AirshipJSON.wrap(actionValue)
337+
name,
338+
value: action["value"] is NSNull ? nil : try AirshipJSON.wrap(action["value"])
335339
)
336340
}
337341
}
@@ -350,6 +354,10 @@ public extension AirshipReactNative {
350354
key: key
351355
)
352356
}
357+
358+
func addCustomEvent(_ json: Any) throws {
359+
try AirshipProxy.shared.analytics.addEvent(json)
360+
}
353361
}
354362

355363
// Contact

ios/RTNAirship.mm

+13-3
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,10 @@ + (BOOL)requiresMainQueueSetup {
336336
}
337337

338338
RCT_REMAP_METHOD(actionRun,
339-
actionRun:(NSString *)name value:(NSDictionary *)value
339+
actionRun:(NSDictionary *)action
340340
resolve:(RCTPromiseResolveBlock)resolve
341341
reject:(RCTPromiseRejectBlock)reject) {
342-
[AirshipReactNative.shared actionsRunWithActionName:name
343-
actionValue:value
342+
[AirshipReactNative.shared actionsRunWithAction:action
344343
completionHandler:^(id result , NSError *error) {
345344

346345

@@ -375,6 +374,17 @@ + (BOOL)requiresMainQueueSetup {
375374
[self handleResult:nil error:error resolve:resolve reject:reject];
376375
}
377376

377+
RCT_REMAP_METHOD(addCustomEvent,
378+
addCustomEvent:(NSDictionary *)event
379+
resolve:(RCTPromiseResolveBlock)resolve
380+
reject:(RCTPromiseRejectBlock)reject) {
381+
NSError *error;
382+
[AirshipReactNative.shared addCustomEvent:event
383+
error:&error];
384+
385+
[self handleResult:nil error:error resolve:resolve reject:reject];
386+
}
387+
378388
RCT_REMAP_METHOD(contactEditAttributes,
379389
contactEditAttributes:(NSArray *)operations
380390
resolve:(RCTPromiseResolveBlock)resolve

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AirshipActions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ export class AirshipActions {
99
/**
1010
* Runs an Airship action.
1111
*
12-
* @param name The name of the action.
13-
* @param value The action's value.
12+
* @param actionName The name of the action.
13+
* @param actionValue The action's value.
1414
* @return A promise that returns the action result if the action
1515
* successfully runs, or the Error if the action was unable to be run.
1616
*/
1717
public run(
1818
actionName: string,
1919
actionValue?: JsonValue
2020
): Promise<JsonValue | null | undefined> {
21-
return this.module.actionRun(actionName, actionValue);
21+
return this.module.actionRun({name: actionName, value: actionValue});
2222
}
2323
}

src/AirshipAnalytics.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,7 @@ export class AirshipAnalytics {
3232
* @return A promise that returns null if resolved, or an Error if the
3333
* custom event is rejected.
3434
*/
35-
public addCustomEvent(event: CustomEvent): Promise<null | Error> {
36-
const actionArg = {
37-
event_name: event._name,
38-
event_value: event._value,
39-
transaction_id: event._transactionId,
40-
properties: event._properties
41-
}
42-
43-
return new Promise((resolve, reject) => {
44-
this.module.actionRun("add_custom_event_action", actionArg).then(() => {
45-
resolve(null)
46-
}, (error: Error) => {
47-
reject(error)
48-
})
49-
})
35+
public addCustomEvent(event: CustomEvent): Promise<void> {
36+
return this.module.addCustomEvent(event.toJsonValue());
5037
}
5138
}

src/CustomEvent.ts

+54
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export class CustomEvent {
1212
_value?: number;
1313
_properties: JsonObject;
1414
_transactionId?: string;
15+
_interactionId?: string;
16+
_interactionType?: string;
1517

1618
/**
1719
* Custom event constructor.
@@ -39,6 +41,34 @@ export class CustomEvent {
3941
this._transactionId = value;
4042
}
4143

44+
/**
45+
* Gets the event's interaction ID.
46+
*/
47+
get interactionId(): string | undefined {
48+
return this._interactionId;
49+
}
50+
51+
/**
52+
* Sets the event's interaction ID.
53+
*/
54+
set interactionId(value: string | undefined) {
55+
this._interactionId = value;
56+
}
57+
58+
/**
59+
* Gets the event's interaction Type.
60+
*/
61+
get interactionType(): string | undefined {
62+
return this._interactionType;
63+
}
64+
65+
/**
66+
* Sets the event's interaction Type.
67+
*/
68+
set interactionType(value: string | undefined) {
69+
this._interactionType = value;
70+
}
71+
4272
/**
4373
* Adds a property to the custom event.
4474
*
@@ -48,4 +78,28 @@ export class CustomEvent {
4878
addProperty(name: string, value: JsonValue) {
4979
this._properties[name] = value;
5080
}
81+
82+
/**
83+
* Converts a CustomEvent into a JsonValue.
84+
*
85+
* @returns A JsonValue.
86+
*/
87+
toJsonValue(): JsonValue {
88+
let jsonObject: JsonObject = {};
89+
jsonObject.eventName = this._name;
90+
if (this._value) {
91+
jsonObject.eventValue = this._value;
92+
}
93+
jsonObject.properties = this._properties;
94+
if (this._transactionId) {
95+
jsonObject.transactionId = this._transactionId;
96+
}
97+
if (this._interactionId) {
98+
jsonObject.interactionId = this._interactionId;
99+
}
100+
if (this._interactionType) {
101+
jsonObject.interactionType = this._interactionType;
102+
}
103+
return jsonObject;
104+
}
51105
}

src/NativeRTNAirship.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ export interface Spec extends TurboModule {
6666
// Analytics
6767
analyticsTrackScreen(screen?: string): Promise<void>;
6868
analyticsAssociateIdentifier(key: string, identifier?: string): Promise<void>;
69+
addCustomEvent(event: Object): Promise<void>;
6970

7071
// Action
71-
actionRun(name: string, value?: Object): Promise<Object | Error>;
72+
actionRun(action: Object): Promise<Object | Error>;
7273

7374
// Privacy Manager
7475
privacyManagerSetEnabledFeatures(features: string[]): Promise<void>;

0 commit comments

Comments
 (0)