react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
customData in track event crash if it's not string
Definition
The type for customData
is set to AnyDataType
(Ref:https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/blob/master/src/index.d.ts#L74),
type AnyDataType =
| string
| boolean
| number
| null
| undefined
| AnyDataArray
| AnyDataObject;
However using anything other than string will cause the app to crash in Android. You can observe the following error in native log
Exception in native call
com.facebook.react.bridge.UnexpectedNativeTypeException: Value for fb_success cannot be cast from Double to String
at com.facebook.react.bridge.ReadableNativeMap.checkInstance(ReadableNativeMap.java:140)
at com.facebook.react.bridge.ReadableNativeMap.getNullableValue(ReadableNativeMap.java:128)
at com.facebook.react.bridge.ReadableNativeMap.getString(ReadableNativeMap.java:162)
at io.branch.rnbranch.RNBranchModule.createBranchEvent(RNBranchModule.java:710)
at io.branch.rnbranch.RNBranchModule.logEvent(RNBranchModule.java:479)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Reproducible code
new BranchEvent(BranchEvent.Search, undefined, {
customData: {
fb_success: 0,
},
}).logEvent();
Cause
The reason it's throwing crash is because the native module always query it as string ( Ref: https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/blob/master/android/src/main/java/io/branch/rnbranch/RNBranchModule.java#L705-L712)
if (params.hasKey("customData")) {
ReadableMap customData = params.getMap("customData");
ReadableMapKeySetIterator it = customData.keySetIterator();
while (it.hasNextKey()) {
String key = it.nextKey();
event.addCustomDataProperty(key, customData.getString(key)); //culprit here
}
}
Expected
- Either make the type in typescript strictly string
- OR Native module to query correct type (You can use
getType
then query differentgetXY
depending on the returned type enum`
Thanks for reporting this. We'll track the work for a proper design as you suggested.