Skip to content

Commit 442fd50

Browse files
authored
[MOB-10572] Add new APIs (#295)
* Add `Instabug.setEnabled` API * Add Instabug.setEnabled unit test * Deprecate enableAndroid and disableAndroid APIs * Add `setDisclaimerText` API * Add setDisclaimerText unit test * Add `setCommentMinimumCharacterCount` API * Add setCommentMinimumCharacterCount unit test * Update CHANGELOG.md * Add doc comment setCommentMinimumCharacterCount * Keep annotations after doc comments
1 parent 4788fff commit 442fd50

File tree

11 files changed

+128
-0
lines changed

11 files changed

+128
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Unreleased
22

3+
* Adds BugReporting.setDisclaimerText API
4+
* Adds BugReporting.setCommentMinimumCharacterCount API
5+
* Deprecates Instabug.enableAndroid and Instabug.disableAndroid APIs in favour of a new API Instabug.setEnabled, which works on both platforms
36
* Fixes main thread violation on Android
47
* Fixes an issue with request and response headers parameters type causing network requests not getting logged on iOS
58
* Uses pigeon for internal communication between Flutter and the host platform

android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,21 @@ public void reply(Void reply) {
149149
}
150150
});
151151
}
152+
153+
@Override
154+
public void setDisclaimerText(@NonNull String text) {
155+
BugReporting.setDisclaimerText(text);
156+
}
157+
158+
@Override
159+
public void setCommentMinimumCharacterCount(@NonNull Long limit, @Nullable List<String> reportTypes) {
160+
int[] reportTypesArray = reportTypes == null ? new int[0] : new int[reportTypes.size()];
161+
if(reportTypes != null){
162+
for (int i = 0; i < reportTypes.size(); i++) {
163+
String key = reportTypes.get(i);
164+
reportTypesArray[i] = ArgsRegistry.getDeserializedValue(key);
165+
}
166+
}
167+
BugReporting.setCommentMinimumCharacterCount(limit.intValue(), reportTypesArray);
168+
}
152169
}

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ private void setCurrentPlatform() {
7373
}
7474
}
7575

76+
@Override
77+
public void setEnabled(@NonNull Boolean isEnabled) {
78+
try {
79+
if(isEnabled)
80+
Instabug.enable();
81+
else
82+
Instabug.disable();
83+
} catch (Exception e) {
84+
e.printStackTrace();
85+
}
86+
}
87+
7688
public void start(@NonNull String token, @NonNull List<String> invocationEvents) {
7789
setCurrentPlatform();
7890

ios/Classes/Modules/BugReportingApi.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,23 @@ - (void)bindOnDismissCallbackWithError:(FlutterError *_Nullable *_Nonnull)error
146146
};
147147
}
148148

149+
- (void)setDisclaimerTextText:(NSString *)text error:(FlutterError *_Nullable *_Nonnull)error {
150+
[IBGBugReporting setDisclaimerText:text];
151+
}
152+
153+
- (void)setCommentMinimumCharacterCountLimit:(NSNumber *)limit reportTypes:(nullable NSArray<NSString *> *)reportTypes error:(FlutterError *_Nullable *_Nonnull)error {
154+
IBGBugReportingReportType resolvedTypes = 0;
155+
156+
if (![reportTypes count]) {
157+
resolvedTypes = (ArgsRegistry.reportTypes[@"ReportType.bug"]).integerValue | (ArgsRegistry.reportTypes[@"ReportType.feedback"]).integerValue | (ArgsRegistry.reportTypes[@"ReportType.question"]).integerValue;
158+
}
159+
else {
160+
for (NSString *reportType in reportTypes) {
161+
resolvedTypes |= (ArgsRegistry.reportTypes[reportType]).integerValue;
162+
}
163+
}
164+
165+
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:resolvedTypes withLimit:limit.intValue];
166+
}
167+
149168
@end

