Skip to content

Commit d9f311e

Browse files
committed
feat: enable auto masking screenshots in RN
1 parent 16050df commit d9f311e

File tree

16 files changed

+110
-12
lines changed

16 files changed

+110
-12
lines changed

RNInstabug.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm}"
1717

1818
s.dependency 'React-Core'
19-
use_instabug!(s)
19+
# use_instabug!(s)
20+
s.dependency 'Instabug'
21+
2022
end

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
}

examples/default/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ target 'InstabugExample' do
1515
config = use_native_modules!
1616
rn_maps_path = '../node_modules/react-native-maps'
1717
pod 'react-native-google-maps', :path => rn_maps_path
18-
# Flags change depending on the env values.
18+
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-add-rct-text-view-to-automasked-views/14.2.0/Instabug.podspec' # Flags change depending on the env values.
1919
flags = get_default_flags()
2020

2121
use_react_native!(

examples/default/ios/Podfile.lock

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PODS:
3131
- hermes-engine (0.75.4):
3232
- hermes-engine/Pre-built (= 0.75.4)
3333
- hermes-engine/Pre-built (0.75.4)
34-
- Instabug (14.1.0)
34+
- Instabug (14.2.0)
3535
- instabug-reactnative-ndk (0.1.0):
3636
- DoubleConversion
3737
- glog
@@ -1624,7 +1624,7 @@ PODS:
16241624
- ReactCommon/turbomodule/core
16251625
- Yoga
16261626
- RNInstabug (14.1.0):
1627-
- Instabug (= 14.1.0)
1627+
- Instabug
16281628
- React-Core
16291629
- RNReanimated (3.16.1):
16301630
- DoubleConversion
@@ -1768,6 +1768,7 @@ DEPENDENCIES:
17681768
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
17691769
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
17701770
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
1771+
- Instabug (from `https://ios-releases.instabug.com/custom/feature-add-rct-text-view-to-automasked-views/14.2.0/Instabug.podspec`)
17711772
- instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`)
17721773
- OCMock
17731774
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
@@ -1847,7 +1848,6 @@ SPEC REPOS:
18471848
trunk:
18481849
- Google-Maps-iOS-Utils
18491850
- GoogleMaps
1850-
- Instabug
18511851
- OCMock
18521852
- SocketRocket
18531853

@@ -1865,6 +1865,8 @@ EXTERNAL SOURCES:
18651865
hermes-engine:
18661866
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
18671867
:tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b
1868+
Instabug:
1869+
:podspec: https://ios-releases.instabug.com/custom/feature-add-rct-text-view-to-automasked-views/14.2.0/Instabug.podspec
18681870
instabug-reactnative-ndk:
18691871
:path: "../node_modules/instabug-reactnative-ndk"
18701872
RCT-Folly:
@@ -2017,7 +2019,7 @@ SPEC CHECKSUMS:
20172019
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
20182020
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
20192021
hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0
2020-
Instabug: 8cbca8974168c815658133e2813f5ac3a36f8e20
2022+
Instabug: e55d2b7f7555e4df429795fd528d14de6f150203
20212023
instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641
20222024
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
20232025
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
@@ -2084,14 +2086,14 @@ SPEC CHECKSUMS:
20842086
ReactCommon: 6a952e50c2a4b694731d7682aaa6c79bc156e4ad
20852087
RNCClipboard: 2821ac938ef46f736a8de0c8814845dde2dcbdfb
20862088
RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8
2087-
RNInstabug: 96e629f47c0af2e9455fbcf800d12049f980d873
2089+
RNInstabug: b77a5561ccf3806073944bc085a4e4b31f91d31d
20882090
RNReanimated: f42a5044d121d68e91680caacb0293f4274228eb
20892091
RNScreens: c7ceced6a8384cb9be5e7a5e88e9e714401fd958
20902092
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
20912093
RNVectorIcons: 6382277afab3c54658e9d555ee0faa7a37827136
20922094
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
20932095
Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6
20942096

2095-
PODFILE CHECKSUM: 63bf073bef3872df95ea45e7c9c023a331ebb3c3
2097+
PODFILE CHECKSUM: 654123f40bb27c9e3d81b1a5e6b2b60fc29432a2
20962098

2097-
COCOAPODS: 1.14.0
2099+
COCOAPODS: 1.16.2

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+
}

src/native/NativeInstabug.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NativeEventEmitter, NativeModule, ProcessedColorValue } from 'react-nat
22

33
import type Report from '../models/Report';
44
import type {
5+
AutoMaskingType,
56
ColorTheme,
67
InvocationEvent,
78
Locale,
@@ -152,6 +153,7 @@ export interface InstabugNativeModule extends NativeModule {
152153

153154
// W3C Feature Flags Listener for Android
154155
registerW3CFlagsChangeListener(): void;
156+
enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void;
155157
}
156158

157159
export const NativeInstabug = NativeModules.Instabug;

src/utils/Enums.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,9 @@ export enum LaunchType {
241241
*/
242242
warm = constants.warm,
243243
}
244+
export enum AutoMaskingType {
245+
labels = constants.labels,
246+
textInputs = constants.textInputs,
247+
media = constants.media,
248+
none = constants.none,
249+
}

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const mockInstabug: InstabugNativeModule = {
7373
isW3ExternalGeneratedHeaderEnabled: jest.fn(),
7474
isW3CaughtHeaderEnabled: jest.fn(),
7575
registerW3CFlagsChangeListener: jest.fn(),
76+
enableAutoMasking: jest.fn(),
7677
};
7778

7879
export default mockInstabug;

0 commit comments

Comments
 (0)