Skip to content

Commit c116eae

Browse files
Merge pull request #1353 from Instabug/feat/Auto-masking-screenshots-in-RN
feat: enable/disable auto masking screenshots in rn
2 parents 0523b05 + c64d9dd commit c116eae

File tree

14 files changed

+150
-38
lines changed

14 files changed

+150
-38
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: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void setEnabled(final boolean isEnabled) {
120120
@Override
121121
public void run() {
122122
try {
123-
if(isEnabled)
123+
if (isEnabled)
124124
Instabug.enable();
125125
else
126126
Instabug.disable();
@@ -133,10 +133,11 @@ public void run() {
133133

134134
/**
135135
* Initializes the SDK.
136-
* @param token The token that identifies the app. You can find it on your dashboard.
136+
*
137+
* @param token The token that identifies the app. You can find it on your dashboard.
137138
* @param invocationEventValues The events that invoke the SDK's UI.
138-
* @param logLevel The level of detail in logs that you want to print.
139-
* @param codePushVersion The Code Push version to be used for all reports.
139+
* @param logLevel The level of detail in logs that you want to print.
140+
* @param codePushVersion The Code Push version to be used for all reports.
140141
*/
141142
@ReactMethod
142143
public void init(
@@ -162,8 +163,8 @@ public void run() {
162163
.setInvocationEvents(invocationEvents)
163164
.setLogLevel(parsedLogLevel);
164165

165-
if(codePushVersion != null) {
166-
if(Instabug.isBuilt()) {
166+
if (codePushVersion != null) {
167+
if (Instabug.isBuilt()) {
167168
Instabug.setCodePushVersion(codePushVersion);
168169
} else {
169170
builder.setCodePushVersion(codePushVersion);
@@ -329,7 +330,7 @@ public void run() {
329330
*
330331
* @param userEmail User's default email
331332
* @param userName Username.
332-
* @param userId User's ID
333+
* @param userId User's ID
333334
*/
334335
@ReactMethod
335336
public void identifyUser(
@@ -749,15 +750,15 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) {
749750

750751
private WritableMap convertFromHashMapToWriteableMap(HashMap hashMap) {
751752
WritableMap writableMap = new WritableNativeMap();
752-
for(int i = 0; i < hashMap.size(); i++) {
753+
for (int i = 0; i < hashMap.size(); i++) {
753754
Object key = hashMap.keySet().toArray()[i];
754755
Object value = hashMap.get(key);
755-
writableMap.putString((String) key,(String) value);
756+
writableMap.putString((String) key, (String) value);
756757
}
757758
return writableMap;
758759
}
759760

760-
private static JSONObject objectToJSONObject(Object object){
761+
private static JSONObject objectToJSONObject(Object object) {
761762
Object json = null;
762763
JSONObject jsonObject = null;
763764
try {
@@ -774,13 +775,12 @@ private static JSONObject objectToJSONObject(Object object){
774775
private WritableArray convertArrayListToWritableArray(List arrayList) {
775776
WritableArray writableArray = new WritableNativeArray();
776777

777-
for(int i = 0; i < arrayList.size(); i++) {
778+
for (int i = 0; i < arrayList.size(); i++) {
778779
Object object = arrayList.get(i);
779780

780-
if(object instanceof String) {
781+
if (object instanceof String) {
781782
writableArray.pushString((String) object);
782-
}
783-
else {
783+
} else {
784784
JSONObject jsonObject = objectToJSONObject(object);
785785
writableArray.pushMap((WritableMap) jsonObject);
786786
}
@@ -836,7 +836,7 @@ public void run() {
836836
* Shows the welcome message in a specific mode.
837837
*
838838
* @param welcomeMessageMode An enum to set the welcome message mode to
839-
* live, or beta.
839+
* live, or beta.
840840
*/
841841
@ReactMethod
842842
public void showWelcomeMessageWithMode(final String welcomeMessageMode) {
@@ -858,7 +858,7 @@ public void run() {
858858
* Sets the welcome message mode to live, beta or disabled.
859859
*
860860
* @param welcomeMessageMode An enum to set the welcome message mode to
861-
* live, beta or disabled.
861+
* live, beta or disabled.
862862
*/
863863
@ReactMethod
864864
public void setWelcomeMessageMode(final String welcomeMessageMode) {
@@ -993,7 +993,6 @@ public void run() {
993993
* Reports that the screen name been changed (Current View).
994994
*
995995
* @param screenName string containing the screen name
996-
*
997996
*/
998997
@ReactMethod
999998
public void reportCurrentViewChange(final String screenName) {
@@ -1016,7 +1015,6 @@ public void run() {
10161015
* Reports that the screen has been changed (Repro Steps) the screen sent to this method will be the 'current view' on the dashboard
10171016
*
10181017
* @param screenName string containing the screen name
1019-
*
10201018
*/
10211019
@ReactMethod
10221020
public void reportScreenChange(final String screenName) {
@@ -1026,7 +1024,7 @@ public void run() {
10261024
try {
10271025
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange", Bitmap.class, String.class);
10281026
if (method != null) {
1029-
method.invoke(null , null, screenName);
1027+
method.invoke(null, null, screenName);
10301028
}
10311029
} catch (Exception e) {
10321030
e.printStackTrace();
@@ -1120,7 +1118,7 @@ public void removeFeatureFlags(final ReadableArray featureFlags) {
11201118
@Override
11211119
public void run() {
11221120
try {
1123-
ArrayList<String> stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags);
1121+
ArrayList<String> stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags);
11241122
Instabug.removeFeatureFlag(stringArray);
11251123
} catch (Exception e) {
11261124
e.printStackTrace();
@@ -1156,11 +1154,12 @@ public void run() {
11561154
}
11571155
});
11581156
}
1157+
11591158
/**
11601159
* Register a listener for W3C flags value change
11611160
*/
11621161
@ReactMethod
1163-
public void registerW3CFlagsChangeListener(){
1162+
public void registerW3CFlagsChangeListener() {
11641163

11651164
MainThreadHandler.runOnMainThread(new Runnable() {
11661165
@Override
@@ -1177,8 +1176,7 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11771176
sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
11781177
}
11791178
});
1180-
}
1181-
catch (Exception e) {
1179+
} catch (Exception e) {
11821180
e.printStackTrace();
11831181
}
11841182

@@ -1189,18 +1187,17 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11891187

11901188

11911189
/**
1192-
* Get first time Value of W3ExternalTraceID flag
1190+
* Get first time Value of W3ExternalTraceID flag
11931191
*/
11941192
@ReactMethod
1195-
public void isW3ExternalTraceIDEnabled(Promise promise){
1193+
public void isW3ExternalTraceIDEnabled(Promise promise) {
11961194

11971195
MainThreadHandler.runOnMainThread(new Runnable() {
11981196
@Override
11991197
public void run() {
12001198
try {
12011199
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_EXTERNAL_TRACE_ID));
1202-
}
1203-
catch (Exception e) {
1200+
} catch (Exception e) {
12041201
e.printStackTrace();
12051202
promise.resolve(false);
12061203
}
@@ -1212,18 +1209,17 @@ public void run() {
12121209

12131210

12141211
/**
1215-
* Get first time Value of W3ExternalGeneratedHeader flag
1212+
* Get first time Value of W3ExternalGeneratedHeader flag
12161213
*/
12171214
@ReactMethod
1218-
public void isW3ExternalGeneratedHeaderEnabled(Promise promise){
1215+
public void isW3ExternalGeneratedHeaderEnabled(Promise promise) {
12191216

12201217
MainThreadHandler.runOnMainThread(new Runnable() {
12211218
@Override
12221219
public void run() {
12231220
try {
12241221
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_GENERATED_HEADER));
1225-
}
1226-
catch (Exception e) {
1222+
} catch (Exception e) {
12271223
e.printStackTrace();
12281224
promise.resolve(false);
12291225
}
@@ -1234,18 +1230,17 @@ public void run() {
12341230
}
12351231

12361232
/**
1237-
* Get first time Value of W3CaughtHeader flag
1233+
* Get first time Value of W3CaughtHeader flag
12381234
*/
12391235
@ReactMethod
1240-
public void isW3CaughtHeaderEnabled(Promise promise){
1236+
public void isW3CaughtHeaderEnabled(Promise promise) {
12411237

12421238
MainThreadHandler.runOnMainThread(new Runnable() {
12431239
@Override
12441240
public void run() {
12451241
try {
12461242
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_CAPTURED_HEADER));
1247-
}
1248-
catch (Exception e) {
1243+
} catch (Exception e) {
12491244
e.printStackTrace();
12501245
promise.resolve(false);
12511246
}
@@ -1274,4 +1269,29 @@ public Map<String, Object> getConstants() {
12741269

12751270
return constants;
12761271
}
1272+
1273+
/**
1274+
* Sets the auto mask screenshots types.
1275+
*
1276+
* @param autoMaskingTypes The masking type to be applied.
1277+
*/
1278+
@ReactMethod
1279+
public void enableAutoMasking(@NonNull ReadableArray autoMaskingTypes) {
1280+
MainThreadHandler.runOnMainThread(new Runnable() {
1281+
1282+
@Override
1283+
public void run() {
1284+
int[] autoMassingTypesArray = new int[autoMaskingTypes.size()];
1285+
for (int i = 0; i < autoMaskingTypes.size(); i++) {
1286+
String key = autoMaskingTypes.getString(i);
1287+
1288+
autoMassingTypesArray[i] = ArgsRegistry.autoMaskingTypes.get(key);
1289+
1290+
}
1291+
1292+
Instabug.setAutoMaskScreenshotsTypes(autoMassingTypesArray);
1293+
}
1294+
1295+
});
1296+
}
12771297
}

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

Lines changed: 14 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,17 @@ 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+
rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone));
676+
677+
mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
678+
}
665679
}

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,5 +608,21 @@ - (void) testIsW3CaughtHeaderEnabled {
608608
OCMVerify([mock w3CaughtHeaderEnabled]);
609609
}
610610

611+
- (void)testEnableAutoMasking {
612+
id mock = OCMClassMock([Instabug class]);
613+
614+
NSArray *autoMaskingTypes = [NSArray arrayWithObjects:
615+
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionLabels],
616+
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionTextInputs],
617+
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMedia],
618+
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMaskNothing],
619+
nil];
620+
621+
OCMStub([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
622+
623+
[self.instabugBridge enableAutoMasking:autoMaskingTypes];
624+
625+
OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
626+
}
611627

612628
@end

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

0 commit comments

Comments
 (0)