Skip to content

Commit 748eb40

Browse files
authored
[Mob 3186] - Flutter API: tintColor (#53)
Android API Mapping IOS API Mapping Flutter API Mapping Adds tests for new API updates Readme updated Changelog
1 parent bb00436 commit 748eb40

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
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 setPrimaryColor API mapping.
34
* Adds setSessionProfilerEnabled API mapping.
45

56
## Version 0.0.3 (2019-03-21)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
4343
| `logUserEventWithName(String name)` | `logUserEvent(String name)`<br>`+ logUserEventWithName:` |
4444
| `show()` | `show()`<br>`+ show` |
4545
| `setSessionProfilerEnabled(bool sessionProfilerEnabled)` | `setSessionProfilerState(Feature.State state)`<br>`sessionProfilerEnabled` |
46-
| | `setPrimaryColor(@ColorInt int primaryColorValue)`<br>`tintColor` |
46+
|`setPrimaryColor(Color color)` | `setPrimaryColor(@ColorInt int primaryColorValue)`<br>`tintColor` |
4747
| | `onReportSubmitHandler(Report.OnReportCreatedListener listener)`<br>`willSendReportHandler`. |
4848
| | `setUserData(String userData)`<br>`userData` |
4949
| | `addFileAttachment(Uri fileUri, String fileNameWithExtension)`<br>`+ addFileAttachmentWithURL:` |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,18 @@ public void setSessionProfilerEnabled(boolean sessionProfilerEnabled) {
400400
Instabug.setSessionProfilerState(Feature.State.DISABLED);
401401
}
402402
}
403+
404+
/**
405+
* Set the primary color that the SDK will use to tint certain UI elements in the SDK
406+
*
407+
* @param primaryColor The value of the primary color
408+
*/
409+
public void setPrimaryColor(final long primaryColor) {
410+
new Handler(Looper.getMainLooper()).post(new Runnable() {
411+
@Override
412+
public void run() {
413+
Instabug.setPrimaryColor((int)primaryColor);
414+
}
415+
});
416+
}
403417
}

example/lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class _MyAppState extends State<MyApp> {
5353
Instabug.setValueForStringWithKey('What\'s the problem', IBGCustomTextPlaceHolderKey.REPORT_BUG);
5454
Instabug.setValueForStringWithKey('Send some ideas', IBGCustomTextPlaceHolderKey.REPORT_FEEDBACK);
5555
Instabug.setSessionProfilerEnabled(false);
56+
Color c = const Color.fromRGBO(255, 0, 255, 1.0);
57+
Color c = const Color.fromRGBO(255, 0, 0, 1.0);
58+
Instabug.setPrimaryColor(c);
5659
} on PlatformException {
5760
platformVersion = 'Failed to get platform version.';
5861
}

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#import "InstabugFlutterPlugin.h"
22
#import "Instabug.h"
33

4+
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:((float)((rgbValue & 0xFF000000) >> 24))/255.0 ];
5+
46
@implementation InstabugFlutterPlugin
57

68

@@ -299,6 +301,16 @@ + (void) setSessionProfilerEnabled:(NSString*) sessionProfilerEnabled {
299301
[Instabug setSessionProfilerEnabled:boolValue];
300302
}
301303

304+
/**
305+
* Set the primary color that the SDK will use to tint certain UI elements in the SDK
306+
*
307+
* @param color The value of the primary color
308+
*/
309+
+ (void) setPrimaryColor:(NSString*) color {
310+
Instabug.tintColor = UIColorFromRGB([color longLongValue]);
311+
}
312+
313+
302314
+ (NSDictionary *)constants {
303315
return @{
304316
@"InvocationEvent.shake": @(IBGInvocationEventShake),

lib/Instabug.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:ui';
23
import 'package:flutter/services.dart';
34

45
enum InvocationEvent {
@@ -210,6 +211,15 @@ class Instabug {
210211
final List<dynamic> params = <dynamic>[sessionProfilerEnabled];
211212
await _channel.invokeMethod<Object>('setSessionProfilerEnabled:', params);
212213
}
214+
215+
/// Sets the primary color of the SDK's UI.
216+
/// Sets the color of UI elements indicating interactivity or call to action.
217+
/// [color] primaryColor A color to set the UI elements of the SDK to.
218+
static void setPrimaryColor(Color color) async {
219+
final List<dynamic> params = <dynamic>[color.value];
220+
await _channel.invokeMethod<Object>('setPrimaryColor:', params);
221+
}
222+
213223
}
214224

215225

test/instabug_flutter_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:io';
2+
import 'dart:ui';
23

34
import 'package:instabug_flutter/Instabug.dart';
45
import 'package:instabug_flutter/BugReporting.dart';
@@ -294,6 +295,17 @@ test('startWithToken:invocationEvents: Test', () async {
294295
]);
295296
});
296297

298+
test('setPrimaryColor: Test', () async {
299+
Color c = const Color.fromRGBO(255, 0, 255, 1.0);
300+
final List<dynamic> args = <dynamic>[c.value];
301+
Instabug.setPrimaryColor(c);
302+
expect(log, <Matcher>[
303+
isMethodCall('setPrimaryColor:',
304+
arguments: args,
305+
)
306+
]);
307+
});
308+
297309
}
298310

299311

0 commit comments

Comments
 (0)