Skip to content

Commit 0366b06

Browse files
DavidMina96Ali Abdelfattah
andauthored
[MOB-8680] Add setFloatingButtonEdge API (#233)
* Add setFloatingButtonEdge API - Flutter * Add setFloatingButtonEdge API - Android * Add setFloatingButtonEdge API - iOS * Add setFloatingButtonEdge API tests * Update CHANGELOG.md Co-authored-by: Ali Abdelfattah <[email protected]>
1 parent b734e0f commit 0366b06

File tree

10 files changed

+114
-0
lines changed

10 files changed

+114
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## master
22

3+
* Adds BugReporting.setFloatingButtonEdge API
34
* Supports starting SDK from Dart only.
45

56
## v10.13.0 (2022-03-31)

android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.instabug.bug.invocation.Option;
55
import com.instabug.featuresrequest.ActionType;
66
import com.instabug.library.InstabugColorTheme;
7+
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
78
import com.instabug.library.InstabugCustomTextPlaceHolder;
89
import com.instabug.library.extendedbugreport.ExtendedBugReport;
910
import com.instabug.library.visualusersteps.State;
@@ -56,6 +57,7 @@ final class ArgsRegistry {
5657
registerColorThemeArgs(ARGS);
5758
registerLocaleArgs(ARGS);
5859
registerInvocationOptionsArgs(ARGS);
60+
registerInstabugFloatingButtonEdgeArgs(ARGS);
5961
registerCustomTextPlaceHolderKeysArgs(ARGS);
6062
registerInstabugReportTypesArgs(ARGS);
6163
registerInstabugExtendedBugReportModeArgs(ARGS);
@@ -123,6 +125,11 @@ static void registerColorThemeArgs(Map<String, Object> args) {
123125
args.put("ColorTheme.dark", InstabugColorTheme.InstabugColorThemeDark);
124126
}
125127

128+
static void registerInstabugFloatingButtonEdgeArgs(Map<String, Object> args) {
129+
args.put("FloatingButtonEdge.left", InstabugFloatingButtonEdge.LEFT);
130+
args.put("FloatingButtonEdge.right", InstabugFloatingButtonEdge.RIGHT);
131+
}
132+
126133
static void registerInvocationOptionsArgs(Map<String, Object> args) {
127134
args.put("InvocationOption.commentFieldRequired", Option.COMMENT_FIELD_REQUIRED);
128135
args.put("InvocationOption.disablePostSendingDialog", Option.DISABLE_POST_SENDING_DIALOG);

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.instabug.library.extendedbugreport.ExtendedBugReport;
2727
import com.instabug.library.invocation.InstabugInvocationEvent;
2828
import com.instabug.library.invocation.OnInvokeCallback;
29+
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
2930
import com.instabug.library.logging.InstabugLog;
3031
import com.instabug.library.model.NetworkLog;
3132
import com.instabug.library.ui.onboarding.WelcomeMessage;
@@ -282,6 +283,19 @@ public void setColorTheme(String colorTheme) {
282283
}
283284
}
284285

286+
/**
287+
* Sets the position of Instabug floating button on the screen.
288+
*
289+
* @param floatingButtonEdge left or right edge of the screen.
290+
* @param floatingButtonOffset offset for the position on the y-axis.
291+
*/
292+
public void setFloatingButtonEdge(String floatingButtonEdge, int floatingButtonOffset) {
293+
InstabugFloatingButtonEdge resolvedFloatingButtonEdge = ArgsRegistry.getDeserializedValue(floatingButtonEdge,
294+
InstabugFloatingButtonEdge.class);
295+
BugReporting.setFloatingButtonEdge(resolvedFloatingButtonEdge);
296+
BugReporting.setFloatingButtonOffset(floatingButtonOffset);
297+
}
298+
285299
/**
286300
* Appends a set of tags to previously added tags of reported feedback, bug or
287301
* crash.

example/android/app/src/main/kotlin/com/example/InstabugSample/OnMethodCallTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ public void testSetPrimaryColor() {
148148
verify(instabugMock).setPrimaryColor(12312331231233L);
149149
}
150150

151+
public void testSetFloatingButtonEdge(){
152+
String methodName = "setFloatingButtonEdge";
153+
ArrayList<Object> argsList = new ArrayList<>();
154+
argsList.add("FloatingButtonEdge.left");
155+
argsList.add(300);
156+
Mockito.doNothing().when(instabugMock).setFloatingButtonEdge(any(String.class), any(Integer.class));
157+
testMethodCall(methodName, argsList);
158+
verify(instabugMock).setFloatingButtonEdge("FloatingButtonEdge.left", 300);
159+
}
160+
151161
public void testAddFileAttachmentWithData() {
152162
String methodName = "addFileAttachmentWithData";
153163
ArrayList<Object> argsList = new ArrayList<>();

example/android/app/src/test/java/com/example/InstabugSample/InstabugFlutterPluginTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public void testSetPrimaryColor() {
9797
new OnMethodCallTests().testSetPrimaryColor();
9898
}
9999

100+
/**
101+
* (String, int)
102+
*/
103+
@Test
104+
public void testSetFloatingButtonEdge() {
105+
new OnMethodCallTests().testSetFloatingButtonEdge();
106+
}
107+
100108
/**
101109
* (byte[], String)
102110
*/

example/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ - (void)testSetPrimaryColor {
199199
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
200200
}
201201

202+
- (void)testSetFloatingButtonEdge {
203+
id mock = OCMClassMock([InstabugFlutterPlugin class]);
204+
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];
205+
206+
NSArray *arguments = [NSArray arrayWithObjects:@"FloatingButtonEdge.left", @(300), nil];
207+
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"setFloatingButtonEdge:withTopOffset:" arguments:arguments];
208+
[[[mock stub] classMethod] setFloatingButtonEdge:@"FloatingButtonEdge.left"withTopOffset:@(300)];
209+
210+
XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
211+
[instabug handleMethodCall:call result:^(id _Nullable result) {
212+
XCTAssertNil(result);
213+
[expectation fulfill];
214+
}];
215+
216+
[[[mock verify] classMethod] setFloatingButtonEdge:@"FloatingButtonEdge.left"withTopOffset:@(300)];
217+
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
218+
}
219+
202220
- (void)testAddFileAttachmentWithData {
203221
id mock = OCMClassMock([InstabugFlutterPlugin class]);
204222
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];

