Skip to content

Commit acfd914

Browse files
committed
✨ Add new feature for setting the floating button edge and offset on Android.
1 parent bd0bfa1 commit acfd914

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

InstabugSample/index.ios.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default class InstabugSample extends Component {
3737
}
3838
});
3939

40+
41+
4042
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
4143
this.state = {
4244
dataSource: ds.cloneWithRows(this._genRows({})),

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.instabug.library.Instabug;
1111
import com.instabug.library.InstabugColorTheme;
1212
import com.instabug.library.invocation.InstabugInvocationEvent;
13+
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
1314
import android.graphics.Color;
1415

1516
import java.util.ArrayList;
@@ -26,7 +27,8 @@ public class RNInstabugReactnativePackage implements ReactPackage {
2627
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
2728

2829
public RNInstabugReactnativePackage(String androidApplicationToken, Application androidApplication,
29-
String invocationEventValue, String primaryColor) {
30+
String invocationEventValue, String primaryColor,
31+
InstabugFloatingButtonEdge floatingButtonEdge, int offset) {
3032
this.androidApplication = androidApplication;
3133
this.mAndroidApplicationToken = androidApplicationToken;
3234

@@ -55,9 +57,69 @@ public RNInstabugReactnativePackage(String androidApplicationToken, Application
5557
.build();
5658

5759
Instabug.setPrimaryColor(Color.parseColor(primaryColor));
60+
Instabug.setFloatingButtonEdge(floatingButtonEdge);
61+
Instabug.setFloatingButtonOffsetFromTop(offset);
5862

5963
}
6064

65+
public static class Builder {
66+
//FloatingButtonEdge
67+
private final String FLOATING_BUTTON_EDGE_RIGHT = "right";
68+
private final String FLOATING_BUTTON_EDGE_LEFT = "left";
69+
70+
String androidApplicationToken;
71+
Application application;
72+
String invocationEvent;
73+
String primaryColor;
74+
InstabugFloatingButtonEdge floatingButtonEdge;
75+
int offset;
76+
77+
public Builder(String androidApplicationToken, Application application) {
78+
this.androidApplicationToken = androidApplicationToken;
79+
this.application = application;
80+
}
81+
82+
public Builder setInvocationEvent(String invocationEvent) {
83+
this.invocationEvent = invocationEvent;
84+
return this;
85+
}
86+
87+
public Builder setPrimaryColor(String primaryColor) {
88+
this.primaryColor = primaryColor;
89+
return this;
90+
}
91+
92+
public Builder setFloatingEdge(String floatingEdge) {
93+
this.floatingButtonEdge = getFloatingButtonEdge(floatingEdge);
94+
return this;
95+
}
96+
97+
public Builder setFloatingButtonOffsetFromTop(int offset) {
98+
this.offset = offset;
99+
return this;
100+
}
101+
102+
public RNInstabugReactnativePackage build() {
103+
return new RNInstabugReactnativePackage(androidApplicationToken,application,invocationEvent,primaryColor,floatingButtonEdge,offset);
104+
}
105+
106+
private InstabugFloatingButtonEdge getFloatingButtonEdge(String floatingButtonEdgeValue) {
107+
InstabugFloatingButtonEdge floatingButtonEdge = InstabugFloatingButtonEdge.RIGHT;
108+
try {
109+
if (floatingButtonEdgeValue.equals(FLOATING_BUTTON_EDGE_LEFT)) {
110+
floatingButtonEdge = InstabugFloatingButtonEdge.LEFT;
111+
} else if (floatingButtonEdgeValue.equals(FLOATING_BUTTON_EDGE_RIGHT)) {
112+
floatingButtonEdge = InstabugFloatingButtonEdge.RIGHT;
113+
}
114+
return floatingButtonEdge;
115+
116+
} catch(Exception e) {
117+
e.printStackTrace();
118+
return floatingButtonEdge;
119+
}
120+
}
121+
}
122+
61123
@Override
62124
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
63125
List<NativeModule> modules = new ArrayList<>();

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,9 @@ module.exports = {
852852
* @readonly
853853
* @enum {number}
854854
*/
855-
rectEdge: {
856-
minX: Instabug.rectMinXEdge,
857-
minY: Instabug.rectMinYEdge,
858-
maxX: Instabug.rectMaxXEdge,
859-
maxY: Instabug.rectMaxYEdge
855+
floatingButtonEdge: {
856+
left: Instabug.rectMinXEdge,
857+
right: Instabug.rectMaxXEdge,
860858
},
861859

862860
/**

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "instabug-reactnative",
3-
"version": "1.1.6",
3+
"version": "1.1.8",
44
"description": "React Native plugin for integrating the Instabug SDK",
55
"main": "index.js",
66
"repository": {
@@ -23,7 +23,7 @@
2323
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
2424
"rnpm": {
2525
"android": {
26-
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"shake\",\"#1D82DC\")"
26+
"packageInstance": "new RNInstabugReactnativePackage.Builder(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this)\n.setInvocationEvent(\"shake\")\n.build()"
2727
}
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)