Skip to content

Commit ead57d5

Browse files
committed
feat: enable auto masking screenshots in RN
1 parent 0523b05 commit ead57d5

File tree

13 files changed

+97
-3
lines changed

13 files changed

+97
-3
lines changed

android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition;
1818
import com.instabug.library.sessionreplay.model.SessionMetadata;
1919
import com.instabug.library.ui.onboarding.WelcomeMessage;
20+
import com.instabug.library.MaskingType;
2021

2122
import java.util.ArrayList;
2223
import java.util.HashMap;
@@ -60,6 +61,7 @@ static Map<String, Object> getAll() {
6061
putAll(locales);
6162
putAll(placeholders);
6263
putAll(launchType);
64+
putAll(autoMaskingTypes);
6365
}};
6466
}
6567

@@ -253,5 +255,10 @@ static Map<String, Object> getAll() {
253255
put(SessionMetadata.LaunchType.COLD,"cold");
254256
put(SessionMetadata.LaunchType.WARM,"warm" );
255257
}};
256-
258+
public static final ArgsMap<Integer> autoMaskingTypes = new ArgsMap<Integer>() {{
259+
put("labels", MaskingType.LABELS);
260+
put("textInputs", MaskingType.TEXT_INPUTS);
261+
put("media", MaskingType.MEDIA);
262+
put("none", MaskingType.MASK_NOTHING);
263+
}};
257264
}

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,4 +1274,21 @@ public Map<String, Object> getConstants() {
12741274

12751275
return constants;
12761276
}
1277+
/**
1278+
* Sets the auto mask screenshots types.
1279+
* @param autoMaskingTypes The masking type to be applied.
1280+
*/
1281+
@ReactMethod
1282+
public void enableAutoMasking(@NonNull ReadableArray autoMaskingTypes) {
1283+
int[] autoMassingTypesArray = new int[autoMaskingTypes.size()];
1284+
for (int i=0;i< autoMaskingTypes.size();i++)
1285+
{
1286+
String key = autoMaskingTypes.getString(i);
1287+
1288+
autoMassingTypesArray[i]= ArgsRegistry.autoMaskingTypes.get(key);
1289+
1290+
}
1291+
1292+
Instabug.setAutoMaskScreenshotsTypes(autoMassingTypesArray);
1293+
}
12771294
}

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.instabug.library.internal.module.InstabugLocale;
2626
import com.instabug.library.ui.onboarding.WelcomeMessage;
2727
import com.instabug.reactlibrary.utils.MainThreadHandler;
28+
import com.instabug.library.MaskingType;
2829

2930
import org.junit.After;
3031
import org.junit.Assert;
@@ -662,4 +663,18 @@ public void testW3CCaughtHeaderFlag(){
662663
boolean expected=internalAPM._isFeatureEnabled(CoreFeature.W3C_ATTACHING_CAPTURED_HEADER);
663664
verify(promise).resolve(expected);
664665
}
666+
667+
@Test
668+
public void testEnableAutoMasking(){
669+
670+
String maskLabel = "labels";
671+
String maskTextInputs = "textInputs";
672+
String maskMedia = "media";
673+
String maskNone = "none";
674+
675+
676+
rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone));
677+
678+
mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
679+
}
665680
}

ios/RNInstabug/ArgsRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ typedef NSDictionary<NSString*, NSNumber*> ArgsDictionary;
2525
+ (ArgsDictionary *) launchType;
2626

2727
+ (NSDictionary<NSString *, NSString *> *) placeholders;
28+
+ (ArgsDictionary *)autoMaskingTypes;
2829

2930
@end

ios/RNInstabug/ArgsRegistry.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ + (NSMutableDictionary *) getAll {
2121
[all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel];
2222
[all addEntriesFromDictionary:ArgsRegistry.placeholders];
2323
[all addEntriesFromDictionary:ArgsRegistry.launchType];
24+
[all addEntriesFromDictionary:ArgsRegistry.autoMaskingTypes];
25+
2426

2527
return all;
2628
}
@@ -249,4 +251,12 @@ + (ArgsDictionary *) launchType {
249251
};
250252
}
251253

