Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7dfdb9

Browse files
Release v1.0.1
1 parent b216ced commit f7dfdb9

File tree

5 files changed

+142
-125
lines changed

5 files changed

+142
-125
lines changed

README.md

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,52 @@
77

88
## Installation
99

10-
#### iOS
11-
1210
`$ npm install https://github.com/Instabug/instabug-reactnative --save`
1311

14-
`$ rnpm link instabug-reactnative`
12+
`$ react-native link instabug-reactnative`
13+
14+
#### iOS Manual installation
1515

1616
1. Open your app `.xcodeproj` file
1717
2. Add the following line to your "Podfile": `pod 'Instabug', '~> 6.0.0'`
1818
3. run `pod install`
1919
4. Run your project (`Cmd+R`)<
2020

21-
#### Android (Pending)
22-
23-
`$ npm install https://github.com/Instabug/instabug-reactnative --save`
24-
25-
`$ rnpm link instabug-reactnative`
26-
27-
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
28-
- Add `import com.instabug.reactlibrary.RNInstabugReactnativePackage;` to the imports at the top of the file
29-
- Add `new RNInstabugReactnativePackage()` to the list returned by the `getPackages()` method
21+
#### Android Manual installation
22+
23+
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
24+
- Add
25+
```java
26+
import com.instabug.reactlibrary.RNInstabugReactnativePackage;
27+
```
28+
to the imports at the top of the file
29+
- Add
30+
```java
31+
new RNInstabugReactnativePackage("YOUR_ANDROID_APPLICATION_TOKEN",MainApplication.this,"INVOCATION_EVENT");
32+
```
33+
to the list returned by the `getPackages()` method
3034
2. Append the following lines to `android/settings.gradle`:
31-
```
35+
```gradle
3236
include ':instabug-reactnative'
3337
project(':instabug-reactnative').projectDir = new File(rootProject.projectDir, '../node_modules/instabug-reactnative/android')
3438
```
3539
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
36-
```
40+
```gradle
3741
compile project(':instabug-reactnative')
3842
```
3943

