Skip to content

Commit de700ff

Browse files
authored
[Mob 3202] - [MOB-3208]: Flutter API [Surveys] (#59)
* Android API Mappings * IOS API Mapping * Flutter API Mapping * Adds tests for new API * updates Readme * updated Changelog ## Mapped APIs: * Surveys.setEnabled * setAutoShowingEnabled * getAvailableSurveys * setOnShowCallback * setOnDismissCallback * setShouldShowWelcomeScreen * showSurveyIfAvailable
1 parent 15d39b2 commit de700ff

File tree

9 files changed

+373
-10
lines changed

9 files changed

+373
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Master
22

3+
* Adds showSurveyIfAvailable API mapping.
4+
* Adds setShouldShowWelcomeScreen API mapping.
5+
* Adds setOnDismissCallback API mapping.
6+
* Adds setOnShowCallback API mapping.
7+
* Adds getAvailableSurveys API mapping.
8+
* Adds setAutoShowingEnabled API mapping.
9+
* Adds Surveys.setEnabled API mapping.
310
* Adds showWithOptions API mapping.
411
* Adds setInvocationOptions API mapping.
512
* Adds setExtendedBugReportMode API mapping.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
8181

8282
| API Method | Native Equivalent (Android/iOS) |
8383
|-----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
84-
| | `setState(Feature.State state)`<br>`enabled` |
85-
| | `setAutoShowingEnabled(boolean isAutoShowingEnabled)`<br>`autoShowingEnabled` |
86-
| | `getAvailableSurveys()`<br>`+ availableSurveys` |
87-
| | `setOnShowCallback(OnShowCallback onShowCallback)`<br>`willShowSurveyHandler` |
88-
| | `setOnDismissCallback(OnDismissCallback onDismissCallback)`<br>`didDismissSurveyHandler` |
89-
| | `setShouldShowWelcomeScreen(boolean shouldShow)`<br>`shouldShowWelcomeScreen` |
90-
| | `showSurveyIfAvailable()`<br>`+ showSurveyIfAvailable` |
84+
| `setEnabled(bool isEnabled)` | `setState(Feature.State state)`<br>`enabled` |
85+
| `setAutoShowingEnabled(bool isEnabled)` | `setAutoShowingEnabled(boolean isAutoShowingEnabled)`<br>`autoShowingEnabled` |
86+
| `getAvailableSurveys(Function function)` | `getAvailableSurveys()`<br>`+ availableSurveys` |
87+
| `setOnShowCallback(Function function)` | `setOnShowCallback(OnShowCallback onShowCallback)`<br>`willShowSurveyHandler` |
88+
| `setOnDismissCallback(Function function)` | `setOnDismissCallback(OnDismissCallback onDismissCallback)`<br>`didDismissSurveyHandler` |
89+
| `setShouldShowWelcomeScreen(bool shouldShowWelcomeScreen)` | `setShouldShowWelcomeScreen(boolean shouldShow)`<br>`shouldShowWelcomeScreen` |
90+
| `showSurveyIfAvailable()` | `showSurveyIfAvailable()`<br>`+ showSurveyIfAvailable` |
9191
| | `showSurvey(String token)`<br>`+ showSurveyWithToken:` |
9292
| | `setThresholdForReshowingSurveyAfterDismiss(int sessionsCount, int daysCount)`<br>`+ setThresholdForReshowingSurveyAfterDismiss:daysCount:` |
9393
| | `hasRespondToSurvey(String token)`<br>`+ hasRespondedToSurveyWithToken:` |

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ android {
3434
}
3535

3636
dependencies {
37-
implementation 'com.instabug.library:instabug:8.1.2'
37+
implementation 'com.instabug.library:instabug:8.2.0'
3838
testImplementation 'junit:junit:4.12'
3939
}

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import com.instabug.library.invocation.OnInvokeCallback;
2121
import com.instabug.library.logging.InstabugLog;
2222
import com.instabug.library.ui.onboarding.WelcomeMessage;
23+
import com.instabug.survey.OnDismissCallback;
24+
import com.instabug.survey.OnShowCallback;
25+
import com.instabug.survey.Survey;
26+
import com.instabug.survey.Surveys;
2327

2428
import java.io.File;
2529
import java.lang.reflect.InvocationTargetException;
@@ -613,4 +617,94 @@ public void showBugReportingWithReportTypeAndOptions(final String reportType, fi
613617
int reportTypeInt = ArgsRegistry.getDeserializedValue(reportType, Integer.class);
614618
BugReporting.show(reportTypeInt,options);
615619
}
620+
621+
/**
622+
* Show any valid survey if exist
623+
*
624+
* @param {isEnabled} boolean
625+
*/
626+
public void setSurveysEnabled(final boolean isEnabled) {
627+
new Handler(Looper.getMainLooper()).post(new Runnable() {
628+
@Override
629+
public void run() {
630+
if (isEnabled) {
631+
Surveys.setState(Feature.State.ENABLED);
632+
} else {
633+
Surveys.setState(Feature.State.DISABLED);
634+
}
635+
}
636+
});
637+
}
638+
639+
/**
640+
* Set Surveys auto-showing state, default state auto-showing enabled
641+
*
642+
* @param isEnabled whether Surveys should be auto-showing or not
643+
*/
644+
public void setAutoShowingSurveysEnabled(boolean isEnabled) {
645+
Surveys.setAutoShowingEnabled(isEnabled);
646+
}
647+
648+
/**
649+
* Sets the runnable that gets executed just before showing any valid survey<br/>
650+
* WARNING: This runs on your application's main UI thread. Please do not include
651+
* any blocking operations to avoid ANRs.
652+
*/
653+
public void setOnShowSurveyCallback() {
654+
Surveys.setOnShowCallback(new OnShowCallback() {
655+
@Override
656+
public void onShow() {
657+
channel.invokeMethod("onShowSurveyCallback", null);
658+
}
659+
});
660+
}
661+
662+
/**
663+
* Sets the runnable that gets executed just after showing any valid survey<br/>
664+
* WARNING: This runs on your application's main UI thread. Please do not include
665+
* any blocking operations to avoid ANRs.
666+
*
667+
*/
668+
public void setOnDismissSurveyCallback() {
669+
670+
Surveys.setOnDismissCallback(new OnDismissCallback() {
671+
@Override
672+
public void onDismiss() {
673+
channel.invokeMethod("onDismissSurveyCallback", null);
674+
}
675+
});
676+
}
677+
678+
/**
679+
* Returns an array containing the available surveys.*
680+
*/
681+
public void getAvailableSurveys() {
682+
List<Survey> availableSurveys = Surveys.getAvailableSurveys();
683+
ArrayList<String> result = new ArrayList<>();
684+
for (Survey obj : availableSurveys) {
685+
result.add(obj.getTitle());
686+
}
687+
channel.invokeMethod("availableSurveysCallback", result);
688+
}
689+
690+
691+
/**
692+
* Set Surveys welcome screen enabled, default value is false
693+
*
694+
* @param shouldShow shouldShow whether should a welcome screen be shown
695+
* before taking surveys or not
696+
*/
697+
public void setShouldShowSurveysWelcomeScreen(boolean shouldShow) {
698+
Surveys.setShouldShowWelcomeScreen(shouldShow);
699+
}
700+
701+
/**
702+
* Show any valid survey if exist
703+
*
704+
* @return true if a valid survey was shown otherwise false
705+
*/
706+
public void showSurveysIfAvailable() {
707+
Surveys.showSurveyIfAvailable();
708+
}
709+
616710
}

