Skip to content

Commit 3ccbfdf

Browse files
Add startWithTokenForAndroid to index.js
1 parent eb6401c commit 3ccbfdf

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import com.facebook.react.bridge.ReactContextBaseJavaModule;
66
import com.facebook.react.bridge.ReactMethod;
77
import com.facebook.react.bridge.Callback;
8-
8+
import com.instabug.library.InstabugColorTheme;
9+
import com.instabug.library.InstabugInvocationEvent;
910
import com.instabug.library.InstabugInvocationMode;
1011
import com.instabug.library.Instabug;
1112

@@ -16,17 +17,40 @@
1617
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
1718

1819
private Instabug mInstabug;
20+
private String mAndroidApplicationToken;
21+
private Instabug.Builder mBuilder;
22+
private Application mApplication;
1923

20-
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug instabug) {
24+
public RNInstabugReactnativeModule(ReactApplicationContext reactContext) {
2125
super(reactContext);
22-
this.mInstabug = instabug;
26+
this.mApplication = reactContext;
2327
}
2428

2529
@Override
2630
public String getName() {
2731
return "RNInstabugReactnative";
2832
}
2933

34+
/**
35+
* start Instabug with default opetions
36+
* default Invocation event Floating button
37+
* @param androidApplicationToken
38+
*/
39+
@ReactMethod
40+
public void startInstabugWithTokenForAndroid(String androidApplicationToken)
41+
{
42+
this.mAndroidApplicationToken = androidApplicationToken;
43+
44+
mInstagbug = new Instabug.Builder(mApplication, mAndroidApplicationToken)
45+
.setDebugEnabled(true)
46+
.setEmailFieldRequired(false)
47+
.setFloatingButtonOffsetFromTop(400)
48+
.setColorTheme(InstabugColorTheme.InstabugColorThemeLight)
49+
.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventFloatingButton)
50+
.setShouldShowIntroDialog(false)
51+
.build();
52+
}
53+
3054
/**
3155
* Adds tag(s) to issues before sending them
3256
*

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,10 @@
1919

2020
public class RNInstabugReactnativePackage implements ReactPackage {
2121

22-
private String mToken;
23-
private Application mApplication;
24-
25-
private Instabug mInstagbug;
26-
private Instabug.Builder mBuilder;
27-
28-
public RNInstabugReactnativePackage(Instabug instabug) {
29-
this.mInstagbug = instabug;
30-
}
31-
32-
public RNInstabugReactnativePackage(Instabug.Builder builder) {
33-
this.mBuilder = builder;
34-
}
35-
36-
public RNInstabugReactnativePackage(String token, Application application) {
37-
this.mToken = token;
38-
this.mApplication = application;
39-
40-
mInstagbug = new Instabug.Builder(mApplication, mToken)
41-
.setDebugEnabled(true)
42-
.setEmailFieldRequired(false)
43-
.setFloatingButtonOffsetFromTop(400)
44-
.setColorTheme(InstabugColorTheme.InstabugColorThemeDark)
45-
.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventFloatingButton)
46-
.setShouldShowIntroDialog(false)
47-
//.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventShake)
48-
.build();
49-
50-
}
5122
@Override
5223
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
5324
List<NativeModule> modules = new ArrayList<>();
54-
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstagbug));
25+
modules.add(new RNInstabugReactnativeModule(reactContext));
5526
return modules;
5627
}
5728

index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ import { NativeModules, NativeAppEventEmitter } from 'react-native';
99
let {Instabug} = NativeModules;
1010

1111
module.exports = {
12+
/**
13+
* Starts the SDK.
14+
* This is the main SDK method that does all the magic. This is the only
15+
* method that SHOULD be called.
16+
* Should be called in constructor of the app registery component
17+
* @param {string} androidToken The token that identifies the app, you can find
18+
* it on your dashboard.
19+
* @param {string} iosToken The token that identifies the app, you can find
20+
* it on your dashboard.
21+
* @param {constants.invocationEvent} invocationEvent The event that invokes
22+
* the SDK's UI.
23+
*/
24+
startWithToken: function(androidToken,iosToken, invocationEvent) {
25+
if( Platform.OS === 'ios') {
26+
Instabug.startWithToken(iosToken, invocationEvent);
27+
28+
} else {
29+
30+
Instabug.startInstabugWithTokenForAndroid(androidToken);
31+
32+
}
33+
34+
35+
},
1236
/**
1337
* Starts the SDK.
1438
* This is the main SDK method that does all the magic. This is the only
@@ -20,7 +44,15 @@ module.exports = {
2044
* the SDK's UI.
2145
*/
2246
startWithToken: function(token, invocationEvent) {
23-
Instabug.startWithToken(token, invocationEvent);
47+
if( Platform.OS === 'ios') {
48+
Instabug.startWithToken(token, invocationEvent);
49+
50+
} else {
51+
Instabug.startInstabugWithTokenForAndroid(token);
52+
53+
}
54+
55+
2456
},
2557

2658
/**

0 commit comments

Comments
 (0)