Skip to content

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

AyaMahmoud148
Copy link
Contributor

Description of the change

Support Advanced UI customization

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Issue links go here

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests

Code review

  • This pull request has a descriptive title and information useful to a reviewer
  • Issue from task tracker has a link to this pull request

@InstabugCI
Copy link
Collaborator

Coverage Report

Label Coverage Status
JavaScript 90.3%
Android 49.9%
iOS 50.7%

Generated by 🚫 dangerJS against c5409f0

Comment on lines +1508 to +1517
try {
Typeface typeface = Typeface.createFromAsset(getReactApplicationContext().getAssets(), "fonts/" + fileName);
return typeface;
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
Copy link
Contributor

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 ?

Comment on lines +1488 to +1495
try {
Typeface typeface = Typeface.create(fileName, Typeface.NORMAL);
if (typeface != null && !typeface.equals(Typeface.DEFAULT)) {
return typeface;
}
} catch (Exception e) {
e.printStackTrace();
}
Copy link
Contributor

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

Comment on lines +179 to +273
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;
}
}
Copy link
Contributor

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);
        }
    }
}

Comment on lines +277 to +283
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;
}
Copy link
Contributor

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

@kholood-ea
Copy link
Contributor

Great effort @AyaMahmoud148 👏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants