Skip to content

Commit

Permalink
Added support for setToolbarTintColor & setToolbarBarTintColor
Browse files Browse the repository at this point in the history
  • Loading branch information
jigs611989 committed Nov 4, 2020
1 parent 31707a3 commit 01f7a6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 01f7a6b

Please sign in to comment.