Skip to content

Commit 8143618

Browse files
authored
🎉 Unifying native SDKs initialization (#356)
1 parent b69b126 commit 8143618

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+175
-136
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Master
2+
3+
**⚠️ If you are using Android, please make sure to follow the migration guide [here](https://github.com/Instabug/Instabug-React-Native/blob/master/README.md#updating-to-version-863)**
4+
* You can now initialize Instabug on Android by calling `Instabug.start` from Javascript, instead of calling the builder method from the application class.
5+
* Updates native iOS SDK to v8.6.2
6+
17
## v8.6.2 (2019-08-29)
28

39
* Updates native Android SDK to v8.6.2

InstabugSample/android/app/src/main/java/com/instabugsample/MainApplication.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ protected List<ReactPackage> getPackages() {
2626
List<ReactPackage> packages = new PackageList(this).getPackages();
2727
// Packages that cannot be autolinked yet can be added manually here, for example:
2828
// packages.add(new MyReactNativePackage());
29-
new RNInstabugReactnativePackage.Builder("YOUR_TOKEN",this.getApplication())
30-
.setInvocationEvent("shake")
31-
.build();
3229
return packages;
3330
}
3431

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,35 +87,19 @@ pod install
8787
```
8888

8989
## Using Instabug
90-
1. To start using Instabug, import it into your `index.ios.js` and `index.android.js` file.
90+
1. To start using Instabug, import it into your `index.js` file.
9191

9292
```javascript
9393
import Instabug from 'instabug-reactnative';
9494
```
95-
2. Then initialize it in the `constructor` or `componentWillMount`. This line will let the Instabug SDK work with the default behavior. The SDK will be invoked when the device is shaken. You can customize this behavior through the APIs (You can skip this step if you are building an Android app only).
95+
2. Then initialize it in the `constructor` or `componentWillMount`. This line will let the Instabug SDK work with the default behavior. The SDK will be invoked when the device is shaken. You can customize this behavior through the APIs.
9696

9797
```javascript
98-
Instabug.startWithToken('IOS_APP_TOKEN', [Instabug.invocationEvent.shake]);
99-
```
100-
3. Open `android/app/src/main/java/[...]/MainApplication.java`
101-
You should find the getPackages method looks like the following snippet. You just need to add your Android app token (You can skip this step if you are building an iOS app only). You can change the invocation event from here, simply by replacing the `"shake"` with any of the following `"button"`, `"none"`, `"screenshot"`, or `"swipe"`. You can change the primary color by replacing the `"#1D82DC"` with any colour of your choice.
102-
In the case that you are using the floating button as an invocation event, you can change the floating button edge and the floating button offset using the last two methods, by replacing `"left"` to `"right"`, and by changing the offset number.
103-
```javascript
104-
@Override
105-
protected List<ReactPackage> getPackages() {
106-
return Arrays.<ReactPackage>asList(
107-
new MainReactPackage(),
108-
new RNInstabugReactnativePackage.Builder("YOUR_APP_TOKEN", MainApplication.this)
109-
.setInvocationEvent("shake")
110-
.setPrimaryColor("#1D82DC")
111-
.setFloatingEdge("left")
112-
.setFloatingButtonOffsetFromTop(250)
113-
.build()
114-
}
98+
Instabug.start('APP_TOKEN', [Instabug.invocationEvent.shake]);
11599
```
116100
You can find your app token by selecting the SDK tab from your [**Instabug dashboard**](https://dashboard.instabug.com/app/sdk/).
117101

118-
4. Make sure the following snippet is added to your project level `build.gradle`. This should be added automatically upon linking. If not, you can add it manually.
102+
3. Make sure the following snippet is added to your project level `build.gradle`. This should be added automatically upon linking. If not, you can add it manually.
119103
```dart
120104
allprojects {
121105
repositories {
@@ -166,6 +150,25 @@ npm install instabug-reactnative
166150
react-native add-instabug
167151
```
168152

153+
### Updating to version 8.6.3
154+
155+
Starting 8.6.3, starting the SDK on Android can now be done from the JS side and no longer requires the integration code inside Android's `MainApplication.java`.
156+
157+
1) Remove the android integration code from your `MainApplication.java`, it should look something like this:
158+
159+
```java
160+
new RNInstabugReactnativePackage.Builder("YOUR_APP_TOKEN", MainApplication.this)
161+
.setInvocationEvent("shake")
162+
.build();
163+
```
164+
165+
2. Then initialize it in the `constructor` or `componentWillMount`. This line will let the Instabug SDK work with the default behavior. The SDK will be invoked when the device is shaken. You can customize this behavior through the APIs.
166+
167+
```javascript
168+
Instabug.start('APP_TOKEN', [Instabug.invocationEvent.shake]);
169+
```
170+
171+
169172
## Microphone and Photo Library Usage Description (iOS Only)
170173

171174
Instabug needs access to the microphone and photo library to be able to let users add audio and video attachments. Starting from iOS 10, apps that don’t provide a usage description for those 2 permissions would be rejected when submitted to the App Store.

__tests__/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('Instabug Module', () => {
102102
const invocationEvents = [Instabug.invocationEvent.floatingButton, Instabug.invocationEvent.shake];
103103
Instabug.start(token, invocationEvents);
104104

105-
expect(startWithToken.notCalled).toBe(true);
105+
expect(startWithToken.calledOnceWithExactly(token, invocationEvents)).toBe(true);
106106

107107
});
108108

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727

2828
dependencies {
2929
implementation 'com.facebook.react:react-native:+'
30-
api('com.instabug.library:instabug:8.6.2.0') {
30+
api('com.instabug.library:instabug:8.6.3.0') {
3131
exclude group: 'com.android.support:appcompat-v7'
3232
}
3333
testImplementation 'org.mockito:mockito-core:1.10.19'

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,39 @@ public String getName() {
237237
return "Instabug";
238238
}
239239

240+
/**
241+
* Starts the SDK.
242+
* @param token string The token that identifies the app, you can find
243+
* it on your dashboard.
244+
* @param invocationEventValues ReadableArray The events that invokes
245+
* the SDK's UI.
246+
*/
247+
@ReactMethod
248+
public void startWithToken(final String token, final ReadableArray invocationEventValues) {
249+
try {
250+
Object[] objectArray = ArrayUtil.toArray(invocationEventValues);
251+
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
252+
final InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[stringArray.length];
253+
254+
for (int i = 0; i < stringArray.length; i++) {
255+
String key = stringArray[i];
256+
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
257+
}
258+
new Handler(Looper.getMainLooper()).post(new Runnable() {
259+
@Override
260+
public void run() {
261+
try {
262+
new Instabug.Builder(getCurrentActivity().getApplication(), token).setInvocationEvents(invocationEventsArray).build();
263+
} catch (Exception e) {
264+
e.printStackTrace();
265+
}
266+
}
267+
});
268+
} catch (Exception e) {
269+
e.printStackTrace();
270+
}
271+
}
272+
240273
/**
241274
* Adds tag(s) to issues before sending them
242275
*

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const InstabugModule = {
5555
* @param {invocationEvent} invocationEvent The event that invokes
5656
* the SDK's UI.
5757
*/
58-
start(token, invocationEvent) {
59-
if (Platform.OS === 'ios') Instabug.startWithToken(token, invocationEvent);
58+
start: function(token, invocationEvent) {
59+
Instabug.startWithToken(token, invocationEvent);
6060
},
6161

6262
/**

ios/Instabug.framework/Headers/IBGBugReporting.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2019 by Instabug, Inc., all rights reserved.
77
8-
Version: 8.6.1
8+
Version: 8.6.2
99
*/
1010

1111
#import <Foundation/Foundation.h>

ios/Instabug.framework/Headers/IBGChats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2019 by Instabug, Inc., all rights reserved.
77
8-
Version: 8.6.1
8+
Version: 8.6.2
99
*/
1010

1111
#import <Foundation/Foundation.h>

ios/Instabug.framework/Headers/IBGCrashReporting.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2019 by Instabug, Inc., all rights reserved.
77
8-
Version: 8.6.1
8+
Version: 8.6.2
99
*/
1010

1111
#import <Foundation/Foundation.h>

ios/Instabug.framework/Headers/IBGFeatureRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2019 by Instabug, Inc., all rights reserved.
77
8-
Version: 8.6.1
8+
Version: 8.6.2
99
*/
1010

1111

ios/Instabug.framework/Headers/IBGLog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2019 by Instabug, Inc., all rights reserved.
77
8-
Version: 8.6.1
8+
Version: 8.6.2
99
*/
1010

1111
#import <Foundation/Foundation.h>

0 commit comments

Comments
 (0)