-
Notifications
You must be signed in to change notification settings - Fork 101
feat: Support Advanced UI customization #1411
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
base: dev
Are you sure you want to change the base?
Conversation
try { | ||
Typeface typeface = Typeface.createFromAsset(getReactApplicationContext().getAssets(), "fonts/" + fileName); | ||
return typeface; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about extracting this to a new function instead of writing the same logic twice ?
try { | ||
Typeface typeface = Typeface.create(fileName, Typeface.NORMAL); | ||
if (typeface != null && !typeface.equals(Typeface.DEFAULT)) { | ||
return typeface; | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can export this to a new function for better readability
if (themeConfig[@"primaryColor"]) { | ||
NSString *colorString = themeConfig[@"primaryColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.primaryColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"backgroundColor"]) { | ||
NSString *colorString = themeConfig[@"backgroundColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.backgroundColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"titleTextColor"]) { | ||
NSString *colorString = themeConfig[@"titleTextColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.titleTextColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"subtitleTextColor"]) { | ||
NSString *colorString = themeConfig[@"subtitleTextColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.subtitleTextColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"primaryTextColor"]) { | ||
NSString *colorString = themeConfig[@"primaryTextColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.primaryTextColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"secondaryTextColor"]) { | ||
NSString *colorString = themeConfig[@"secondaryTextColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.secondaryTextColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"callToActionTextColor"]) { | ||
NSString *colorString = themeConfig[@"callToActionTextColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.callToActionTextColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"headerBackgroundColor"]) { | ||
NSString *colorString = themeConfig[@"headerBackgroundColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.headerBackgroundColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"footerBackgroundColor"]) { | ||
NSString *colorString = themeConfig[@"footerBackgroundColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.footerBackgroundColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"rowBackgroundColor"]) { | ||
NSString *colorString = themeConfig[@"rowBackgroundColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.rowBackgroundColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"selectedRowBackgroundColor"]) { | ||
NSString *colorString = themeConfig[@"selectedRowBackgroundColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.selectedRowBackgroundColor = color; | ||
} | ||
} | ||
|
||
if (themeConfig[@"rowSeparatorColor"]) { | ||
NSString *colorString = themeConfig[@"rowSeparatorColor"]; | ||
UIColor *color = [self colorFromHexString:colorString]; | ||
if (color) { | ||
theme.rowSeparatorColor = color; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about replacing the redundant "ifs" with creating a dictionary with theme colors and corresponding setters property like so
NSDictionary<NSString *, void(^)(UIColor *)> *colorSetters = @{
@"primaryColor": ^(UIColor *color) { theme.primaryColor = color; },
@"backgroundColor": ^(UIColor *color) { theme.backgroundColor = color; },
....
};
then loop on them something looks like so
for (NSString *key in colorSetters) {
void (^setter)(UIColor *) = colorSetters[key];
NSString *hexString = themeConfig[key];
if ([hexString isKindOfClass:[NSString class]]) {
UIColor *color = [self colorFromHexString:hexString];
if (color) {
setter(color);
}
}
}
NSString *fontName = themeConfig[@"primaryFontPath"]; | ||
NSString *fileName = [fontName lastPathComponent]; | ||
NSString *nameWithoutExtension = [fileName stringByDeletingPathExtension]; | ||
UIFont *font = [UIFont fontWithName:nameWithoutExtension size:17.0]; | ||
if (font) { | ||
theme.primaryTextFont = font; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also replace redundant logic for setting fonts with create one function and call it for all of them
Great effort @AyaMahmoud148 👏🏻 |
Description of the change
Type of change
Related issues
Checklists
Development
Code review