ios/Classes/Modules/InstabugApi.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ extern void InitInstabugApi(id<FlutterBinaryMessenger> messenger) {
1313

1414
@implementation InstabugApi
1515

16+
- (void)setEnabledIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nullable *_Nonnull)error {
17+
Instabug.enabled = [isEnabled boolValue];
18+
}
19+
1620
- (void)startToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invocationEvents error:(FlutterError *_Nullable *_Nonnull)error {
1721
SEL setPrivateApiSEL = NSSelectorFromString(@"setCurrentPlatform:");
1822
if ([[Instabug class] respondsToSelector:setPrivateApiSEL]) {

lib/src/modules/bug_reporting.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,26 @@ class BugReporting implements BugReportingFlutterApi {
227227
return _host.setShakingThresholdForAndroid(threshold);
228228
}
229229
}
230+
231+
/// Adds a disclaimer text within the bug reporting form,
232+
/// which can include hyperlinked text.
233+
/// [text] String text
234+
static Future<void> setDisclaimerText(String text) async {
235+
return _host.setDisclaimerText(text);
236+
}
237+
238+
/// Sets a minimum number of characters as a requirement for
239+
/// the comments field in the different report types.
240+
/// [limit] int number of characters
241+
/// [reportTypes] Optional list of ReportType. If it's not passed,
242+
/// the limit will apply to all report types.
243+
static Future<void> setCommentMinimumCharacterCount(
244+
int limit, [
245+
List<ReportType>? reportTypes,
246+
]) async {
247+
return _host.setCommentMinimumCharacterCount(
248+
limit,
249+
reportTypes?.mapToString(),
250+
);
251+
}
230252
}

lib/src/modules/instabug.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ class Instabug {
129129
Surveys.init();
130130
}
131131

132+
/// Enables or disables Instabug functionality.
133+
/// [boolean] isEnabled
134+
static Future<void> setEnabled(bool isEnabled) async {
135+
return _host.setEnabled(isEnabled);
136+
}
137+
132138
/// Starts the SDK.
133139
/// This is the main SDK method that does all the magic. This is the only
134140
/// method that SHOULD be called.
@@ -341,6 +347,9 @@ class Instabug {
341347

342348
/// Android Only
343349
/// Enables all Instabug functionality
350+
@Deprecated(
351+
"Use [Instabug.setEnabled(true)] instead. This will work on both Android and iOS. ",
352+
)
344353
static Future<void> enableAndroid() async {
345354
if (IBGBuildInfo.I.isAndroid) {
346355
return _host.enableAndroid();
@@ -349,6 +358,9 @@ class Instabug {
349358

350359
/// Android Only
351360
/// Disables all Instabug functionality
361+
@Deprecated(
362+
"Use [Instabug.setEnabled(false)] instead. This will work on both Android and iOS. ",
363+
)
352364
static Future<void> disableAndroid() async {
353365
if (IBGBuildInfo.I.isAndroid) {
354366
return _host.disableAndroid();

pigeons/bug_reporting.api.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ abstract class BugReportingHostApi {
2727
);
2828
void bindOnInvokeCallback();
2929
void bindOnDismissCallback();
30+
void setDisclaimerText(String text);
31+
void setCommentMinimumCharacterCount(
32+
int limit,
33+
List<String>? reportTypes,
34+
);
3035
}

pigeons/instabug.api.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:pigeon/pigeon.dart';
22

33
@HostApi()
44
abstract class InstabugHostApi {
5+
void setEnabled(bool isEnabled);
56
void start(String token, List<String> invocationEvents);
67

78
void show();

test/bug_reporting_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,25 @@ void main() {
178178
mHost.bindOnDismissCallback(),
179179
).called(1);
180180
});
181+
182+
test('[setDisclaimerText] should call host method', () async {
183+
const text = 'This is a disclaimer text!';
184+
185+
await BugReporting.setDisclaimerText(text);
186+
187+
verify(
188+
mHost.setDisclaimerText(text),
189+
).called(1);
190+
});
191+
192+
test('[setCommentMinimumCharacterCount] should call host method', () async {
193+
const count = 20;
194+
const reportTypes = [ReportType.bug];
195+
196+
await BugReporting.setCommentMinimumCharacterCount(count, reportTypes);
197+
198+
verify(
199+
mHost.setCommentMinimumCharacterCount(count, reportTypes.mapToString()),
200+
).called(1);
201+
});
181202
}

0 commit comments

Comments
 (0)