Add new feature for setting the floating button edge and offset on Android.

This commit is contained in:
Salma ElTarzi 2017-07-20 13:48:02 +02:00
parent bd0bfa1175
commit acfd914cfe
4 changed files with 71 additions and 9 deletions

View File

@ -37,6 +37,8 @@ export default class InstabugSample extends Component {
}
});
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: ds.cloneWithRows(this._genRows({})),

View File

@ -10,6 +10,7 @@ import com.facebook.react.uimanager.ViewManager;
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
import android.graphics.Color;
import java.util.ArrayList;
@ -26,7 +27,8 @@ public class RNInstabugReactnativePackage implements ReactPackage {
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
public RNInstabugReactnativePackage(String androidApplicationToken, Application androidApplication,
String invocationEventValue, String primaryColor) {
String invocationEventValue, String primaryColor,
InstabugFloatingButtonEdge floatingButtonEdge, int offset) {
this.androidApplication = androidApplication;
this.mAndroidApplicationToken = androidApplicationToken;
@ -55,9 +57,69 @@ public class RNInstabugReactnativePackage implements ReactPackage {
.build();
Instabug.setPrimaryColor(Color.parseColor(primaryColor));
Instabug.setFloatingButtonEdge(floatingButtonEdge);
Instabug.setFloatingButtonOffsetFromTop(offset);
}
public static class Builder {
//FloatingButtonEdge
private final String FLOATING_BUTTON_EDGE_RIGHT = "right";
private final String FLOATING_BUTTON_EDGE_LEFT = "left";
String androidApplicationToken;
Application application;
String invocationEvent;
String primaryColor;
InstabugFloatingButtonEdge floatingButtonEdge;
int offset;
public Builder(String androidApplicationToken, Application application) {
this.androidApplicationToken = androidApplicationToken;
this.application = application;
}
public Builder setInvocationEvent(String invocationEvent) {
this.invocationEvent = invocationEvent;
return this;
}
public Builder setPrimaryColor(String primaryColor) {
this.primaryColor = primaryColor;
return this;
}
public Builder setFloatingEdge(String floatingEdge) {
this.floatingButtonEdge = getFloatingButtonEdge(floatingEdge);
return this;
}
public Builder setFloatingButtonOffsetFromTop(int offset) {
this.offset = offset;
return this;
}
public RNInstabugReactnativePackage build() {
return new RNInstabugReactnativePackage(androidApplicationToken,application,invocationEvent,primaryColor,floatingButtonEdge,offset);
}
private InstabugFloatingButtonEdge getFloatingButtonEdge(String floatingButtonEdgeValue) {
InstabugFloatingButtonEdge floatingButtonEdge = InstabugFloatingButtonEdge.RIGHT;
try {
if (floatingButtonEdgeValue.equals(FLOATING_BUTTON_EDGE_LEFT)) {
floatingButtonEdge = InstabugFloatingButtonEdge.LEFT;
} else if (floatingButtonEdgeValue.equals(FLOATING_BUTTON_EDGE_RIGHT)) {
floatingButtonEdge = InstabugFloatingButtonEdge.RIGHT;
}
return floatingButtonEdge;
} catch(Exception e) {
e.printStackTrace();
return floatingButtonEdge;
}
}
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

View File

@ -852,11 +852,9 @@ module.exports = {
* @readonly
* @enum {number}
*/
rectEdge: {
minX: Instabug.rectMinXEdge,
minY: Instabug.rectMinYEdge,
maxX: Instabug.rectMaxXEdge,
maxY: Instabug.rectMaxYEdge
floatingButtonEdge: {
left: Instabug.rectMinXEdge,
right: Instabug.rectMaxXEdge,
},
/**

View File

@ -1,6 +1,6 @@
{
"name": "instabug-reactnative",
"version": "1.1.6",
"version": "1.1.8",
"description": "React Native plugin for integrating the Instabug SDK",
"main": "index.js",
"repository": {
@ -23,7 +23,7 @@
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
"rnpm": {
"android": {
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"shake\",\"#1D82DC\")"
"packageInstance": "new RNInstabugReactnativePackage.Builder(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this)\n.setInvocationEvent(\"shake\")\n.build()"
}
}
}
}