From 01f7a6ba7b6628a5891ed92bfeeceff66ca1cdfd Mon Sep 17 00:00:00 2001 From: Jignesh Date: Thu, 5 Nov 2020 03:12:04 +0530 Subject: [PATCH] Added support for setToolbarTintColor & setToolbarBarTintColor --- README.md | 2 ++ .../ReactNativeKeyboardManager.m | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index c46c8c9..8fb9e96 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ if (Platform.OS === 'ios') { KeyboardManager.setToolbarManageBehaviour(0); KeyboardManager.setToolbarPreviousNextButtonEnable(false); KeyboardManager.setShouldToolbarUsesTextFieldTintColor(false); + KeyboardManager.setToolbarTintColor('#0000FF'); + KeyboardManager.setToolbarBarTintColor('#FFFFFF'); KeyboardManager.setShouldShowTextFieldPlaceholder(true); // deprecated, use setShouldShowToolbarPlaceholder KeyboardManager.setShouldShowToolbarPlaceholder(true); KeyboardManager.setOverrideKeyboardAppearance(false); diff --git a/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m b/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m index b1fb99e..ca742c2 100644 --- a/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m +++ b/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m @@ -52,6 +52,14 @@ void Swizzle(Class c, SEL orig, SEL new) method_exchangeImplementations(origMethod, newMethod); } +- (UIColor *)colorFromHexString:(NSString *)hexString { + unsigned rgbValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:hexString]; + [scanner setScanLocation:1]; // bypass '#' character + [scanner scanHexInt:&rgbValue]; + return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; +} + + (BOOL)requiresMainQueueSetup { return YES; @@ -109,6 +117,21 @@ + (BOOL)requiresMainQueueSetup [[IQKeyboardManager sharedManager] setShouldToolbarUsesTextFieldTintColor:enabled]; } +RCT_EXPORT_METHOD(setToolbarTintColor: (NSString*) hexString) { + dispatch_sync(dispatch_get_main_queue(), ^{ + if (debugging) RCTLogInfo(@"KeyboardManager.setToolbarTintColor: %@", hexString); + UIColor* toolbarTintColor = [self colorFromHexString:hexString]; + [[IQKeyboardManager sharedManager] setToolbarTintColor: toolbarTintColor]; + }); +} + +RCT_EXPORT_METHOD(setToolbarBarTintColor: (NSString*) hexString) { + dispatch_sync(dispatch_get_main_queue(), ^{ + if (debugging) RCTLogInfo(@"KeyboardManager.setToolbarBarTintColor: %@", hexString); + UIColor* toolbarBarTintColor = [self colorFromHexString:hexString]; + [[IQKeyboardManager sharedManager] setToolbarBarTintColor: toolbarBarTintColor]; + }); +} RCT_EXPORT_METHOD(shouldShowToolbarPlaceholder: (BOOL) enabled) { if (debugging) RCTLogInfo(@"KeyboardManager.shouldShowToolbarPlaceholder: %d", enabled);