-
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
Open
AyaMahmoud148
wants to merge
5
commits into
dev
Choose a base branch
from
feat/Advanced-UI-Customization
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,14 @@ | |
|
||
import android.app.Application; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.UiThread; | ||
|
||
|
@@ -45,6 +49,7 @@ | |
import com.instabug.library.internal.module.InstabugLocale; | ||
import com.instabug.library.invocation.InstabugInvocationEvent; | ||
import com.instabug.library.logging.InstabugLog; | ||
import com.instabug.library.model.IBGTheme; | ||
import com.instabug.library.model.NetworkLog; | ||
import com.instabug.library.model.Report; | ||
import com.instabug.library.ui.onboarding.WelcomeMessage; | ||
|
@@ -1351,4 +1356,203 @@ public void run() { | |
} | ||
}); | ||
} | ||
/** | ||
* Sets the theme for Instabug using a configuration object. | ||
* | ||
* @param themeConfig A ReadableMap containing theme properties such as colors, fonts, and text styles. | ||
*/ | ||
@ReactMethod | ||
public void setTheme(final ReadableMap themeConfig) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
com.instabug.library.model.IBGTheme.Builder builder = new com.instabug.library.model.IBGTheme.Builder(); | ||
|
||
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")); | ||
} | ||
|
||
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")); | ||
} | ||
if (themeConfig.hasKey("primaryFontPath") || themeConfig.hasKey("primaryFontAsset")) { | ||
Typeface primaryTypeface = getTypeface(themeConfig, "primaryFontPath", "primaryFontAsset"); | ||
if (primaryTypeface != null) { | ||
builder.setPrimaryTextFont(primaryTypeface); | ||
} else { | ||
Log.e("InstabugModule", "Failed to load primary font"); | ||
} | ||
} | ||
|
||
if (themeConfig.hasKey("secondaryFontPath") || themeConfig.hasKey("secondaryFontAsset")) { | ||
Typeface secondaryTypeface = getTypeface(themeConfig, "secondaryFontPath", "secondaryFontAsset"); | ||
if (secondaryTypeface != null) { | ||
builder.setSecondaryTextFont(secondaryTypeface); | ||
} else { | ||
Log.e("InstabugModule", "Failed to load secondary font"); | ||
} | ||
} | ||
|
||
if (themeConfig.hasKey("ctaFontPath") || themeConfig.hasKey("ctaFontAsset")) { | ||
Typeface ctaTypeface = getTypeface(themeConfig, "ctaFontPath", "ctaFontAsset"); | ||
if (ctaTypeface != null) { | ||
builder.setCtaTextFont(ctaTypeface); | ||
} else { | ||
Log.e("InstabugModule", "Failed to load CTA font"); | ||
} | ||
} | ||
|
||
IBGTheme theme = builder.build(); | ||
Instabug.setTheme(theme); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Retrieves a color value from the ReadableMap. | ||
* | ||
* @param map The ReadableMap object. | ||
* @param key The key to look for. | ||
* @return The parsed color as an integer, or black if missing or invalid. | ||
*/ | ||
private int getColor(ReadableMap map, String key) { | ||
try { | ||
if (map != null && map.hasKey(key) && !map.isNull(key)) { | ||
String colorString = map.getString(key); | ||
return Color.parseColor(colorString); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return Color.BLACK; | ||
} | ||
|
||
/** | ||
* Retrieves a text style from the ReadableMap. | ||
* | ||
* @param map The ReadableMap object. | ||
* @param key The key to look for. | ||
* @return The corresponding Typeface style, or Typeface.NORMAL if missing or invalid. | ||
*/ | ||
private int getTextStyle(ReadableMap map, String key) { | ||
try { | ||
if (map != null && map.hasKey(key) && !map.isNull(key)) { | ||
String style = map.getString(key); | ||
switch (style.toLowerCase()) { | ||
case "bold": | ||
return Typeface.BOLD; | ||
case "italic": | ||
return Typeface.ITALIC; | ||
case "bold_italic": | ||
return Typeface.BOLD_ITALIC; | ||
case "normal": | ||
default: | ||
return Typeface.NORMAL; | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return Typeface.NORMAL; | ||
} | ||
|
||
private Typeface getTypeface(ReadableMap map, String fileKey, String assetKey) { | ||
try { | ||
if (fileKey != null && map.hasKey(fileKey) && !map.isNull(fileKey)) { | ||
String fontPath = map.getString(fileKey); | ||
String fileName = getFileName(fontPath); | ||
|
||
try { | ||
Typeface typeface = Typeface.create(fileName, Typeface.NORMAL); | ||
if (typeface != null && !typeface.equals(Typeface.DEFAULT)) { | ||
return typeface; | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
try { | ||
Typeface typeface = Typeface.createFromAsset(getReactApplicationContext().getAssets(), "fonts/" + fileName); | ||
return typeface; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
if (assetKey != null && map.hasKey(assetKey) && !map.isNull(assetKey)) { | ||
String assetPath = map.getString(assetKey); | ||
String fileName = getFileName(assetPath); | ||
try { | ||
Typeface typeface = Typeface.createFromAsset(getReactApplicationContext().getAssets(), "fonts/" + fileName); | ||
return typeface; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Comment on lines
+1508
to
+1517
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
|
||
return Typeface.DEFAULT; | ||
} | ||
|
||
/** | ||
* Extracts the filename from a path, removing any directory prefixes. | ||
* | ||
* @param path The full path to the file | ||
* @return Just the filename with extension | ||
*/ | ||
private String getFileName(String path) { | ||
if (path == null || path.isEmpty()) { | ||
return path; | ||
} | ||
|
||
int lastSeparator = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); | ||
if (lastSeparator >= 0 && lastSeparator < path.length() - 1) { | ||
return path.substring(lastSeparator + 1); | ||
} | ||
|
||
return path; | ||
} | ||
|
||
/** | ||
* Enables or disables displaying in full-screen mode, hiding the status and navigation bars. | ||
* @param isEnabled A boolean to enable/disable setFullscreen. | ||
*/ | ||
@ReactMethod | ||
public void setFullscreen(final boolean isEnabled) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
Instabug.setFullscreen(isEnabled); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
assets: ['./assets/fonts/'], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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