diff --git a/CHANGELOG.md b/CHANGELOG.md index abda7ed70..0578ee431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v15.0.1...dev) + +### Added + +- Add Support Advanced UI customization. ([#1411](https://github.com/Instabug/Instabug-React-Native/pull/1411)) + ## [15.0.1](https://github.com/Instabug/Instabug-React-Native/compare/v14.3.0...v15.0.1) ### Added diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 17f48656f..3d1e744fc 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -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,211 @@ 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")); + } + setFontIfPresent(themeConfig, builder, "primaryFontPath", "primaryFontAsset", "primary"); + setFontIfPresent(themeConfig, builder, "secondaryFontPath", "secondaryFontAsset", "secondary"); + setFontIfPresent(themeConfig, builder, "ctaFontPath", "ctaFontAsset", "CTA"); + + 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; + } + + /** + * Sets a font on the theme builder if the font configuration is present in the theme config. + * + * @param themeConfig The theme configuration map + * @param builder The theme builder + * @param fileKey The key for font file path + * @param assetKey The key for font asset path + * @param fontType The type of font (for logging purposes) + */ + 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); + if (typeface != null) { + switch (fontType) { + case "primary": + builder.setPrimaryTextFont(typeface); + break; + case "secondary": + builder.setSecondaryTextFont(typeface); + break; + case "CTA": + builder.setCtaTextFont(typeface); + break; + } + } else { + Log.e("InstabugModule", "Failed to load " + fontType + " font"); + } + } + } + +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(); + } + + 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(); + } + } + }); + } } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index f4f6f9bc1..af67213dd 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -704,4 +704,72 @@ public void testGetNetworkBodyMaxSize_resolvesPromiseWithExpectedValue() { verify(promise).resolve(expected); } + @Test + public void testEnablSetFullScreen() { + boolean isEnabled = true; + + // when + rnModule.setFullscreen(isEnabled); + + // then + verify(Instabug.class, times(1)); + Instabug.setFullscreen(isEnabled); + } + + @Test + public void testDisableSetFullScreen() { + // given + boolean isEnabled = false; + + // when + rnModule.setFullscreen(isEnabled); + + // then + verify(Instabug.class, times(1)); + Instabug.setFullscreen(isEnabled); + } + + @Test + public void testSetTheme() { + // given + JavaOnlyMap themeConfig = new JavaOnlyMap(); + themeConfig.putString("primaryColor", "#FF0000"); + themeConfig.putString("primaryTextColor", "#00FF00"); + themeConfig.putString("secondaryTextColor", "#0000FF"); + themeConfig.putString("titleTextColor", "#FFFF00"); + themeConfig.putString("backgroundColor", "#FF00FF"); + themeConfig.putString("primaryTextStyle", "bold"); + themeConfig.putString("secondaryTextStyle", "italic"); + themeConfig.putString("ctaTextStyle", "bold"); + + // Mock IBGTheme.Builder + com.instabug.library.model.IBGTheme.Builder mockBuilder = mock(com.instabug.library.model.IBGTheme.Builder.class); + com.instabug.library.model.IBGTheme mockTheme = mock(com.instabug.library.model.IBGTheme.class); + + try (MockedConstruction mockedBuilder = mockConstruction( + com.instabug.library.model.IBGTheme.Builder.class, + (mock, context) -> { + when(mock.setPrimaryColor(anyInt())).thenReturn(mock); + when(mock.setPrimaryTextColor(anyInt())).thenReturn(mock); + when(mock.setSecondaryTextColor(anyInt())).thenReturn(mock); + when(mock.setTitleTextColor(anyInt())).thenReturn(mock); + when(mock.setBackgroundColor(anyInt())).thenReturn(mock); + when(mock.setPrimaryTextStyle(anyInt())).thenReturn(mock); + when(mock.setSecondaryTextStyle(anyInt())).thenReturn(mock); + when(mock.setCtaTextStyle(anyInt())).thenReturn(mock); + when(mock.setPrimaryTextFont(any())).thenReturn(mock); + when(mock.setSecondaryTextFont(any())).thenReturn(mock); + when(mock.setCtaTextFont(any())).thenReturn(mock); + when(mock.build()).thenReturn(mockTheme); + })) { + + // when + rnModule.setTheme(themeConfig); + + // then + verify(Instabug.class, times(1)); + Instabug.setTheme(mockTheme); + } + } + } diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index ded37c3af..5591a0287 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -651,6 +651,73 @@ - (void)testGetNetworkBodyMaxSize { OCMVerify(ClassMethod([mock getNetworkBodyMaxSize])); } +- (void)testSetTheme { + id mock = OCMClassMock([Instabug class]); + id mockTheme = OCMClassMock([IBGTheme class]); + + // Create theme configuration dictionary + NSDictionary *themeConfig = @{ + @"primaryColor": @"#FF0000", + @"backgroundColor": @"#00FF00", + @"titleTextColor": @"#0000FF", + @"subtitleTextColor": @"#FFFF00", + @"primaryTextColor": @"#FF00FF", + @"secondaryTextColor": @"#00FFFF", + @"callToActionTextColor": @"#800080", + @"headerBackgroundColor": @"#808080", + @"footerBackgroundColor": @"#C0C0C0", + @"rowBackgroundColor": @"#FFFFFF", + @"selectedRowBackgroundColor": @"#E6E6FA", + @"rowSeparatorColor": @"#D3D3D3", + @"primaryFontPath": @"TestFont.ttf", + @"secondaryFontPath": @"fonts/AnotherFont.ttf", + @"ctaFontPath": @"./assets/fonts/CTAFont.ttf" + }; + + // Mock IBGTheme creation and configuration + OCMStub([mockTheme primaryColor]).andReturn([UIColor redColor]); + OCMStub([mockTheme backgroundColor]).andReturn([UIColor greenColor]); + OCMStub([mockTheme titleTextColor]).andReturn([UIColor blueColor]); + OCMStub([mockTheme subtitleTextColor]).andReturn([UIColor yellowColor]); + OCMStub([mockTheme primaryTextColor]).andReturn([UIColor magentaColor]); + OCMStub([mockTheme secondaryTextColor]).andReturn([UIColor cyanColor]); + OCMStub([mockTheme callToActionTextColor]).andReturn([UIColor purpleColor]); + OCMStub([mockTheme headerBackgroundColor]).andReturn([UIColor grayColor]); + OCMStub([mockTheme footerBackgroundColor]).andReturn([UIColor lightGrayColor]); + OCMStub([mockTheme rowBackgroundColor]).andReturn([UIColor whiteColor]); + OCMStub([mockTheme selectedRowBackgroundColor]).andReturn([UIColor redColor]); + OCMStub([mockTheme rowSeparatorColor]).andReturn([UIColor lightGrayColor]); + OCMStub([mockTheme primaryTextFont]).andReturn([UIFont systemFontOfSize:17.0]); + OCMStub([mockTheme secondaryTextFont]).andReturn([UIFont systemFontOfSize:17.0]); + OCMStub([mockTheme callToActionTextFont]).andReturn([UIFont systemFontOfSize:17.0]); + + // Mock theme property setting + OCMStub([mockTheme setPrimaryColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setBackgroundColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setTitleTextColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setSubtitleTextColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setPrimaryTextColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setSecondaryTextColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setCallToActionTextColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setHeaderBackgroundColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setFooterBackgroundColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setRowBackgroundColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setSelectedRowBackgroundColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setRowSeparatorColor:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setPrimaryTextFont:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setSecondaryTextFont:[OCMArg any]]).andReturn(mockTheme); + OCMStub([mockTheme setCallToActionTextFont:[OCMArg any]]).andReturn(mockTheme); + + // Mock Instabug.theme property + OCMStub([mock theme]).andReturn(mockTheme); + OCMStub([mock setTheme:[OCMArg any]]); + + // Call the method + [self.instabugBridge setTheme:themeConfig]; + + // Verify that setTheme was called + OCMVerify([mock setTheme:[OCMArg any]]); +} @end diff --git a/examples/default/react-native.config.js b/examples/default/react-native.config.js new file mode 100644 index 000000000..cbdf34c94 --- /dev/null +++ b/examples/default/react-native.config.js @@ -0,0 +1,3 @@ +module.exports = { + assets: ['./assets/fonts/'], +}; diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index 1fe5505d3..c12b59b1e 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -42,6 +42,8 @@ - (void)setPrimaryColor:(UIColor *)color; +- (void)setTheme:(NSDictionary *)themeConfig; + - (void)appendTags:(NSArray *)tags; - (void)resetTags; diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index a48851ba8..794c3b6f2 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -173,6 +173,87 @@ - (dispatch_queue_t)methodQueue { Instabug.tintColor = color; } +RCT_EXPORT_METHOD(setTheme:(NSDictionary *)themeConfig) { + IBGTheme *theme = [[IBGTheme alloc] init]; + + NSDictionary *colorMapping = @{ + @"primaryColor": ^(UIColor *color) { theme.primaryColor = color; }, + @"backgroundColor": ^(UIColor *color) { theme.backgroundColor = color; }, + @"titleTextColor": ^(UIColor *color) { theme.titleTextColor = color; }, + @"subtitleTextColor": ^(UIColor *color) { theme.subtitleTextColor = color; }, + @"primaryTextColor": ^(UIColor *color) { theme.primaryTextColor = color; }, + @"secondaryTextColor": ^(UIColor *color) { theme.secondaryTextColor = color; }, + @"callToActionTextColor": ^(UIColor *color) { theme.callToActionTextColor = color; }, + @"headerBackgroundColor": ^(UIColor *color) { theme.headerBackgroundColor = color; }, + @"footerBackgroundColor": ^(UIColor *color) { theme.footerBackgroundColor = color; }, + @"rowBackgroundColor": ^(UIColor *color) { theme.rowBackgroundColor = color; }, + @"selectedRowBackgroundColor": ^(UIColor *color) { theme.selectedRowBackgroundColor = color; }, + @"rowSeparatorColor": ^(UIColor *color) { theme.rowSeparatorColor = color; } + }; + + for (NSString *key in colorMapping) { + if (themeConfig[key]) { + NSString *colorString = themeConfig[key]; + UIColor *color = [self colorFromHexString:colorString]; + if (color) { + void (^setter)(UIColor *) = colorMapping[key]; + setter(color); + } + } + } + + [self setFontIfPresent:themeConfig[@"primaryFontPath"] forTheme:theme type:@"primary"]; + [self setFontIfPresent:themeConfig[@"secondaryFontPath"] forTheme:theme type:@"secondary"]; + [self setFontIfPresent:themeConfig[@"ctaFontPath"] forTheme:theme type:@"cta"]; + + Instabug.theme = theme; +} + +- (void)setFontIfPresent:(NSString *)fontPath forTheme:(IBGTheme *)theme type:(NSString *)type { + if (fontPath) { + NSString *fileName = [fontPath lastPathComponent]; + NSString *nameWithoutExtension = [fileName stringByDeletingPathExtension]; + UIFont *font = [UIFont fontWithName:nameWithoutExtension size:17.0]; + if (font) { + if ([type isEqualToString:@"primary"]) { + theme.primaryTextFont = font; + } else if ([type isEqualToString:@"secondary"]) { + theme.secondaryTextFont = font; + } else if ([type isEqualToString:@"cta"]) { + theme.callToActionTextFont = font; + } + } + } +} + +- (UIColor *)colorFromHexString:(NSString *)hexString { + NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]; + + if (cleanString.length == 6) { + unsigned int rgbValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:cleanString]; + [scanner scanHexInt:&rgbValue]; + + return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 + green:((rgbValue & 0xFF00) >> 8) / 255.0 + blue:(rgbValue & 0xFF) / 255.0 + alpha:1.0]; + } else if (cleanString.length == 8) { + unsigned int rgbaValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:cleanString]; + [scanner scanHexInt:&rgbaValue]; + + return [UIColor colorWithRed:((rgbaValue & 0xFF000000) >> 24) / 255.0 + green:((rgbaValue & 0xFF0000) >> 16) / 255.0 + blue:((rgbaValue & 0xFF00) >> 8) / 255.0 + alpha:(rgbaValue & 0xFF) / 255.0]; + } + + return [UIColor blackColor]; +} + + + RCT_EXPORT_METHOD(appendTags:(NSArray *)tags) { [Instabug appendTags:tags]; } diff --git a/src/index.ts b/src/index.ts index 6e7de0284..82628c48b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import type { InstabugConfig } from './models/InstabugConfig'; import Report from './models/Report'; import Trace from './models/Trace'; +import type { ThemeConfig } from './models/ThemeConfig'; // Modules import * as APM from './modules/APM'; import * as BugReporting from './modules/BugReporting'; @@ -29,6 +30,13 @@ export { Replies, Surveys, }; -export type { InstabugConfig, Survey, NetworkData, NetworkDataObfuscationHandler, SessionMetadata }; +export type { + InstabugConfig, + Survey, + NetworkData, + NetworkDataObfuscationHandler, + SessionMetadata, + ThemeConfig, +}; export default Instabug; diff --git a/src/models/ThemeConfig.ts b/src/models/ThemeConfig.ts new file mode 100644 index 000000000..fb90347c9 --- /dev/null +++ b/src/models/ThemeConfig.ts @@ -0,0 +1,34 @@ +export type ThemeConfig = { + // Colors + primaryColor?: string; + backgroundColor?: string; + titleTextColor?: string; + subtitleTextColor?: string; + primaryTextColor?: string; + secondaryTextColor?: string; + callToActionTextColor?: string; + headerBackgroundColor?: string; + footerBackgroundColor?: string; + rowBackgroundColor?: string; + selectedRowBackgroundColor?: string; + rowSeparatorColor?: string; + + // Text Styles (Android only) + primaryTextStyle?: 'bold' | 'italic' | 'normal'; + secondaryTextStyle?: 'bold' | 'italic' | 'normal'; + titleTextStyle?: 'bold' | 'italic' | 'normal'; + ctaTextStyle?: 'bold' | 'italic' | 'normal'; + + // Fonts + primaryFontPath?: string; + primaryFontAsset?: string; + secondaryFontPath?: string; + secondaryFontAsset?: string; + ctaFontPath?: string; + ctaFontAsset?: string; + + // Legacy properties (deprecated) + primaryTextType?: string; + secondaryTextType?: string; + ctaTextType?: string; +}; diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index f7d582e70..f5943e348 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -42,6 +42,7 @@ import { NativeNetworkLogger } from '../native/NativeNetworkLogger'; import InstabugConstants from '../utils/InstabugConstants'; import { InstabugRNConfig } from '../utils/config'; import { Logger } from '../utils/logger'; +import type { ThemeConfig } from '../models/ThemeConfig'; let _currentScreen: string | null = null; let _lastScreen: string | null = null; @@ -895,3 +896,50 @@ export const _registerFeatureFlagsChangeListener = ( export const enableAutoMasking = (autoMaskingTypes: AutoMaskingType[]) => { NativeInstabug.enableAutoMasking(autoMaskingTypes); }; + +/** + * Sets a custom theme for Instabug UI elements. + * + * This method provides comprehensive theming support. It will automatically use IBGTheme + * if available in the SDK version, otherwise falls back to individual theming methods. + * + * @param theme - Configuration object containing theme properties + * + * @example + * ```typescript + * // Basic usage with primary color (always supported) + * Instabug.setTheme({ + * primaryColor: '#FF6B6B' + * }); + * + * // Comprehensive theming (uses IBGTheme when available) + * Instabug.setTheme({ + * primaryColor: '#FF6B6B', + * secondaryTextColor: '#666666', + * primaryTextColor: '#333333', + * titleTextColor: '#000000', + * backgroundColor: '#FFFFFF', + * primaryTextStyle: 'bold', + * secondaryTextStyle: 'normal', + * titleTextStyle: 'bold', + * ctaTextStyle: 'bold', + * primaryFontPath: '/data/user/0/com.yourapp/files/fonts/YourFont.ttf', + * secondaryFontPath: '/data/user/0/com.yourapp/files/fonts/YourFont.ttf', + * ctaTextType: '/data/user/0/com.yourapp/files/fonts/YourFont.ttf', + * primaryFontAsset: 'fonts/YourFont.ttf', + * secondaryFontAsset: 'fonts/YourFont.ttf' + * }); + * ``` + */ +export const setTheme = (theme: ThemeConfig) => { + NativeInstabug.setTheme(theme); +}; +/** + * Enables or disables displaying in full-screen mode, hiding the status and navigation bars. + * @param isEnabled A boolean to enable/disable setFullscreen. + */ +export const setFullscreen = (isEnabled: boolean) => { + if (Platform.OS === 'android') { + NativeInstabug.setFullscreen(isEnabled); + } +}; diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 7032bbc07..70c6ae42c 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -14,6 +14,7 @@ import type { import type { NativeConstants } from './NativeConstants'; import type { W3cExternalTraceAttributes } from '../models/W3cExternalTraceAttributes'; import { NativeModules } from './NativePackage'; +import type { ThemeConfig } from '../models/ThemeConfig'; export interface InstabugNativeModule extends NativeModule { getConstants(): NativeConstants; @@ -158,9 +159,12 @@ export interface InstabugNativeModule extends NativeModule { setOnFeaturesUpdatedListener(handler?: (params: any) => void): void; // android only enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void; getNetworkBodyMaxSize(): Promise; + + setTheme(theme: ThemeConfig): void; + setFullscreen(isEnabled: boolean): void; } -export const NativeInstabug = NativeModules.Instabug; +export const NativeInstabug = NativeModules.Instabug as InstabugNativeModule; export enum NativeEvents { PRESENDING_HANDLER = 'IBGpreSendingHandler', diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 391a00a38..60c4b9ade 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -77,6 +77,8 @@ const mockInstabug: InstabugNativeModule = { setOnFeaturesUpdatedListener: jest.fn(), enableAutoMasking: jest.fn(), getNetworkBodyMaxSize: jest.fn().mockResolvedValue(10240), // 10 KB + setTheme: jest.fn(), + setFullscreen: jest.fn(), }; export default mockInstabug;