Commit 6e52d4a9 by Ben Getsug

attempt fixing ios background color

parent da7609f5
...@@ -9,85 +9,84 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -9,85 +9,84 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
} }
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:CHANNEL_NAME methodChannelWithName:CHANNEL_NAME
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
UIViewController *viewController = UIViewController *viewController =
[UIApplication sharedApplication].delegate.window.rootViewController; [UIApplication sharedApplication].delegate.window.rootViewController;
FluttertoastPlugin* instance = [[FluttertoastPlugin alloc] init]; FluttertoastPlugin *instance = [[FluttertoastPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel]; [registrar addMethodCallDelegate:instance channel:channel];
} }
- (unsigned int)intFromHexString:(NSString *)hexStr { - (unsigned int)intFromHexString:(NSString *)hexStr {
unsigned int hexInt = 0; unsigned int hexInt = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexStr]; NSScanner *scanner = [NSScanner scannerWithString:hexStr];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
[scanner scanHexInt:&hexInt]; [scanner scanHexInt:&hexInt];
return hexInt; return hexInt;
} }
- (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha - (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha {
{
// Convert hex string to an integer // Convert hex string to an integer
unsigned int hexint = [self intFromHexString:hexStr]; unsigned int hexint = [self intFromHexString:hexStr];
// Create color object, specifying alpha as well // Create color object, specifying alpha as well
UIColor *color = UIColor *color =
[UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255 [UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16)) / 255
green:((CGFloat) ((hexint & 0xFF00) >> 8))/255 green:((CGFloat) ((hexint & 0xFF00) >> 8)) / 255
blue:((CGFloat) (hexint & 0xFF))/255 blue:((CGFloat) (hexint & 0xFF)) / 255
alpha:alpha]; alpha:alpha];
return color; return color;
} }
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"showToast" isEqualToString:call.method]) { if ([@"showToast" isEqualToString:call.method]) {
NSString *msg = call.arguments[@"msg"]; NSString *msg = call.arguments[@"msg"];
NSString *gravity = call.arguments[@"gravity"]; NSString *gravity = call.arguments[@"gravity"];
NSString *durationTime = call.arguments[@"time"]; NSString *durationTime = call.arguments[@"time"];
NSString *bgcolor = call.arguments[@"bgcolor"]; NSString *bgcolor = call.arguments[@"bgcolor"];
NSString *textcolor = call.arguments[@"textcolor"]; NSString *textcolor = call.arguments[@"textcolor"];
int time = 1; int time = 1;
@try{ @try {
time = [durationTime intValue]; time = [durationTime intValue];
} @catch(NSException *e){ } @catch (NSException *e) {
time = 3; time = 3;
} }
if(time > 10 ) time = 10; if (time > 10) time = 10;
else if(time < 1) time = 1; else if (time < 1) time = 1;
CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
if(![bgcolor isEqualToString:@"null"]) { if (![bgcolor isEqualToString:@"null"]) {
style.self.backgroundColor = [self getUIColorObjectFromHexString:bgcolor alpha:1.0]; style.backgroundColor = [self getUIColorObjectFromHexString:bgcolor alpha:1.0];
} }
if(![textcolor isEqualToString:@"null"]) { if (![textcolor isEqualToString:@"null"]) {
style.messageColor = [self getUIColorObjectFromHexString:textcolor alpha:1.0]; style.messageColor = [self getUIColorObjectFromHexString:textcolor alpha:1.0];
} }
if([gravity isEqualToString:@"top"]) { if ([gravity isEqualToString:@"top"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time duration:time
position:CSToastPositionTop position:CSToastPositionTop
style:style]; style:style];
} else if([gravity isEqualToString:@"center"]) { } else if ([gravity isEqualToString:@"center"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time duration:time
position:CSToastPositionCenter position:CSToastPositionCenter
style:style]; style:style];
} else { } else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time duration:time
position:CSToastPositionBottom position:CSToastPositionBottom
style:style]; style:style];
} }
result(@"done"); result(@"done");
} else { } else {
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment