@octopus-community/react-native 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +257 -12
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactNativeSdkModule.kt +82 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSDKInitializer.kt +93 -17
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusThemeConfig.kt +12 -1
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIActivity.kt +135 -56
- package/ios/OctopusReactNativeSdk.mm +8 -0
- package/ios/OctopusReactNativeSdk.swift +21 -1
- package/ios/OctopusSDKInitializer.swift +95 -24
- package/ios/OctopusUIManager.swift +106 -11
- package/lib/module/initialize.js +50 -1
- package/lib/module/initialize.js.map +1 -1
- package/lib/module/internals/colorSchemeManager.js +105 -0
- package/lib/module/internals/colorSchemeManager.js.map +1 -0
- package/lib/module/internals/fontParser.js +48 -0
- package/lib/module/internals/fontParser.js.map +1 -0
- package/lib/typescript/src/initialize.d.ts +78 -10
- package/lib/typescript/src/initialize.d.ts.map +1 -1
- package/lib/typescript/src/internals/colorSchemeManager.d.ts +39 -0
- package/lib/typescript/src/internals/colorSchemeManager.d.ts.map +1 -0
- package/lib/typescript/src/internals/fontParser.d.ts +18 -0
- package/lib/typescript/src/internals/fontParser.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/initialize.ts +117 -12
- package/src/internals/colorSchemeManager.ts +113 -0
- package/src/internals/fontParser.ts +64 -0
package/lib/module/initialize.js
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
|
|
4
|
+
import { Appearance } from 'react-native';
|
|
5
|
+
import { colorSchemeManager } from "./internals/colorSchemeManager.js";
|
|
6
|
+
import { parseFontConfig } from "./internals/fontParser.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Color set for a specific appearance mode (light or dark).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Font type options for unified cross-platform font configuration.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Font size configuration for different text types.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Font configuration for a specific text type.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Font configuration for customizing the Octopus UI typography.
|
|
26
|
+
*/
|
|
4
27
|
|
|
5
28
|
/**
|
|
6
29
|
* Theme configuration for customizing the Octopus UI appearance.
|
|
30
|
+
*
|
|
31
|
+
* Supports two approaches:
|
|
32
|
+
* 1. Single color set (backward compatible) - colors are applied to both light and dark modes
|
|
33
|
+
* 2. Dual mode colors - separate color sets for light and dark modes
|
|
7
34
|
*/
|
|
8
35
|
|
|
9
36
|
/**
|
|
@@ -37,6 +64,28 @@ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
|
|
|
37
64
|
* ```
|
|
38
65
|
*/
|
|
39
66
|
export function initialize(params) {
|
|
40
|
-
|
|
67
|
+
// Automatically detect the current color scheme and add it to the params
|
|
68
|
+
const colorScheme = Appearance.getColorScheme();
|
|
69
|
+
|
|
70
|
+
// Pre-process font configuration to avoid duplication in native layers
|
|
71
|
+
const processedTheme = params.theme ? {
|
|
72
|
+
...params.theme,
|
|
73
|
+
fonts: params.theme.fonts ? {
|
|
74
|
+
...params.theme.fonts,
|
|
75
|
+
parsedConfig: parseFontConfig(params.theme.fonts)
|
|
76
|
+
} : undefined
|
|
77
|
+
} : undefined;
|
|
78
|
+
const paramsWithColorScheme = {
|
|
79
|
+
...params,
|
|
80
|
+
theme: processedTheme,
|
|
81
|
+
colorScheme: colorScheme || undefined
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Set the theme in the color scheme manager for dual-mode support
|
|
85
|
+
colorSchemeManager.setTheme(processedTheme || null);
|
|
86
|
+
|
|
87
|
+
// Start listening to color scheme changes for automatic updates
|
|
88
|
+
colorSchemeManager.startListening();
|
|
89
|
+
return OctopusReactNativeSdk.initialize(paramsWithColorScheme);
|
|
41
90
|
}
|
|
42
91
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OctopusReactNativeSdk","initialize","params"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;;
|
|
1
|
+
{"version":3,"names":["OctopusReactNativeSdk","Appearance","colorSchemeManager","parseFontConfig","initialize","params","colorScheme","getColorScheme","processedTheme","theme","fonts","parsedConfig","undefined","paramsWithColorScheme","setTheme","startListening"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;AAGhE,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,kBAAkB,QAAQ,mCAAgC;AACnE,SAASC,eAAe,QAA+B,2BAAwB;;AAE/E;AACA;AACA;;AAYA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAQA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;;AAyBA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,MAAwB,EAAiB;EAClE;EACA,MAAMC,WAAW,GAAGL,UAAU,CAACM,cAAc,CAAC,CAAC;;EAE/C;EACA,MAAMC,cAAc,GAAGH,MAAM,CAACI,KAAK,GAC/B;IACE,GAAGJ,MAAM,CAACI,KAAK;IACfC,KAAK,EAAEL,MAAM,CAACI,KAAK,CAACC,KAAK,GACrB;MACE,GAAGL,MAAM,CAACI,KAAK,CAACC,KAAK;MACrBC,YAAY,EAAER,eAAe,CAACE,MAAM,CAACI,KAAK,CAACC,KAAK;IAClD,CAAC,GACDE;EACN,CAAC,GACDA,SAAS;EAEb,MAAMC,qBAAqB,GAAG;IAC5B,GAAGR,MAAM;IACTI,KAAK,EAAED,cAAc;IACrBF,WAAW,EAAEA,WAAW,IAAIM;EAC9B,CAAC;;EAED;EACAV,kBAAkB,CAACY,QAAQ,CAACN,cAAc,IAAI,IAAI,CAAC;;EAEnD;EACAN,kBAAkB,CAACa,cAAc,CAAC,CAAC;EAEnC,OAAOf,qBAAqB,CAACI,UAAU,CAACS,qBAAqB,CAAC;AAChE","ignoreList":[]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Appearance, AppState } from 'react-native';
|
|
4
|
+
import { OctopusReactNativeSdk } from "./nativeModule.js";
|
|
5
|
+
let isListening = false;
|
|
6
|
+
let currentColorScheme = null;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal color scheme manager that automatically handles appearance changes
|
|
10
|
+
* and updates the native modules accordingly.
|
|
11
|
+
*/
|
|
12
|
+
export class ColorSchemeManager {
|
|
13
|
+
appearanceSubscription = null;
|
|
14
|
+
appStateSubscription = null;
|
|
15
|
+
constructor() {}
|
|
16
|
+
static getInstance() {
|
|
17
|
+
if (!ColorSchemeManager.instance) {
|
|
18
|
+
ColorSchemeManager.instance = new ColorSchemeManager();
|
|
19
|
+
}
|
|
20
|
+
return ColorSchemeManager.instance;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set the current theme for color scheme management
|
|
25
|
+
* Note: This is kept for API compatibility but theme updates are not used
|
|
26
|
+
* when the Octopus UI is open since the React Native app is backgrounded.
|
|
27
|
+
*/
|
|
28
|
+
setTheme(_theme) {
|
|
29
|
+
// Theme is set during initialization and applied when UI opens
|
|
30
|
+
// No need to store it here since updates can't happen while UI is open
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Start listening to appearance changes and automatically update native modules
|
|
35
|
+
*/
|
|
36
|
+
startListening() {
|
|
37
|
+
if (isListening) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
isListening = true;
|
|
41
|
+
currentColorScheme = Appearance.getColorScheme();
|
|
42
|
+
|
|
43
|
+
// Listen to appearance changes
|
|
44
|
+
this.appearanceSubscription = Appearance.addChangeListener(({
|
|
45
|
+
colorScheme
|
|
46
|
+
}) => {
|
|
47
|
+
currentColorScheme = colorScheme;
|
|
48
|
+
this.updateNativeColorScheme();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Listen to app state changes to ensure we have the latest color scheme
|
|
52
|
+
this.appStateSubscription = AppState.addEventListener('change', nextAppState => {
|
|
53
|
+
// Only check color scheme when app becomes active (foreground)
|
|
54
|
+
if (nextAppState === 'active') {
|
|
55
|
+
const newColorScheme = Appearance.getColorScheme();
|
|
56
|
+
if (newColorScheme !== currentColorScheme) {
|
|
57
|
+
currentColorScheme = newColorScheme;
|
|
58
|
+
this.updateNativeColorScheme();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Stop listening to appearance changes
|
|
66
|
+
*/
|
|
67
|
+
stopListening() {
|
|
68
|
+
if (this.appearanceSubscription) {
|
|
69
|
+
this.appearanceSubscription.remove();
|
|
70
|
+
this.appearanceSubscription = null;
|
|
71
|
+
}
|
|
72
|
+
if (this.appStateSubscription) {
|
|
73
|
+
this.appStateSubscription.remove();
|
|
74
|
+
this.appStateSubscription = null;
|
|
75
|
+
}
|
|
76
|
+
isListening = false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the current color scheme
|
|
81
|
+
*/
|
|
82
|
+
getCurrentColorScheme() {
|
|
83
|
+
return currentColorScheme;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Update the native modules with the current color scheme
|
|
88
|
+
* Note: This is only called when the app becomes active (foreground).
|
|
89
|
+
* When the Octopus UI is open, the React Native app is backgrounded,
|
|
90
|
+
* so theme updates are not possible during UI display.
|
|
91
|
+
*/
|
|
92
|
+
updateNativeColorScheme() {
|
|
93
|
+
// Both platforms handle theme updates when the app becomes active
|
|
94
|
+
// iOS uses adaptive colors, Android applies the theme when UI reopens
|
|
95
|
+
try {
|
|
96
|
+
OctopusReactNativeSdk.updateColorScheme(currentColorScheme || undefined);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.stopListening();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Export singleton instance
|
|
104
|
+
export const colorSchemeManager = ColorSchemeManager.getInstance();
|
|
105
|
+
//# sourceMappingURL=colorSchemeManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Appearance","AppState","OctopusReactNativeSdk","isListening","currentColorScheme","ColorSchemeManager","appearanceSubscription","appStateSubscription","constructor","getInstance","instance","setTheme","_theme","startListening","getColorScheme","addChangeListener","colorScheme","updateNativeColorScheme","addEventListener","nextAppState","newColorScheme","stopListening","remove","getCurrentColorScheme","updateColorScheme","undefined","error","colorSchemeManager"],"sourceRoot":"../../../src","sources":["internals/colorSchemeManager.ts"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,cAAc;AACnD,SAASC,qBAAqB,QAAQ,mBAAgB;AAGtD,IAAIC,WAAW,GAAG,KAAK;AACvB,IAAIC,kBAA6C,GAAG,IAAI;;AAExD;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAC;EAEtBC,sBAAsB,GAAQ,IAAI;EAClCC,oBAAoB,GAAQ,IAAI;EAEhCC,WAAWA,CAAA,EAAG,CAAC;EAEvB,OAAOC,WAAWA,CAAA,EAAuB;IACvC,IAAI,CAACJ,kBAAkB,CAACK,QA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;AACA;EACEoB,qBAAqBA,CAAA,EAA8B;IACjD,OAAOnB,kBAAkB;EAC3B;;EAEA;AACF;AACA;AACA;AACA;AACA;EACUa,uBAAuBA,CAAA,EAAS;IACtC;IACA;IACA,IAAI;MACFf,qBAAqB,CAACsB,iBAAiB,CAACpB,kBAAkB,IAAIqB,SAAS,CAAC;IAC1E,CAAC,CAAC,OAAOC,KAAK,EAAE;MACd,IAAI,CAACL,aAAa,CAAC,CAAC;IACtB;EACF;AACF;;AAEA;AACA,OAAO,MAAMM,kBAAkB,GAAGtB,kBAAkB,CAACI,WAAW,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parsed font configuration for native platforms
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parse font configuration from the theme and return a simplified structure
|
|
9
|
+
* that can be easily consumed by native platforms.
|
|
10
|
+
*
|
|
11
|
+
* This centralizes the font parsing logic to avoid duplication across platforms.
|
|
12
|
+
*/
|
|
13
|
+
export function parseFontConfig(fonts) {
|
|
14
|
+
if (!fonts?.textStyles) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const textStyles = {};
|
|
18
|
+
|
|
19
|
+
// Define the text style keys that are supported
|
|
20
|
+
const supportedTextStyles = ['title1', 'title2', 'body1', 'body2', 'caption1', 'caption2'];
|
|
21
|
+
for (const key of supportedTextStyles) {
|
|
22
|
+
const textStyle = fonts.textStyles[key];
|
|
23
|
+
if (textStyle) {
|
|
24
|
+
const parsedStyle = {};
|
|
25
|
+
|
|
26
|
+
// Parse font type
|
|
27
|
+
if (textStyle.fontType) {
|
|
28
|
+
parsedStyle.fontType = textStyle.fontType;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Parse font size
|
|
32
|
+
if (textStyle.fontSize?.size) {
|
|
33
|
+
parsedStyle.fontSize = textStyle.fontSize.size;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Only include the style if it has at least one property
|
|
37
|
+
if (parsedStyle.fontType || parsedStyle.fontSize) {
|
|
38
|
+
textStyles[key] = parsedStyle;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Return null if no text styles were parsed
|
|
44
|
+
return Object.keys(textStyles).length > 0 ? {
|
|
45
|
+
textStyles
|
|
46
|
+
} : null;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=fontParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parseFontConfig","fonts","textStyles","supportedTextStyles","key","textStyle","parsedStyle","fontType","fontSize","size","Object","keys","length"],"sourceRoot":"../../../src","sources":["internals/fontParser.ts"],"mappings":";;AAEA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAACC,KAAoB,EAA2B;EAC7E,IAAI,CAACA,KAAK,EAAEC,UAAU,EAAE;IACtB,OAAO,IAAI;EACb;EAEA,MAAMA,UAAoE,GACxE,CAAC,CAAC;;EAEJ;EACA,MAAMC,mBAAmB,GAAG,CAC1B,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,UAAU,CACX;EAED,KAAK,MAAMC,GAAG,IAAID,mBAAmB,EAAE;IACrC,MAAME,SAAS,GAAGJ,KAAK,CAACC,UAAU,CAACE,GAAG,CAAkC;IACxE,IAAIC,SAAS,EAAE;MACb,MAAMC,WAAqD,GAAG,CAAC,CAAC;;MAEhE;MACA,IAAID,SAAS,CAACE,QAAQ,EAAE;QACtBD,WAAW,CAACC,QAAQ,GAAGF,SAAS,CAACE,QAAQ;MAC3C;;MAEA;MACA,IAAIF,SAAS,CAACG,QAAQ,EAAEC,IAAI,EAAE;QAC5BH,WAAW,CAACE,QAAQ,GAAGH,SAAS,CAACG,QAAQ,CAACC,IAAI;MAChD;;MAEA;MACA,IAAIH,WAAW,CAACC,QAAQ,IAAID,WAAW,CAACE,QAAQ,EAAE;QAChDN,UAAU,CAACE,GAAG,CAAC,GAAGE,WAAW;MAC/B;IACF;EACF;;EAEA;EACA,OAAOI,MAAM,CAACC,IAAI,CAACT,UAAU,CAAC,CAACU,MAAM,GAAG,CAAC,GAAG;IAAEV;EAAW,CAAC,GAAG,IAAI;AACnE","ignoreList":[]}
|
|
@@ -1,20 +1,88 @@
|
|
|
1
1
|
import type { UserProfileField } from './types/userProfileField';
|
|
2
2
|
import type { ImageResolvedAssetSource } from 'react-native';
|
|
3
|
+
import { type ParsedFontConfig } from './internals/fontParser';
|
|
4
|
+
/**
|
|
5
|
+
* Color set for a specific appearance mode (light or dark).
|
|
6
|
+
*/
|
|
7
|
+
export interface OctopusColorSet {
|
|
8
|
+
/** Primary color set for branding (hex format: #FF6B35 or FF6B35) */
|
|
9
|
+
primary?: string;
|
|
10
|
+
/** Primary low contrast color (lighter variation of primary) (hex format: #FF6B35 or FF6B35) */
|
|
11
|
+
primaryLowContrast?: string;
|
|
12
|
+
/** High contrast variation of primary color (hex format: #FF6B35 or FF6B35) */
|
|
13
|
+
primaryHighContrast?: string;
|
|
14
|
+
/** Color for content displayed over the primary color (hex format: #FF6B35 or FF6B35) */
|
|
15
|
+
onPrimary?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Font type options for unified cross-platform font configuration.
|
|
19
|
+
*/
|
|
20
|
+
export type OctopusFontType = 'serif' | 'monospace' | 'default';
|
|
21
|
+
/**
|
|
22
|
+
* Font size configuration for different text types.
|
|
23
|
+
*/
|
|
24
|
+
export interface OctopusFontSize {
|
|
25
|
+
/** Font size in points (will be converted to platform-specific units) */
|
|
26
|
+
size?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Font configuration for a specific text type.
|
|
30
|
+
*/
|
|
31
|
+
export interface OctopusTextStyle {
|
|
32
|
+
/** Font type: serif, monospace, or default (uses system default) */
|
|
33
|
+
fontType?: OctopusFontType;
|
|
34
|
+
/** Font size configuration */
|
|
35
|
+
fontSize?: OctopusFontSize;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Font configuration for customizing the Octopus UI typography.
|
|
39
|
+
*/
|
|
40
|
+
export interface OctopusFonts {
|
|
41
|
+
/**
|
|
42
|
+
* Unified font configuration for different text types.
|
|
43
|
+
*/
|
|
44
|
+
textStyles?: {
|
|
45
|
+
/** Configuration for title1 text */
|
|
46
|
+
title1?: OctopusTextStyle;
|
|
47
|
+
/** Configuration for title2 text */
|
|
48
|
+
title2?: OctopusTextStyle;
|
|
49
|
+
/** Configuration for body1 text */
|
|
50
|
+
body1?: OctopusTextStyle;
|
|
51
|
+
/** Configuration for body2 text */
|
|
52
|
+
body2?: OctopusTextStyle;
|
|
53
|
+
/** Configuration for caption1 text */
|
|
54
|
+
caption1?: OctopusTextStyle;
|
|
55
|
+
/** Configuration for caption2 text */
|
|
56
|
+
caption2?: OctopusTextStyle;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Pre-processed font configuration for native platforms.
|
|
60
|
+
* This is automatically generated and should not be set manually.
|
|
61
|
+
*/
|
|
62
|
+
parsedConfig?: ParsedFontConfig | null;
|
|
63
|
+
}
|
|
3
64
|
/**
|
|
4
65
|
* Theme configuration for customizing the Octopus UI appearance.
|
|
66
|
+
*
|
|
67
|
+
* Supports two approaches:
|
|
68
|
+
* 1. Single color set (backward compatible) - colors are applied to both light and dark modes
|
|
69
|
+
* 2. Dual mode colors - separate color sets for light and dark modes
|
|
5
70
|
*/
|
|
6
71
|
export interface OctopusTheme {
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Color customization options.
|
|
74
|
+
*
|
|
75
|
+
* For backward compatibility, you can pass a single color set that will be used for both light and dark modes.
|
|
76
|
+
* For enhanced theming, you can pass separate color sets for light and dark modes.
|
|
77
|
+
*/
|
|
78
|
+
colors?: OctopusColorSet | {
|
|
79
|
+
/** Colors for light mode */
|
|
80
|
+
light: OctopusColorSet;
|
|
81
|
+
/** Colors for dark mode */
|
|
82
|
+
dark: OctopusColorSet;
|
|
17
83
|
};
|
|
84
|
+
/** Font customization options */
|
|
85
|
+
fonts?: OctopusFonts;
|
|
18
86
|
/** Logo customization */
|
|
19
87
|
logo?: {
|
|
20
88
|
/** Local image resource - use Image.resolveAssetSource(require('./path/to/image.png')) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/initialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/initialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAG7D,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,+EAA+E;IAC/E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,IAAI,CAAC,EA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A0C;QAC1C,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC;IACN,sDAAsD;IACtD,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BlE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OctopusTheme } from '../initialize';
|
|
2
|
+
/**
|
|
3
|
+
* Internal color scheme manager that automatically handles appearance changes
|
|
4
|
+
* and updates the native modules accordingly.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ColorSchemeManager {
|
|
7
|
+
private static instance;
|
|
8
|
+
private appearanceSubscription;
|
|
9
|
+
private appStateSubscription;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): ColorSchemeManager;
|
|
12
|
+
/**
|
|
13
|
+
* Set the current theme for color scheme management
|
|
14
|
+
* Note: This is kept for API compatibility but theme updates are not used
|
|
15
|
+
* when the Octopus UI is open since the React Native app is backgrounded.
|
|
16
|
+
*/
|
|
17
|
+
setTheme(_theme: OctopusTheme | null): void;
|
|
18
|
+
/**
|
|
19
|
+
* Start listening to appearance changes and automatically update native modules
|
|
20
|
+
*/
|
|
21
|
+
startListening(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Stop listening to appearance changes
|
|
24
|
+
*/
|
|
25
|
+
stopListening(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the current color scheme
|
|
28
|
+
*/
|
|
29
|
+
getCurrentColorScheme(): string | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Update the native modules with the current color scheme
|
|
32
|
+
* Note: This is only called when the app becomes active (foreground).
|
|
33
|
+
* When the Octopus UI is open, the React Native app is backgrounded,
|
|
34
|
+
* so theme updates are not possible during UI display.
|
|
35
|
+
*/
|
|
36
|
+
private updateNativeColorScheme;
|
|
37
|
+
}
|
|
38
|
+
export declare const colorSchemeManager: ColorSchemeManager;
|
|
39
|
+
//# sourceMappingURL=colorSchemeManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorSchemeManager.d.ts","sourceRoot":"","sources":["../../../../src/internals/colorSchemeManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKlD;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAC5C,OAAO,CAAC,sBAAsB,CAAa;IAC3C,OAAO,CAAC,oBAAoB,CAAa;IAEzC,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,kBAAkB;IAOxC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI;IAK3C;;OAEG;IACH,cAAc,IAAI,IAAI;IAgCtB;;OAEG;IACH,aAAa,IAAI,IAAI;IAcrB;;OAEG;IACH,qBAAqB,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS;IAIlD;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;CAShC;AAGD,eAAO,MAAM,kBAAkB,oBAAmC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OctopusFonts } from '../initialize';
|
|
2
|
+
/**
|
|
3
|
+
* Parsed font configuration for native platforms
|
|
4
|
+
*/
|
|
5
|
+
export interface ParsedFontConfig {
|
|
6
|
+
textStyles: Record<string, {
|
|
7
|
+
fontType?: string;
|
|
8
|
+
fontSize?: number;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse font configuration from the theme and return a simplified structure
|
|
13
|
+
* that can be easily consumed by native platforms.
|
|
14
|
+
*
|
|
15
|
+
* This centralizes the font parsing logic to avoid duplication across platforms.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseFontConfig(fonts?: OctopusFonts): ParsedFontConfig | null;
|
|
18
|
+
//# sourceMappingURL=fontParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fontParser.d.ts","sourceRoot":"","sources":["../../../../src/internals/fontParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAChB,MAAM,EACN;QACE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CACF,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,YAAY,GAAG,gBAAgB,GAAG,IAAI,CA0C7E"}
|
package/package.json
CHANGED
package/src/initialize.ts
CHANGED
|
@@ -1,22 +1,99 @@
|
|
|
1
1
|
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
2
|
import type { UserProfileField } from './types/userProfileField';
|
|
3
3
|
import type { ImageResolvedAssetSource } from 'react-native';
|
|
4
|
+
import { Appearance } from 'react-native';
|
|
5
|
+
import { colorSchemeManager } from './internals/colorSchemeManager';
|
|
6
|
+
import { parseFontConfig, type ParsedFontConfig } from './internals/fontParser';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Color set for a specific appearance mode (light or dark).
|
|
10
|
+
*/
|
|
11
|
+
export interface OctopusColorSet {
|
|
12
|
+
/** Primary color set for branding (hex format: #FF6B35 or FF6B35) */
|
|
13
|
+
primary?: string;
|
|
14
|
+
/** Primary low contrast color (lighter variation of primary) (hex format: #FF6B35 or FF6B35) */
|
|
15
|
+
primaryLowContrast?: string;
|
|
16
|
+
/** High contrast variation of primary color (hex format: #FF6B35 or FF6B35) */
|
|
17
|
+
primaryHighContrast?: string;
|
|
18
|
+
/** Color for content displayed over the primary color (hex format: #FF6B35 or FF6B35) */
|
|
19
|
+
onPrimary?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Font type options for unified cross-platform font configuration.
|
|
24
|
+
*/
|
|
25
|
+
export type OctopusFontType = 'serif' | 'monospace' | 'default';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Font size configuration for different text types.
|
|
29
|
+
*/
|
|
30
|
+
export interface OctopusFontSize {
|
|
31
|
+
/** Font size in points (will be converted to platform-specific units) */
|
|
32
|
+
size?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Font configuration for a specific text type.
|
|
37
|
+
*/
|
|
38
|
+
export interface OctopusTextStyle {
|
|
39
|
+
/** Font type: serif, monospace, or default (uses system default) */
|
|
40
|
+
fontType?: OctopusFontType;
|
|
41
|
+
/** Font size configuration */
|
|
42
|
+
fontSize?: OctopusFontSize;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Font configuration for customizing the Octopus UI typography.
|
|
47
|
+
*/
|
|
48
|
+
export interface OctopusFonts {
|
|
49
|
+
/**
|
|
50
|
+
* Unified font configuration for different text types.
|
|
51
|
+
*/
|
|
52
|
+
textStyles?: {
|
|
53
|
+
/** Configuration for title1 text */
|
|
54
|
+
title1?: OctopusTextStyle;
|
|
55
|
+
/** Configuration for title2 text */
|
|
56
|
+
title2?: OctopusTextStyle;
|
|
57
|
+
/** Configuration for body1 text */
|
|
58
|
+
body1?: OctopusTextStyle;
|
|
59
|
+
/** Configuration for body2 text */
|
|
60
|
+
body2?: OctopusTextStyle;
|
|
61
|
+
/** Configuration for caption1 text */
|
|
62
|
+
caption1?: OctopusTextStyle;
|
|
63
|
+
/** Configuration for caption2 text */
|
|
64
|
+
caption2?: OctopusTextStyle;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Pre-processed font configuration for native platforms.
|
|
68
|
+
* This is automatically generated and should not be set manually.
|
|
69
|
+
*/
|
|
70
|
+
parsedConfig?: ParsedFontConfig | null;
|
|
71
|
+
}
|
|
4
72
|
|
|
5
73
|
/**
|
|
6
74
|
* Theme configuration for customizing the Octopus UI appearance.
|
|
75
|
+
*
|
|
76
|
+
* Supports two approaches:
|
|
77
|
+
* 1. Single color set (backward compatible) - colors are applied to both light and dark modes
|
|
78
|
+
* 2. Dual mode colors - separate color sets for light and dark modes
|
|
7
79
|
*/
|
|
8
80
|
export interface OctopusTheme {
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Color customization options.
|
|
83
|
+
*
|
|
84
|
+
* For backward compatibility, you can pass a single color set that will be used for both light and dark modes.
|
|
85
|
+
* For enhanced theming, you can pass separate color sets for light and dark modes.
|
|
86
|
+
*/
|
|
87
|
+
colors?:
|
|
88
|
+
| OctopusColorSet
|
|
89
|
+
| {
|
|
90
|
+
/** Colors for light mode */
|
|
91
|
+
light: OctopusColorSet;
|
|
92
|
+
/** Colors for dark mode */
|
|
93
|
+
dark: OctopusColorSet;
|
|
94
|
+
};
|
|
95
|
+
/** Font customization options */
|
|
96
|
+
fonts?: OctopusFonts;
|
|
20
97
|
/** Logo customization */
|
|
21
98
|
logo?: {
|
|
22
99
|
/** Local image resource - use Image.resolveAssetSource(require('./path/to/image.png')) */
|
|
@@ -77,5 +154,33 @@ export interface InitializeParams {
|
|
|
77
154
|
* ```
|
|
78
155
|
*/
|
|
79
156
|
export function initialize(params: InitializeParams): Promise<void> {
|
|
80
|
-
|
|
157
|
+
// Automatically detect the current color scheme and add it to the params
|
|
158
|
+
const colorScheme = Appearance.getColorScheme();
|
|
159
|
+
|
|
160
|
+
// Pre-process font configuration to avoid duplication in native layers
|
|
161
|
+
const processedTheme = params.theme
|
|
162
|
+
? {
|
|
163
|
+
...params.theme,
|
|
164
|
+
fonts: params.theme.fonts
|
|
165
|
+
? {
|
|
166
|
+
...params.theme.fonts,
|
|
167
|
+
parsedConfig: parseFontConfig(params.theme.fonts),
|
|
168
|
+
}
|
|
169
|
+
: undefined,
|
|
170
|
+
}
|
|
171
|
+
: undefined;
|
|
172
|
+
|
|
173
|
+
const paramsWithColorScheme = {
|
|
174
|
+
...params,
|
|
175
|
+
theme: processedTheme,
|
|
176
|
+
colorScheme: colorScheme || undefined,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Set the theme in the color scheme manager for dual-mode support
|
|
180
|
+
colorSchemeManager.setTheme(processedTheme || null);
|
|
181
|
+
|
|
182
|
+
// Start listening to color scheme changes for automatic updates
|
|
183
|
+
colorSchemeManager.startListening();
|
|
184
|
+
|
|
185
|
+
return OctopusReactNativeSdk.initialize(paramsWithColorScheme);
|
|
81
186
|
}
|