7
7
import com .facebook .react .bridge .NativeModule ;
8
8
import com .facebook .react .bridge .ReactApplicationContext ;
9
9
import com .facebook .react .uimanager .ViewManager ;
10
+ import com .instabug .bug .BugReporting ;
10
11
import com .instabug .library .Feature ;
11
12
import com .instabug .library .Instabug ;
12
13
import com .instabug .library .InstabugColorTheme ;
13
14
import com .instabug .library .invocation .InstabugInvocationEvent ;
14
15
import com .instabug .library .invocation .util .InstabugFloatingButtonEdge ;
15
16
import com .instabug .library .visualusersteps .State ;
16
17
import android .graphics .Color ;
18
+ import android .util .Log ;
17
19
18
20
import java .util .ArrayList ;
21
+ import java .util .Arrays ;
19
22
import java .util .Collections ;
20
23
import java .util .List ;
21
24
22
25
public class RNInstabugReactnativePackage implements ReactPackage {
23
26
27
+ private static final String TAG = RNInstabugReactnativePackage .class .getSimpleName ();
28
+
24
29
private Application androidApplication ;
25
30
private String mAndroidApplicationToken ;
26
31
private Instabug mInstabug ;
27
32
private Instabug .Builder mBuilder ;
28
- private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent . FLOATING_BUTTON ;
33
+ private ArrayList < InstabugInvocationEvent > invocationEvents = new ArrayList <>() ;
29
34
private InstabugColorTheme instabugColorTheme = InstabugColorTheme .InstabugColorThemeLight ;
30
35
31
36
public RNInstabugReactnativePackage (String androidApplicationToken , Application androidApplication ,
32
- String invocationEventValue , String primaryColor ,
37
+ String [] invocationEventValues , String primaryColor ,
33
38
InstabugFloatingButtonEdge floatingButtonEdge , int offset ) {
34
39
this .androidApplication = androidApplication ;
35
40
this .mAndroidApplicationToken = androidApplicationToken ;
36
41
37
42
//setting invocation event
38
- if (invocationEventValue .equals ("button" )) {
39
- this .invocationEvent = InstabugInvocationEvent .FLOATING_BUTTON ;
40
- } else if (invocationEventValue .equals ("swipe" )) {
41
- this .invocationEvent = InstabugInvocationEvent .TWO_FINGER_SWIPE_LEFT ;
42
-
43
- } else if (invocationEventValue .equals ("shake" )) {
44
- this .invocationEvent = InstabugInvocationEvent .SHAKE ;
45
-
46
- } else if (invocationEventValue .equals ("screenshot" )) {
47
- this .invocationEvent = InstabugInvocationEvent .SCREENSHOT_GESTURE ;
48
-
49
- } else if (invocationEventValue .equals ("none" )) {
50
- this .invocationEvent = InstabugInvocationEvent .NONE ;
51
-
52
- } else {
53
- this .invocationEvent = InstabugInvocationEvent .SHAKE ;
54
- }
55
-
43
+ this .parseInvocationEvent (invocationEventValues );
56
44
57
45
mInstabug = new Instabug .Builder (this .androidApplication , this .mAndroidApplicationToken )
58
- .setInvocationEvent (this .invocationEvent )
46
+ .setInvocationEvents (this .invocationEvents . toArray ( new InstabugInvocationEvent [ 0 ]) )
59
47
.setCrashReportingState (Feature .State .ENABLED )
60
48
.setReproStepsState (State .DISABLED )
61
49
.build ();
62
50
63
51
Instabug .setPrimaryColor (Color .parseColor (primaryColor ));
64
- Instabug .setFloatingButtonEdge (floatingButtonEdge );
65
- Instabug . setFloatingButtonOffsetFromTop (offset );
52
+ BugReporting .setFloatingButtonEdge (floatingButtonEdge );
53
+ BugReporting . setFloatingButtonOffset (offset );
66
54
67
55
}
68
56
69
57
public RNInstabugReactnativePackage (String androidApplicationToken , Application androidApplication ,
70
- String invocationEventValue , String primaryColor ) {
71
- new RNInstabugReactnativePackage (androidApplicationToken ,androidApplication ,invocationEventValue ,primaryColor ,
58
+ String [] invocationEventValues , String primaryColor ) {
59
+ new RNInstabugReactnativePackage (androidApplicationToken ,androidApplication ,invocationEventValues ,primaryColor ,
72
60
InstabugFloatingButtonEdge .LEFT ,250 );
73
61
}
74
62
63
+ private void parseInvocationEvent (String [] invocationEventValues ) {
64
+
65
+ for (int i = 0 ; i < invocationEventValues .length ; i ++) {
66
+ if (invocationEventValues [i ].equals ("button" )) {
67
+ this .invocationEvents .add (InstabugInvocationEvent .FLOATING_BUTTON );
68
+ } else if (invocationEventValues [i ].equals ("swipe" )) {
69
+ this .invocationEvents .add (InstabugInvocationEvent .TWO_FINGER_SWIPE_LEFT );
70
+
71
+ } else if (invocationEventValues [i ].equals ("shake" )) {
72
+ this .invocationEvents .add (InstabugInvocationEvent .SHAKE );
73
+
74
+ } else if (invocationEventValues [i ].equals ("screenshot" )) {
75
+ this .invocationEvents .add (InstabugInvocationEvent .SCREENSHOT_GESTURE );
76
+
77
+ } else if (invocationEventValues [i ].equals ("none" )) {
78
+ this .invocationEvents .add (InstabugInvocationEvent .NONE );
79
+ }
80
+ }
81
+
82
+ if (invocationEvents .isEmpty ()) {
83
+ invocationEvents .add (InstabugInvocationEvent .SHAKE );
84
+ }
85
+ }
86
+
87
+ @ Override
88
+ public List <NativeModule > createNativeModules (ReactApplicationContext reactContext ) {
89
+ List <NativeModule > modules = new ArrayList <>();
90
+ modules .add (new RNInstabugReactnativeModule (reactContext , this .androidApplication , this .mInstabug ));
91
+ return modules ;
92
+ }
93
+
94
+ public List <Class <? extends JavaScriptModule >> createJSModules () {
95
+ return Collections .emptyList ();
96
+ }
97
+
98
+ @ Override
99
+ public List <ViewManager > createViewManagers (ReactApplicationContext reactContext ) {
100
+ return Collections .emptyList ();
101
+ }
102
+
103
+
75
104
public static class Builder {
76
105
//FloatingButtonEdge
77
106
private final String FLOATING_BUTTON_EDGE_RIGHT = "right" ;
78
107
private final String FLOATING_BUTTON_EDGE_LEFT = "left" ;
79
108
80
109
String androidApplicationToken ;
81
110
Application application ;
82
- String invocationEvent ;
111
+ String [] invocationEvents ;
83
112
String primaryColor ;
84
113
InstabugFloatingButtonEdge floatingButtonEdge ;
85
114
int offset ;
@@ -89,8 +118,8 @@ public Builder(String androidApplicationToken, Application application) {
89
118
this .application = application ;
90
119
}
91
120
92
- public Builder setInvocationEvent (String invocationEvent ) {
93
- this .invocationEvent = invocationEvent ;
121
+ public Builder setInvocationEvent (String ... invocationEvents ) {
122
+ this .invocationEvents = invocationEvents ;
94
123
return this ;
95
124
}
96
125
@@ -110,7 +139,7 @@ public Builder setFloatingButtonOffsetFromTop(int offset) {
110
139
}
111
140
112
141
public RNInstabugReactnativePackage build () {
113
- return new RNInstabugReactnativePackage (androidApplicationToken ,application ,invocationEvent ,primaryColor ,floatingButtonEdge ,offset );
142
+ return new RNInstabugReactnativePackage (androidApplicationToken ,application ,invocationEvents ,primaryColor ,floatingButtonEdge ,offset );
114
143
}
115
144
116
145
private InstabugFloatingButtonEdge getFloatingButtonEdge (String floatingButtonEdgeValue ) {
@@ -130,20 +159,4 @@ private InstabugFloatingButtonEdge getFloatingButtonEdge(String floatingButtonEd
130
159
}
131
160
}
132
161
133
- @ Override
134
- public List <NativeModule > createNativeModules (ReactApplicationContext reactContext ) {
135
- List <NativeModule > modules = new ArrayList <>();
136
- modules .add (new RNInstabugReactnativeModule (reactContext , this .androidApplication , this .mInstabug ));
137
- return modules ;
138
- }
139
-
140
- public List <Class <? extends JavaScriptModule >> createJSModules () {
141
- return Collections .emptyList ();
142
- }
143
-
144
- @ Override
145
- public List <ViewManager > createViewManagers (ReactApplicationContext reactContext ) {
146
- return Collections .emptyList ();
147
- }
148
-
149
162
}
0 commit comments