Skip to content

Commit 542b32e

Browse files
Merge pull request #69 from jigs611989/toolbarTintColor
Added support for setToolbarTintColor & setToolbarBarTintColor
2 parents 31707a3 + 01f7a6b commit 542b32e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ if (Platform.OS === 'ios') {
100100
KeyboardManager.setToolbarManageBehaviour(0);
101101
KeyboardManager.setToolbarPreviousNextButtonEnable(false);
102102
KeyboardManager.setShouldToolbarUsesTextFieldTintColor(false);
103+
KeyboardManager.setToolbarTintColor('#0000FF');
104+
KeyboardManager.setToolbarBarTintColor('#FFFFFF');
103105
KeyboardManager.setShouldShowTextFieldPlaceholder(true); // deprecated, use setShouldShowToolbarPlaceholder
104106
KeyboardManager.setShouldShowToolbarPlaceholder(true);
105107
KeyboardManager.setOverrideKeyboardAppearance(false);

ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ void Swizzle(Class c, SEL orig, SEL new)
5252
method_exchangeImplementations(origMethod, newMethod);
5353
}
5454

55+
- (UIColor *)colorFromHexString:(NSString *)hexString {
56+
unsigned rgbValue = 0;
57+
NSScanner *scanner = [NSScanner scannerWithString:hexString];
58+
[scanner setScanLocation:1]; // bypass '#' character
59+
[scanner scanHexInt:&rgbValue];
60+
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
61+
}
62+
5563
+ (BOOL)requiresMainQueueSetup
5664
{
5765
return YES;
@@ -109,6 +117,21 @@ + (BOOL)requiresMainQueueSetup
109117
[[IQKeyboardManager sharedManager] setShouldToolbarUsesTextFieldTintColor:enabled];
110118
}
111119

120+
RCT_EXPORT_METHOD(setToolbarTintColor: (NSString*) hexString) {
121+
dispatch_sync(dispatch_get_main_queue(), ^{
122+
if (debugging) RCTLogInfo(@"KeyboardManager.setToolbarTintColor: %@", hexString);
123+
UIColor* toolbarTintColor = [self colorFromHexString:hexString];
124+
[[IQKeyboardManager sharedManager] setToolbarTintColor: toolbarTintColor];
125+
});
126+
}
127+
128+
RCT_EXPORT_METHOD(setToolbarBarTintColor: (NSString*) hexString) {
129+
dispatch_sync(dispatch_get_main_queue(), ^{
130+
if (debugging) RCTLogInfo(@"KeyboardManager.setToolbarBarTintColor: %@", hexString);
131+
UIColor* toolbarBarTintColor = [self colorFromHexString:hexString];
132+
[[IQKeyboardManager sharedManager] setToolbarBarTintColor: toolbarBarTintColor];
133+
});
134+
}
112135

113136
RCT_EXPORT_METHOD(shouldShowToolbarPlaceholder: (BOOL) enabled) {
114137
if (debugging) RCTLogInfo(@"KeyboardManager.shouldShowToolbarPlaceholder: %d", enabled);

0 commit comments

Comments
 (0)