example/lib/main.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
66
import 'package:instabug_flutter/Instabug.dart';
77
import 'package:instabug_flutter/BugReporting.dart';
88
import 'package:instabug_flutter/InstabugLog.dart';
9+
import 'package:instabug_flutter/Surveys.dart';
910

1011
void main() => runApp(MyApp());
1112

@@ -66,10 +67,15 @@ class _MyAppState extends State<MyApp> {
6667
BugReporting.setOnInvokeCallback(sdkInvoked);
6768
BugReporting.setOnDismissCallback(sdkDismissed);
6869
BugReporting.setInvocationEvents(<InvocationEvent>[InvocationEvent.floatingButton]);
70+
Surveys.setEnabled(true);
71+
Surveys.setAutoShowingEnabled(false);
72+
Surveys.setOnShowCallback(surveyShown);
73+
Surveys.setOnDismissCallback(surveyDismiss);
6974
//BugReporting.setEnabledAttachmentTypes(false, false, false, false);
7075
//BugReporting.setReportTypes(<ReportType>[ReportType.FEEDBACK,ReportType.BUG]);
7176
//BugReporting.setExtendedBugReportMode(ExtendedBugReportMode.ENABLED_WITH_REQUIRED_FIELDS);
7277
//BugReporting.setInvocationOptions(<InvocationOption>[InvocationOption.EMAIL_FIELD_HIDDEN]);
78+
7379
} on PlatformException {
7480
platformVersion = 'Failed to get platform version.';
7581
}
@@ -87,18 +93,34 @@ class _MyAppState extends State<MyApp> {
8793
Instabug.resetTags();
8894
}
8995

96+
void getSurveys(List<String> surveys) {
97+
int x = surveys.length;
98+
debugPrint(x.toString());
99+
}
100+
90101
void sdkInvoked() {
91102
debugPrint("I am called before invocation");
92103
}
93104

