Skip to content

Commit 7def449

Browse files
committed
fix: React Native Codegen issue with version 0.84
`NativeMParticle.ts (line 6) uses TSArrayType shorthand (string[]) which is unsupported by the React Native codegen` Removed the null type in the map - In RNMParticle.mm, added sanitization for user attributes to exclude null values before returning them in the callback. - Updated TypeScript definitions to reflect the changes in callback result types.
1 parent d9db901 commit 7def449

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

android/src/main/java/com/mparticle/react/MParticleModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class MParticleModule(
179179
},
180180
)
181181
} else {
182-
callback.invoke()
182+
callback.invoke(null, WritableNativeMap())
183183
}
184184
}
185185

ios/RNMParticle/RNMParticle.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ + (void)load {
163163
{
164164
MParticleUser *selectedUser = [[MParticleUser alloc] init];
165165
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
166-
callback(@[[NSNull null], [selectedUser userAttributes]]);
166+
NSDictionary *attributes = [selectedUser userAttributes] ?: @{};
167+
NSMutableDictionary *sanitizedAttributes = [[NSMutableDictionary alloc] initWithCapacity:attributes.count];
168+
[attributes enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
169+
if (obj != nil && obj != [NSNull null]) {
170+
sanitizedAttributes[key] = obj;
171+
}
172+
}];
173+
callback(@[[NSNull null], sanitizedAttributes]);
167174
}
168175

169176
RCT_EXPORT_METHOD(setUserTag:(NSString *)mpid tag:(NSString *)tag)

js/codegenSpecs/NativeMParticle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TurboModuleRegistry } from 'react-native';
33

44
export type CustomAttributes = { [key: string]: string | number | boolean };
55
export type UserAttributes = {
6-
[key: string]: string | string[] | number | boolean | null;
6+
[key: string]: string | string[] | number | boolean;
77
};
88
export type UserIdentities = { [key: string]: string };
99

@@ -153,7 +153,7 @@ export interface Spec extends TurboModule {
153153
mpid: string,
154154
callback: (
155155
error: CallbackError | null,
156-
result: UserAttributes | null
156+
result: UserAttributes
157157
) => void
158158
): void;
159159
setUserTag(mpid: string, tag: string): void;

0 commit comments

Comments
 (0)