40-
## Usage
41-
```javascript
42-
import Instabug from'instabug-reactnative';
44+
## Usage
45+
46+
```javascript
47+
48+
import Instabug from'instabug-reactnative';
49+
50+
```
51+
4352

53+
### iOS Example
54+
55+
```javascript
4456
class testApp extends Component {
4557
constructor() {
4658
super();
@@ -52,13 +64,52 @@ class testApp extends Component {
5264

5365
You can check the rest of the APIs here [Wiki](https://github.com/Instabug/instabug-reactnative/wiki).
5466

55-
### iOS
5667

5768
If your app doesn't already access the microphone or photo library, you'll need to add the following 2 keys to your app's info.plist file:
5869

5970
NSMicrophoneUsageDescription
6071
NSPhotoLibraryUsageDescription
61-
72+
73+
### Android Example
74+
75+
76+
Usage
77+
78+
To initialize Instabug in your app, you only need to link instabug-reactnative correctly by overriding "YOUR_ANDROID_TOKEN" text by your android app token,
79+
"button" text by your desired invocation event,
80+
"light" text by your desired color theme,
81+
and can take a wide range of optional parameters for configuration.
82+
83+
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
84+
85+
after linking the plugin, you should find the getPackages method looks like
86+
87+
```java
88+
@Override
89+
protected List<ReactPackage> getPackages() {
90+
return Arrays.<ReactPackage>asList(
91+
new MainReactPackage(),
92+
new RNInstabugReactnativePackage("YOUR_ANDROID_TOKEN",MainApplication.this,"button","light")
93+
);
94+
}
95+
```
96+
The invocation event can be specified as one of the following values:
97+
98+
99+
| value | native equivalent | description |
100+
|:------------:|:-------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
101+
| 'shake' | InstabugInvocationEvent.SHAKE | Shaking the device while in any screen to show the feedback form. |
102+
| 'button' | InstabugInvocationEvent.FLOATING_BUTTON | Shows a floating button on top of all views, when pressed it takes a screenshot. |
103+
| 'screenshot' | InstabugInvocationEvent.SCREENSHOT_GESTURE | Taking a screenshot using the Home+Lock buttons while in any screen to show the feedback form, substituted with IBGInvocationEventShake on iOS 6.1.3 and earlier. |
104+
| 'swipe' | InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT | Swiping two fingers left while in any screen to show the feedback form. |
105+
| 'none' | InstabugInvocationEvent.NONE | No event will be registered to show the feedback form, you'll need to code your own and call the method invoke. |
106+
107+
The InstabugColorTheme can be specified as one of the following values:
108+
| value | native equivalent | description |
109+
|:------------:|:-------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
110+
| 'light'| InstabugColorTheme.InstabugColorThemeLight |light theme is color theme to use for the SDK's UI|
111+
| 'dark'| InstabugColorTheme.InstabugColorThemeDark |Dark theme is color theme to use for the SDK's UI|
112+
62113
## License
63114

64115
This software is released under <a href="https://opensource.org/licenses/mit-license.php">MIT License</a>.

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

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,27 @@
2222
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
2323

2424
private Instabug mInstabug;
25-
private String mAndroidApplicationToken;
26-
private Instabug.Builder mBuilder;
27-
private Application androidApplication;
25+
private InstabugInvocationEvent invocationEvent;
2826

29-
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application androidApplication) {
27+
public RNInstabugReactnativeModule(ReactApplicationContext reactContext,Instabug mInstabug) {
3028
super(reactContext);
31-
this.androidApplication = androidApplication;
29+
this.mInstabug = mInstabug;
3230
}
3331

3432
@Override
3533
public String getName() {
3634
return "Instabug";
3735
}
3836

39-
/**
40-
* start Instabug with default opetions
41-
* default Invocation event Floating button
42-
* @param androidApplicationToken
37+
/**
38+
* invoke sdk manually
39+
*
40+
* @param tags
4341
*/
4442
@ReactMethod
45-
public void startWithToken(String androidApplicationToken,InstabugInvocationEvent invocationEvent)
43+
public void invoke()
4644
{
47-
this.mAndroidApplicationToken = androidApplicationToken;
48-
49-
mInstabug = new Instabug.Builder(androidApplication, mAndroidApplicationToken)
50-
.setEmailFieldRequired(false)
51-
.setFloatingButtonOffsetFromTop(400)
52-
.setTheme(InstabugColorTheme.InstabugColorThemeLight)
53-
.setInvocationEvent(invocationEvent)
54-
.setIntroMessageEnabled(false)
55-
.build();
45+
mInstabug.invoke();
5646
}
5747

5848
/**
@@ -194,12 +184,6 @@ public void showIntroMessage() {
194184
@Override
195185
public Map<String, Object> getConstants() {
196186
final Map<String, Object> constants = new HashMap<>();
197-
constants.put("invocationEventFloatingButton", InstabugInvocationEvent.FLOATING_BUTTON);
198-
constants.put("invocationEventTwoFingersSwipeLeft", InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFTt);
199-
constants.put("invocationEventScreenshot", InstabugInvocationEvent.SCREENSHOT_GESTURE);
200-
constants.put("invocationEventShake", InstabugInvocationEvent.SHAKE);
201-
constants.put("invocationEventNone", InstabugInvocationEvent.NONE);
202-
203187
return constants;
204188
}
205189
}

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

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,76 @@
1414
import com.facebook.react.bridge.JavaScriptModule;
1515

1616

17+
import com.instabug.library.Instabug;
18+
import com.instabug.library.InstabugColorTheme;
19+
import com.instabug.library.invocation.InstabugInvocationEvent;
20+
21+
1722
public class RNInstabugReactnativePackage implements ReactPackage {
1823

1924
Application androidApplication;
20-
21-
public RNInstabugReactnativePackage(Application application) {
25+
private String mAndroidApplicationToken;
26+
private Instabug mInstabug;
27+
private Instabug.Builder mBuilder;
28+
private InstabugInvocationEvent invocationEvent=InstabugInvocationEvent.FLOATING_BUTTON;
29+
private InstabugColorTheme instabugColorTheme=InstabugColorTheme.InstabugColorThemeLight;
30+
public RNInstabugReactnativePackage(Instabug instabug) {
31+
this.mInstabug = instabug;
32+
}
33+
34+
public RNInstabugReactnativePackage(String androidApplicationToken,Application application) {
2235
this.androidApplication = application;
36+
this.mAndroidApplicationToken = androidApplicationToken;
37+
38+
mInstabug = new Instabug.Builder(androidApplication, mAndroidApplicationToken)
39+
.setEmailFieldRequired(false)
40+
.setFloatingButtonOffsetFromTop(400)
41+
.setTheme(this.instabugColorTheme)
42+
.setInvocationEvent(this.invocationEvent)
43+
.setIntroMessageEnabled(false)
44+
.build();
45+
}
46+
47+
public RNInstabugReactnativePackage(String androidApplicationToken,Application application,String invocationEventValue) {
48+
if(invocationEventValue.equals("button")) {
49+
this.invocationEvent=InstabugInvocationEvent.FLOATING_BUTTON;
50+
} else if(invocationEventValue.equals("swipe")) {
51+
this.invocationEvent=InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
52+
53+
} else if(invocationEventValue.equals("shake")) {
54+
this.invocationEvent=InstabugInvocationEvent.SHAKE;
55+
56+
} else if(invocationEventValue.equals("screenshot")){
57+
this.invocationEvent=InstabugInvocationEvent.SCREENSHOT_GESTURE;
58+
59+
} else if(invocationEventValue.equals("none")) {
60+
this.invocationEvent=InstabugInvocationEvent.NONE;
61+
62+
} else {
63+
this.invocationEvent=InstabugInvocationEvent.FLOATING_BUTTON;
64+
}
65+
66+
this(androidApplicationToken,application);
67+
68+
}
69+
70+
public RNInstabugReactnativePackage(String androidApplicationToken,Application application,String invocationEventValue,String instabugColorThemeValue) {
71+
if (instabugColorThemeValue.equals("light")) {
72+
this.instabugColorTheme=InstabugColorTheme.InstabugColorThemeLight;
73+
} else if (instabugColorThemeValue.equals("dark")) {
74+
this.instabugColorTheme=InstabugColorTheme.InstabugColorThemeDark;
75+
} else {
76+
this.instabugColorTheme=InstabugColorTheme.InstabugColorThemeLight;
77+
}
78+
79+
this(androidApplicationToken,application,invocationEventValue);
80+
2381
}
2482

2583
@Override
2684
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
2785
List<NativeModule> modules = new ArrayList<>();
28-
modules.add(new RNInstabugReactnativeModule(reactContext,androidApplication));
86+
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstabug));
2987
return modules;
3088
}
3189

index.android.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{
33
"name": "instabug-reactnative",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"description": "React Native plugin for integrating the Instabug SDK",
66
"main": "index.js",
77
"scripts": {
@@ -27,7 +27,7 @@
2727
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
2828
"rnpm": {
2929
"android": {
30-
"packageInstance": "new RNInstabugReactnativePackage(MainApplication.this)"
30+
"packageInstance": "new RNInstabugReactnativePackage("YOUR_ANDROID_APPLICATION_TOKEN",MainApplication.this,"button")"
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)