Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intForKey, floatForKey, boolForKey methods for extra theming support #5

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow fontSize to be specified rather than fontSizeKey as this allows…
… more strict theming of fonts
sam899 committed Apr 20, 2014
commit 99f48c0e905dd2f550a93d7beb56d7e2d0c086df
2 changes: 1 addition & 1 deletion Source/RNThemeLabel.h
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
<RNThemeUpdateProtocol>

@property (nonatomic, strong) NSString *fontKey;
@property (nonatomic, strong) NSString *fontSizeKey;
@property (nonatomic, strong) NSNumber *fontSize;
@property (nonatomic, strong) NSString *textColorKey;
@property (nonatomic, strong) NSString *highlightedTextColorKey;
@property (nonatomic, strong) NSString *backgroundColorKey;
11 changes: 6 additions & 5 deletions Source/RNThemeLabel.m
Original file line number Diff line number Diff line change
@@ -55,11 +55,12 @@ - (void)applyTheme {
UIFont *font = nil;

if (self.fontKey) {
// has the fontSizeKey override be provided?
if (self.fontSizeKey) {
font = [[RNThemeManager sharedManager] fontForKey:self.fontKey sizeKey:fontSizeKey];
} else {
font = [[RNThemeManager sharedManager] fontForKey:self.fontKey]
// has the fontSize override been provided?
if (self.fontSize) {
font = [[RNThemeManager sharedManager] fontForKey:self.fontKey size:[self.fontSize floatValue]];
}
else {
font = [[RNThemeManager sharedManager] fontForKey:self.fontKey];
}

if (font) {
4 changes: 2 additions & 2 deletions Source/RNThemeManager.h
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ extern NSString * const RNThemeManagerDidChangeThemes;
// If the size key is not specified, the system default will be assumed
- (UIFont *)fontForKey:(NSString*)key;

// Allows the font size key to be provided separately to the font key
- (UIFont *)fontForKey:(NSString *)key sizeKey:(NSString *)sizeKey;
// Allows the font size to be provided separately rather than using the themed style
- (UIFont *)fontForKey:(NSString *)key size:(CGFloat)size;

// Return a UIColor from a hex color stored in theme file
- (UIColor *)colorForKey:(NSString *)key;
19 changes: 14 additions & 5 deletions Source/RNThemeManager.m
Original file line number Diff line number Diff line change
@@ -100,11 +100,6 @@ - (NSDictionary *)inheritedThemeWithParentTheme:(NSString *)parentThemeName chil

- (UIFont *)fontForKey:(NSString*)key {
NSString *sizeKey = [key stringByAppendingString:@"Size"];
return [self fontForKey:key sizeKey:sizeKey];
}

- (UIFont *)fontForKey:(NSString *)key sizeKey:(NSString *)sizeKey
{
NSString *fontName = self.styles[key];

// get the font size, using default if not supplied
@@ -120,6 +115,20 @@ - (UIFont *)fontForKey:(NSString *)key sizeKey:(NSString *)sizeKey
return nil;
}

- (UIFont *)fontForKey:(NSString *)key size:(CGFloat)size
{
NSString *fontName = self.styles[key];

while (self.styles[fontName]) {
fontName = self.styles[fontName];
}

if (fontName) {
return [UIFont fontWithName:fontName size:size];
}
return nil;
}

#pragma mark - Colors

- (UIColor *)colorForKey:(NSString *)key {