-
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 ?
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 still have the same logic written twice, I was thinking something more like
public static Typeface loadTypefaceFromAssets(Context context, String fileName) {
try {
return Typeface.createFromAsset(context.getAssets(), "fonts/" + fileName);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
then drop the double try catch blocks
android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java
Show resolved
Hide resolved
Great effort @AyaMahmoud148 👏🏻 |
if (themeConfig.hasKey("primaryColor")) { | ||
builder.setPrimaryColor(getColor(themeConfig, "primaryColor")); | ||
} | ||
if (themeConfig.hasKey("secondaryTextColor")) { | ||
builder.setSecondaryTextColor(getColor(themeConfig, "secondaryTextColor")); | ||
} | ||
if (themeConfig.hasKey("primaryTextColor")) { | ||
builder.setPrimaryTextColor(getColor(themeConfig, "primaryTextColor")); | ||
} | ||
if (themeConfig.hasKey("titleTextColor")) { | ||
builder.setTitleTextColor(getColor(themeConfig, "titleTextColor")); | ||
} | ||
if (themeConfig.hasKey("backgroundColor")) { | ||
builder.setBackgroundColor(getColor(themeConfig, "backgroundColor")); | ||
} |
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.
for colors instead of adding a check for every one we can extract the logic
private void applyColorIfPresent(ReadableMap config, com.instabug.library.model.IBGTheme.Builder builder, String key, Consumer<Integer> setter) {
if (config.hasKey(key)) {
setter.accept(getColor(config, key));
}
}
then call it for each color
applyColorIfPresent(themeConfig, builder, "primaryColor", builder::setPrimaryColor);
if (themeConfig.hasKey("primaryTextStyle")) { | ||
builder.setPrimaryTextStyle(getTextStyle(themeConfig, "primaryTextStyle")); | ||
} | ||
if (themeConfig.hasKey("secondaryTextStyle")) { | ||
builder.setSecondaryTextStyle(getTextStyle(themeConfig, "secondaryTextStyle")); | ||
} | ||
if (themeConfig.hasKey("ctaTextStyle")) { | ||
builder.setCtaTextStyle(getTextStyle(themeConfig, "ctaTextStyle")); |
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.
same as previous comment
private void setFontIfPresent(ReadableMap themeConfig, com.instabug.library.model.IBGTheme.Builder builder, | ||
String fileKey, String assetKey, String fontType) { | ||
if (themeConfig.hasKey(fileKey) || themeConfig.hasKey(assetKey)) { | ||
Typeface typeface = getTypeface(themeConfig, fileKey, assetKey); |
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.
if we might not need both fileKey and assetKey inside then lets have a function that does one thing for each of them and not drop all the logic inside getTypeface
public static Typeface loadTypefaceFromFile(Context context, String fileName) {
...
}
public static Typeface loadTypefaceFromAssets(Context context, String assetKey) {
...
}
Description of the change
Type of change
Related issues
Checklists
Development
Code review