Skip to content

Commit 357ac64

Browse files
authored
Feature/private views (#57)
* ✨ add private views for iOS * ✨ add setting private views for android
1 parent f0fe84f commit 357ac64

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.facebook.react.bridge.ReactMethod;
1313
import com.facebook.react.bridge.ReadableArray;
1414
import com.facebook.react.bridge.ReadableMap;
15+
import com.facebook.react.bridge.ReadableType;
1516
import com.facebook.react.bridge.WritableArray;
1617
import com.facebook.react.bridge.WritableNativeArray;
1718
import com.facebook.react.bridge.WritableMap;
@@ -73,6 +74,8 @@
7374
import java.util.Locale;
7475
import java.util.Map;
7576

77+
import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;
78+
7679

7780
/**
7881
* The type Rn instabug reactnative module.
@@ -490,7 +493,7 @@ public void setCrashReportingEnabled(boolean isEnabled) {
490493
private void sendJSCrashByReflection(String exceptionObject, boolean isHandled) {
491494
try {
492495
JSONObject newJSONObject = new JSONObject(exceptionObject);
493-
Method method = InstabugUtil.getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class);
496+
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class);
494497
if (method != null) {
495498
method.invoke(null, newJSONObject, isHandled);
496499
}
@@ -541,24 +544,6 @@ public void run() {
541544
});
542545
}
543546

544-
/**
545-
* Sets whether attachments in bug reporting and in-app messaging are enabled or not.
546-
*
547-
* @param screenshot A boolean to enable or disable screenshot attachments.
548-
* @param {boolean} extraScreenShot A boolean to enable or disable extra screenshot attachments.
549-
* @param {boolean} galleryImage A boolean to enable or disable gallery image attachments.
550-
* @param {boolean} screenRecording A boolean to enable or disable screen recording attachments.
551-
*/
552-
@ReactMethod
553-
public void setEnabledAttachmentTypes(boolean screenshot, boolean extraScreenshot, boolean
554-
galleryImage, boolean screenRecording) {
555-
try {
556-
BugReporting.setAttachmentTypesEnabled(screenshot, extraScreenshot, galleryImage,
557-
screenRecording);
558-
} catch (Exception e) {
559-
e.printStackTrace();
560-
}
561-
}
562547

563548
/**
564549
* Sets whether attachments in bug reporting and in-app messaging are enabled or not.
@@ -1904,6 +1889,30 @@ public void setEmailFieldRequiredForFeatureRequests(boolean isEmailRequired, Rea
19041889
}
19051890
}
19061891

1892+
@ReactMethod
1893+
public void setSecureViews(ReadableArray ids) {
1894+
int[] arrayOfIds = new int[ids.size()];
1895+
for (int i = 0; i < ids.size(); i++) {
1896+
int viewId = (int) ids.getDouble(i);
1897+
arrayOfIds[i] = viewId;
1898+
}
1899+
Method method = null;
1900+
try {
1901+
method = InstabugUtil.getMethod(Class.forName("com.instabug.library.Instabug"), "setSecureViewsId", int[].class);
1902+
} catch (ClassNotFoundException e) {
1903+
e.printStackTrace();
1904+
}
1905+
if (method != null) {
1906+
try {
1907+
method.invoke(null, arrayOfIds);
1908+
} catch (IllegalAccessException e) {
1909+
e.printStackTrace();
1910+
} catch (InvocationTargetException e) {
1911+
e.printStackTrace();
1912+
}
1913+
}
1914+
}
1915+
19071916
private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
19081917
switch (key) {
19091918
case SHAKE_HINT:

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
NativeAppEventEmitter,
44
DeviceEventEmitter,
55
Platform,
6+
findNodeHandle,
67
processColor
78
} from 'react-native';
89
let { Instabug } = NativeModules;
@@ -220,7 +221,7 @@ const InstabugModule = {
220221
* @param {color} primaryColor A color to set the UI elements of the SDK to.
221222
*/
222223
setPrimaryColor: function(primaryColor) {
223-
Instabug.setPrimaryColor(primaryColor);
224+
Instabug.setPrimaryColor(processColor(primaryColor));
224225
},
225226

226227
/**
@@ -692,6 +693,18 @@ const InstabugModule = {
692693
}
693694
},
694695

696+
/**
697+
* Hides component from screenshots, screen recordings and view hierarchy.
698+
* @param {Object} viewRef the ref of the component to hide
699+
*/
700+
setPrivateView: function(viewRef) {
701+
const nativeTag = findNodeHandle(viewRef);
702+
if (Platform.OS === 'ios') {
703+
Instabug.hideView(nativeTag);
704+
} else {
705+
Instabug.setSecureViews([nativeTag]);
706+
}
707+
},
695708
/**
696709
* Shows default Instabug prompt.
697710
*/
@@ -961,6 +974,6 @@ export {
961974
Chats,
962975
Replies,
963976
CrashReporting
964-
}
977+
};
965978

966979
export default InstabugModule;

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import <React/RCTLog.h>
1515
#import <os/log.h>
1616
#import <Instabug/IBGTypes.h>
17+
#import <React/RCTUIManager.h>
1718

1819
@implementation InstabugReactBridge
1920

@@ -529,6 +530,11 @@ - (dispatch_queue_t)methodQueue {
529530
callback(@[[NSNumber numberWithBool:result]]);
530531
}
531532

533+
RCT_EXPORT_METHOD(hideView: (nonnull NSNumber *)reactTag) {
534+
UIView* view = [self.bridge.uiManager viewForReactTag:reactTag];
535+
view.instabug_privateView = true;
536+
537+
}
532538
RCT_EXPORT_METHOD(show) {
533539
[Instabug show];
534540
}

0 commit comments

Comments
 (0)