ios/Classes/InstabugFlutterPlugin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@
102102
*/
103103
+ (void)setColorTheme:(NSString *)colorTheme;
104104

105+
/**
106+
* Sets the position of Instabug floating button on the screen.
107+
* @param floatingButtonEdge left or right edge of the screen.
108+
* @param floatingButtonTopOffset offset for the position on the y-axis.
109+
*/
110+
+ (void)setFloatingButtonEdge:(NSString *)floatingButtonEdge withTopOffset:(NSNumber *)floatingButtonTopOffset;
111+
105112
/**
106113
* Appends a set of tags to previously added tags of reported feedback, bug or crash.
107114
* @param tags An array of tags to append to current tags.

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ + (void)setColorTheme:(NSString*) colorTheme {
212212
[Instabug setColorTheme:intColorTheme];
213213
}
214214

215+
/**
216+
* Sets the position of Instabug floating button on the screen.
217+
* @param floatingButtonEdge left or right edge of the screen.
218+
* @param floatingButtonTopOffset offset for the position on the y-axis.
219+
*/
220+
+ (void)setFloatingButtonEdge:(NSString *)floatingButtonEdge withTopOffset:(NSNumber *)floatingButtonTopOffset {
221+
NSDictionary *constants = [self constants];
222+
CGRectEdge intFloatingButtonEdge = ((NSNumber *) constants[floatingButtonEdge]).doubleValue;
223+
IBGBugReporting.floatingButtonEdge = intFloatingButtonEdge;
224+
double offsetFromTop = [floatingButtonTopOffset doubleValue];
225+
IBGBugReporting.floatingButtonTopOffset = offsetFromTop;
226+
}
227+
215228
/**
216229
* Appends a set of tags to previously added tags of reported feedback, bug or crash.
217230
* @param tags An array of tags to append to current tags.
@@ -1005,6 +1018,9 @@ + (NSDictionary *)constants {
10051018
@"ColorTheme.dark": @(IBGColorThemeDark),
10061019
@"ColorTheme.light": @(IBGColorThemeLight),
10071020

1021+
@"FloatingButtonEdge.left": @(CGRectMinXEdge),
1022+
@"FloatingButtonEdge.right": @(CGRectMaxXEdge),
1023+
10081024
@"InvocationOption.commentFieldRequired": @(IBGBugReportingOptionCommentFieldRequired),
10091025
@"InvocationOption.disablePostSendingDialog": @(IBGBugReportingOptionDisablePostSendingDialog),
10101026
@"InvocationOption.emailFieldHidden": @(IBGBugReportingOptionEmailFieldHidden),

lib/BugReporting.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ enum ExtendedBugReportMode {
2323
disabled
2424
}
2525

26+
enum FloatingButtonEdge { left, right }
27+
2628
class BugReporting {
2729
static Function? _onInvokeCallback;
2830
static Function? _onDismissCallback;
@@ -162,6 +164,19 @@ class BugReporting {
162164
await _channel.invokeMethod<Object>('setInvocationOptions:', params);
163165
}
164166

167+
/// Sets the floating button position.
168+
/// [floatingButtonEdge] FloatingButtonEdge enum - left or right edge of the screen.
169+
/// [offsetFromTop] integer offset for the position on the y-axis.
170+
static Future<void> setFloatingButtonEdge(
171+
FloatingButtonEdge floatingButtonEdge, int offsetFromTop) async {
172+
final List<dynamic> params = <dynamic>[
173+
floatingButtonEdge.toString(),
174+
offsetFromTop
175+
];
176+
await _channel.invokeMethod<Object>(
177+
'setFloatingButtonEdge:withTopOffset:', params);
178+
}
179+
165180
/// Invoke bug reporting with report type and options.
166181
/// [reportType] type
167182
/// [invocationOptions] List of invocation options

test/instabug_flutter_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,24 @@ void main() {
253253
]);
254254
});
255255

256+
test(
257+
'test setFloatingButtonEdge should be called with arguments floatingButtonEdge and offsetFromTop',
258+
() async {
259+
const FloatingButtonEdge floatingButtonEdge = FloatingButtonEdge.left;
260+
const int offsetFromTop = 300;
261+
await BugReporting.setFloatingButtonEdge(floatingButtonEdge, offsetFromTop);
262+
final List<dynamic> args = <dynamic>[
263+
floatingButtonEdge.toString(),
264+
offsetFromTop
265+
];
266+
expect(log, <Matcher>[
267+
isMethodCall(
268+
'setFloatingButtonEdge:withTopOffset:',
269+
arguments: args,
270+
)
271+
]);
272+
});
273+
256274
test('test appendTags should be called with argument List of strings',
257275
() async {
258276
const List<String> tags = ['tag1', 'tag2'];

0 commit comments

Comments
 (0)