105+
void surveyShown() {
106+
debugPrint("The user will se a survey nwoww");
107+
}
108+
109+
void surveyDismiss() {
110+
debugPrint("The survey is Dismissed");
111+
}
112+
94113
void sdkDismissed(DismissType dismissType, ReportType reportType) {
95114
debugPrint('SDK Dismissed DismissType: ' + dismissType.toString());
96115
debugPrint('SDK Dismissed ReportType: ' + reportType.toString());
97116
}
98117

99118
void show() {
100119
//Instabug.show();
101-
BugReporting.showWithOptions(ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
120+
Surveys.getAvailableSurveys(getSurveys);
121+
Surveys.showSurveyIfAvailable();
122+
Surveys.setShouldShowWelcomeScreen(true);
123+
//BugReporting.showWithOptions(ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
102124
}
103125

104126
void invokeWithMode() {

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,86 @@ + (void)showBugReportingWithReportTypeAndOptions:(NSString*)reportType options:(
511511
[IBGBugReporting showWithReportType:reportTypeInt options:invocationOptions];
512512
}
513513

514+
/**
515+
* Show any valid survey if exist
516+
*
517+
* @param {isEnabled} boolean
518+
*/
519+
+ (void)setSurveysEnabled:(NSNumber *)isEnabled {
520+
BOOL boolValue = [isEnabled boolValue];
521+
IBGSurveys.enabled = boolValue;
522+
}
523+
524+
/**
525+
* Set Surveys auto-showing state, default state auto-showing enabled
526+
*
527+
* @param {isEnabled} whether Surveys should be auto-showing or not
528+
*/
529+
+ (void)setAutoShowingSurveysEnabled:(NSNumber *)isEnabled {
530+
BOOL boolValue = [isEnabled boolValue];
531+
IBGSurveys.autoShowingEnabled = boolValue;
532+
}
533+
534+
535+
/**
536+
* Sets the runnable that gets executed just before showing any valid survey<br/>
537+
* WARNING: This runs on your application's main UI thread. Please do not include
538+
* any blocking operations to avoid ANRs.
539+
*/
540+
+ (void)setOnShowSurveyCallback {
541+
IBGSurveys.willShowSurveyHandler = ^{
542+
[channel invokeMethod:@"onShowSurveyCallback" arguments:nil];
543+
};
544+
}
545+
546+
/**
547+
* Sets the runnable that gets executed just after showing any valid survey<br/>
548+
* WARNING: This runs on your application's main UI thread. Please do not include
549+
* any blocking operations to avoid ANRs.
550+
*
551+
*/
552+
+ (void)setOnDismissSurveyCallback {
553+
IBGSurveys.didDismissSurveyHandler = ^{
554+
[channel invokeMethod:@"onDismissSurveyCallback" arguments:nil];
555+
};
556+
}
557+
558+
/**
559+
* Sets a block of code to be executed right after the SDK's UI is dismissed.
560+
* This block is executed on the UI thread. Could be used for performing any
561+
* UI changes after the SDK's UI is dismissed.
562+
*/
563+
+ (void)getAvailableSurveys {
564+
NSArray<IBGSurvey *> *surveys = [IBGSurveys availableSurveys];
565+
NSMutableArray <NSString *> *surveysArray = [[NSMutableArray alloc] init];
566+
for (IBGSurvey * survey in surveys) {
567+
[surveysArray addObject:survey.title];
568+
}
569+
NSArray *result = [surveysArray copy];
570+
[channel invokeMethod:@"availableSurveysCallback" arguments:result];
571+
}
572+
573+
574+
/**
575+
* Set Surveys auto-showing state, default state auto-showing enabled
576+
*
577+
* @param {isEnabled} whether Surveys should be auto-showing or not
578+
*/
579+
+ (void)setShouldShowSurveysWelcomeScreen:(NSNumber *)shouldShowWelcomeScreen {
580+
BOOL boolValue = [shouldShowWelcomeScreen boolValue];
581+
IBGSurveys.shouldShowWelcomeScreen = boolValue;
582+
}
583+
584+
/**
585+
* Show any valid survey if exist
586+
*
587+
* @return true if a valid survey was shown otherwise false
588+
*/
589+
+ (void)showSurveysIfAvailable {
590+
[IBGSurveys showSurveyIfAvailable];
591+
}
592+
593+
514594
+ (NSDictionary *)constants {
515595
return @{
516596
@"InvocationEvent.shake": @(IBGInvocationEventShake),

ios/instabug_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A new flutter plugin project.
1515
s.source_files = 'Classes/**/*'
1616
s.public_header_files = 'Classes/**/*.h'
1717
s.dependency 'Flutter'
18-
s.dependency 'Instabug', '8.1'
18+
s.dependency 'Instabug', '8.2.2'
1919

2020
s.ios.deployment_target = '10.0'
2121
end

0 commit comments

Comments
 (0)