254+
+ (ArgsDictionary *)autoMaskingTypes {
255+
return @{
256+
@"labels" : @(IBGAutoMaskScreenshotOptionLabels),
257+
@"textInputs" : @(IBGAutoMaskScreenshotOptionTextInputs),
258+
@"media" : @(IBGAutoMaskScreenshotOptionMedia),
259+
@"none" : @(IBGAutoMaskScreenshotOptionMaskNothing)
260+
};
261+
}
252262
@end

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes;
138138
- (void)addFeatureFlags:(NSDictionary *)featureFlagsMap;
139139
- (void)removeFeatureFlags:(NSArray *)featureFlags;
140140
- (void)removeAllFeatureFlags;
141+
- (void)enableAutoMasking:(NSArray *)autoMaskingTypes;
142+
141143
@end

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,5 +439,16 @@ + (BOOL)requiresMainQueueSetup
439439
+ (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion {
440440
return [iOSVersion compare:[UIDevice currentDevice].systemVersion options:NSNumericSearch] == NSOrderedDescending;
441441
};
442+
RCT_EXPORT_METHOD(enableAutoMasking:(NSArray *)autoMaskingTypes) {
442443

444+
IBGAutoMaskScreenshotOption autoMaskingOptions = 0;
445+
446+
for (NSNumber *event in autoMaskingTypes) {
447+
448+
autoMaskingOptions |= [event intValue];
449+
}
450+
451+
[Instabug setAutoMaskScreenshots: autoMaskingOptions];
452+
453+
};
443454
@end

ios/RNInstabug/RCTConvert+InstabugEnums.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ @implementation RCTConvert (InstabugEnums)
109109
integerValue
110110
);
111111

112+
RCT_ENUM_CONVERTER(
113+
IBGAutoMaskScreenshotOption,
114+
ArgsRegistry.autoMaskingTypes,
115+
IBGAutoMaskScreenshotOptionMaskNothing,
116+
integerValue
117+
);
112118
@end

src/modules/Instabug.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Report from '../models/Report';
1313
import { emitter, NativeEvents, NativeInstabug } from '../native/NativeInstabug';
1414
import { registerW3CFlagsListener } from '../utils/FeatureFlags';
1515
import {
16+
AutoMaskingType,
1617
ColorTheme,
1718
Locale,
1819
LogLevel,
@@ -678,3 +679,11 @@ export const _registerW3CFlagsChangeListener = (
678679
});
679680
NativeInstabug.registerW3CFlagsChangeListener();
680681
};
682+
683+
/**
684+
* Sets the auto mask screenshots types.
685+
* @param autoMaskingTypes The masking type to be applied.
686+
*/
687+
export const enableAutoMasking = (autoMaskingTypes: AutoMaskingType[]) => {
688+
NativeInstabug.enableAutoMasking(autoMaskingTypes);
689+
};

src/native/NativeConstants.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export type NativeConstants = NativeSdkDebugLogsLevel &
1313
NativeLocale &
1414
NativeNonFatalErrorLevel &
1515
NativeStringKey &
16-
NativeLaunchType;
17-
16+
NativeLaunchType &
17+
NativeAutoMaskingType;
1818
interface NativeSdkDebugLogsLevel {
1919
sdkDebugLogsLevelVerbose: any;
2020
sdkDebugLogsLevelDebug: any;
@@ -195,3 +195,10 @@ interface NativeLaunchType {
195195
warm: any;
196196
unknown: any;
197197
}
198+
199+
interface NativeAutoMaskingType {
200+
labels: any;
201+
textInputs: any;
202+
media: any;
203+
none: any;
204+
}

0 commit comments

Comments
 (0)