react-native-unit-components 1.7.0 → 1.8.0
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/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +2 -3
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +2 -3
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/commonjs/helpers/pushProvisioningService/hooks/useCardWallet.js.map +1 -1
- package/lib/commonjs/scripts/html/fontFaces.js +56 -0
- package/lib/commonjs/scripts/html/fontFaces.js.map +1 -0
- package/lib/commonjs/styles/fonts.js +71 -0
- package/lib/commonjs/styles/fonts.js.map +1 -0
- package/lib/commonjs/types/shared/fonts.types.js +20 -0
- package/lib/commonjs/types/shared/fonts.types.js.map +1 -0
- package/lib/commonjs/types/shared/index.js +22 -0
- package/lib/commonjs/types/shared/index.js.map +1 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js +6 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.js +5 -3
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/commonjs/webComponent/html.js +11 -2
- package/lib/commonjs/webComponent/html.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js +3 -4
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.js +3 -4
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/module/helpers/pushProvisioningService/hooks/useCardWallet.js.map +1 -1
- package/lib/module/scripts/html/fontFaces.js +49 -0
- package/lib/module/scripts/html/fontFaces.js.map +1 -0
- package/lib/module/styles/fonts.js +64 -0
- package/lib/module/styles/fonts.js.map +1 -0
- package/lib/module/types/shared/fonts.types.js +13 -0
- package/lib/module/types/shared/fonts.types.js.map +1 -0
- package/lib/module/types/shared/index.js +2 -0
- package/lib/module/types/shared/index.js.map +1 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js +6 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/module/webComponent/WebComponent.js +5 -3
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/module/webComponent/html.js +11 -2
- package/lib/module/webComponent/html.js.map +1 -1
- package/lib/typescript/scripts/html/fontFaces.d.ts +2 -0
- package/lib/typescript/styles/fonts.d.ts +1 -0
- package/lib/typescript/types/shared/fonts.types.d.ts +23 -0
- package/lib/typescript/types/shared/index.d.ts +2 -0
- package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +4 -1
- package/lib/typescript/webComponent/WebComponent.d.ts +0 -1
- package/lib/typescript/webComponent/html.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/UNAccountComponent/UNAccountComponent.tsx +2 -4
- package/src/components/UNCardComponent/UNCardComponent.tsx +2 -4
- package/src/helpers/pushProvisioningService/hooks/useCardWallet.ts +2 -2
- package/src/scripts/html/fontFaces.ts +56 -0
- package/src/styles/fonts.ts +70 -0
- package/src/types/shared/fonts.types.ts +28 -0
- package/src/types/shared/index.ts +2 -0
- package/src/unitSdkManager/UnitSdkManager.ts +9 -1
- package/src/webComponent/WebComponent.tsx +7 -4
- package/src/webComponent/html.ts +11 -2
|
@@ -4,7 +4,8 @@ export const HTML_PLACEHOLDER = {
|
|
|
4
4
|
SCRIPT_UNIT: '<SCRIPT_UNIT>',
|
|
5
5
|
BODY: '<BODY_HTML_CODE>',
|
|
6
6
|
SCRIPT_FROM_NATIVE: '<SCRIPT_FROM_NATIVE>',
|
|
7
|
-
WINDOW_PARAMS: '<WINDOW_PARAMS>'
|
|
7
|
+
WINDOW_PARAMS: '<WINDOW_PARAMS>',
|
|
8
|
+
FONT_FACES: '<FONT_FACES>'
|
|
8
9
|
};
|
|
9
10
|
const htmlText = `
|
|
10
11
|
<!DOCTYPE html>
|
|
@@ -21,9 +22,17 @@ const htmlText = `
|
|
|
21
22
|
${HTML_PLACEHOLDER.WINDOW_PARAMS}
|
|
22
23
|
</script>
|
|
23
24
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
|
|
25
|
+
|
|
26
|
+
<style type="text/css">
|
|
27
|
+
${HTML_PLACEHOLDER.FONT_FACES}
|
|
28
|
+
|
|
29
|
+
body {
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
24
33
|
</head>
|
|
25
34
|
|
|
26
|
-
<body
|
|
35
|
+
<body>
|
|
27
36
|
${HTML_PLACEHOLDER.BODY}
|
|
28
37
|
|
|
29
38
|
<script>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","DISPATCH_RENDERING_EVENT","LISTENERS","POST_MESSAGE_TO_SDK","POST_PAGE_HEIGHT","DISPATCH_REQUEST_CARD_ACTION","DISPATCH_OPEN_ACTIONS_MENU","DISPATCH_REQUEST_ACCOUNT_ACTION","DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT","HTML_PLACEHOLDER","SCRIPT_UNIT","BODY","SCRIPT_FROM_NATIVE","WINDOW_PARAMS","htmlText","OS","isPageLoaded","onLoad","unitRequestDownload","requestRendering","requestOpenLink","requestCloseFlow","cardActivated","cardStatusChange","unitRequestExternalSdk","unitAccountChanged","unitActivityFiltersChanged"],"sources":["html.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { DISPATCH_RENDERING_EVENT, LISTENERS, POST_MESSAGE_TO_SDK, POST_PAGE_HEIGHT, DISPATCH_REQUEST_CARD_ACTION, DISPATCH_OPEN_ACTIONS_MENU, DISPATCH_REQUEST_ACCOUNT_ACTION, DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT } from '../scripts/html/bodyScript';\n\nexport const HTML_PLACEHOLDER = {\n SCRIPT_UNIT: '<SCRIPT_UNIT>',\n BODY: '<BODY_HTML_CODE>',\n SCRIPT_FROM_NATIVE: '<SCRIPT_FROM_NATIVE>',\n WINDOW_PARAMS: '<WINDOW_PARAMS>'\n};\n\nconst htmlText = `\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head lang=\"en\">\n <title>Unit Web SDK Demo</title>\n <script>\n window.UnitMobileSDK = true\n window.UnitMobileSDKConfig = {\n os: \"${Platform.OS}\",\n walletName: \"${Platform.OS === 'ios' ? 'Apple' : 'Google'}\",\n }\n ${HTML_PLACEHOLDER.WINDOW_PARAMS}\n </script>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=0\">\n
|
|
1
|
+
{"version":3,"names":["Platform","DISPATCH_RENDERING_EVENT","LISTENERS","POST_MESSAGE_TO_SDK","POST_PAGE_HEIGHT","DISPATCH_REQUEST_CARD_ACTION","DISPATCH_OPEN_ACTIONS_MENU","DISPATCH_REQUEST_ACCOUNT_ACTION","DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT","HTML_PLACEHOLDER","SCRIPT_UNIT","BODY","SCRIPT_FROM_NATIVE","WINDOW_PARAMS","FONT_FACES","htmlText","OS","isPageLoaded","onLoad","unitRequestDownload","requestRendering","requestOpenLink","requestCloseFlow","cardActivated","cardStatusChange","unitRequestExternalSdk","unitAccountChanged","unitActivityFiltersChanged"],"sources":["html.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { DISPATCH_RENDERING_EVENT, LISTENERS, POST_MESSAGE_TO_SDK, POST_PAGE_HEIGHT, DISPATCH_REQUEST_CARD_ACTION, DISPATCH_OPEN_ACTIONS_MENU, DISPATCH_REQUEST_ACCOUNT_ACTION, DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT } from '../scripts/html/bodyScript';\n\nexport const HTML_PLACEHOLDER = {\n SCRIPT_UNIT: '<SCRIPT_UNIT>',\n BODY: '<BODY_HTML_CODE>',\n SCRIPT_FROM_NATIVE: '<SCRIPT_FROM_NATIVE>',\n WINDOW_PARAMS: '<WINDOW_PARAMS>',\n FONT_FACES: '<FONT_FACES>'\n};\n\nconst htmlText = `\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head lang=\"en\">\n <title>Unit Web SDK Demo</title>\n <script>\n window.UnitMobileSDK = true\n window.UnitMobileSDKConfig = {\n os: \"${Platform.OS}\",\n walletName: \"${Platform.OS === 'ios' ? 'Apple' : 'Google'}\",\n }\n ${HTML_PLACEHOLDER.WINDOW_PARAMS}\n </script>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=0\">\n\n <style type=\"text/css\">\n ${HTML_PLACEHOLDER.FONT_FACES}\n\n body {\n margin: 0;\n }\n </style>\n </head>\n\n <body>\n ${HTML_PLACEHOLDER.BODY}\n\n <script>\n ${POST_MESSAGE_TO_SDK}\n\n ${POST_PAGE_HEIGHT}\n\n ${LISTENERS.isPageLoaded}\n\n ${LISTENERS.onLoad}\n\n ${LISTENERS.unitRequestDownload}\n\n ${LISTENERS.requestRendering}\n\n ${LISTENERS.requestOpenLink}\n\n ${LISTENERS.requestCloseFlow}\n\n ${LISTENERS.cardActivated}\n\n ${LISTENERS.cardStatusChange}\n\n ${LISTENERS.unitRequestExternalSdk}\n\n ${LISTENERS.unitAccountChanged}\n\n ${LISTENERS.unitActivityFiltersChanged}\n\n ${DISPATCH_RENDERING_EVENT}\n\n ${DISPATCH_OPEN_ACTIONS_MENU}\n\n ${DISPATCH_REQUEST_CARD_ACTION}\n\n ${DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT}\n\n ${DISPATCH_REQUEST_ACCOUNT_ACTION}\n\n ${HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE}\n </script>\n </body>\n </html>\n`;\n\nexport default htmlText;\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,wBAAwB,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,gBAAgB,EAAEC,4BAA4B,EAAEC,0BAA0B,EAAEC,+BAA+B,EAAEC,sCAAsC,QAAQ,4BAA4B;AAE1P,OAAO,MAAMC,gBAAgB,GAAG;EAC9BC,WAAW,EAAE,eAAe;EAC5BC,IAAI,EAAE,kBAAkB;EACxBC,kBAAkB,EAAE,sBAAsB;EAC1CC,aAAa,EAAE,iBAAiB;EAChCC,UAAU,EAAE;AACd,CAAC;AAED,MAAMC,QAAQ,GAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAaf,QAAQ,CAACgB,EAAG;AACzB,qBAAqBhB,QAAQ,CAACgB,EAAE,KAAK,KAAK,GAAG,OAAO,GAAG,QAAS;AAChE;AACA,MAAMP,gBAAgB,CAACI,aAAc;AACrC;AACA;AACA;AACA;AACA,QAAQJ,gBAAgB,CAACK,UAAW;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAML,gBAAgB,CAACE,IAAK;AAC5B;AACA;AACA,QAAQR,mBAAoB;AAC5B;AACA,QAAQC,gBAAiB;AACzB;AACA,QAAQF,SAAS,CAACe,YAAa;AAC/B;AACA,QAAQf,SAAS,CAACgB,MAAO;AACzB;AACA,QAAQhB,SAAS,CAACiB,mBAAoB;AACtC;AACA,QAAQjB,SAAS,CAACkB,gBAAiB;AACnC;AACA,QAAQlB,SAAS,CAACmB,eAAgB;AAClC;AACA,QAAQnB,SAAS,CAACoB,gBAAiB;AACnC;AACA,QAAQpB,SAAS,CAACqB,aAAc;AAChC;AACA,QAAQrB,SAAS,CAACsB,gBAAiB;AACnC;AACA,QAAQtB,SAAS,CAACuB,sBAAuB;AACzC;AACA,QAAQvB,SAAS,CAACwB,kBAAmB;AACrC;AACA,QAAQxB,SAAS,CAACyB,0BAA2B;AAC7C;AACA,QAAQ1B,wBAAyB;AACjC;AACA,QAAQK,0BAA2B;AACnC;AACA,QAAQD,4BAA6B;AACrC;AACA,QAAQG,sCAAuC;AAC/C;AACA,QAAQD,+BAAgC;AACxC;AACA,QAAQE,gBAAgB,CAACG,kBAAmB;AAC5C;AACA;AACA;AACA,CAAC;AAED,eAAeG,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getFontName: (fontFamily: string, fontWeight: number | string) => string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type UNFonts = {
|
|
2
|
+
[fontFamily: string]: UNFontData[];
|
|
3
|
+
};
|
|
4
|
+
export type UNFontData = {
|
|
5
|
+
fontWeight: FontWeight;
|
|
6
|
+
sources: UNFontSource[];
|
|
7
|
+
};
|
|
8
|
+
export type UNFontSource = {
|
|
9
|
+
fileName: string;
|
|
10
|
+
assetDirRelativePath: string;
|
|
11
|
+
format?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare enum FontWeight {
|
|
14
|
+
Thin = 100,
|
|
15
|
+
ExtraLight = 200,
|
|
16
|
+
Light = 300,
|
|
17
|
+
Regular = 400,
|
|
18
|
+
Medium = 500,
|
|
19
|
+
SemiBold = 600,
|
|
20
|
+
Bold = 700,
|
|
21
|
+
ExtraBold = 800,
|
|
22
|
+
Black = 900
|
|
23
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NativeModules } from 'react-native';
|
|
2
2
|
import { UnitUiManager } from './unitUiManager/unitUiManager';
|
|
3
|
+
import type { UNFonts } from '../types/shared/fonts.types';
|
|
3
4
|
export declare enum UNEnvironment {
|
|
4
5
|
sandbox = "sandbox",
|
|
5
6
|
production = "production"
|
|
@@ -13,16 +14,18 @@ export declare class UnitSDK {
|
|
|
13
14
|
protected static customerToken?: string;
|
|
14
15
|
protected static theme?: string;
|
|
15
16
|
protected static language?: string;
|
|
17
|
+
protected static fonts?: UNFonts;
|
|
16
18
|
protected static signedNonce?: string;
|
|
17
19
|
protected static pushProvisionModule?: typeof NativeModules;
|
|
18
20
|
static ui: UnitUiManager;
|
|
19
|
-
static init: (env: UNEnvironment, theme?: string, language?: string) => Promise<void>;
|
|
21
|
+
static init: (env: UNEnvironment, theme?: string, language?: string, fonts?: UNFonts) => Promise<void>;
|
|
20
22
|
static setPushProvisioningModule: (pushProvisionModule: typeof NativeModules) => void;
|
|
21
23
|
static getPushProvisionModule: () => import("react-native").NativeModulesStatic | undefined;
|
|
22
24
|
static setSignedNonce: (signedNonce: string) => void;
|
|
23
25
|
static getEnv: () => UNEnvironment | undefined;
|
|
24
26
|
static getTheme: () => string | undefined;
|
|
25
27
|
static getLanguage: () => string | undefined;
|
|
28
|
+
static getFonts: () => UNFonts | undefined;
|
|
26
29
|
static getSignedNonce: () => string | undefined;
|
|
27
30
|
static setCustomerToken: (customerToken: string) => void;
|
|
28
31
|
static getCustomerToken: () => string | undefined;
|
|
@@ -13,7 +13,6 @@ export interface WebComponentProps {
|
|
|
13
13
|
isScrollable?: boolean;
|
|
14
14
|
nestedScrollEnabled?: boolean;
|
|
15
15
|
handleScroll?: (event: any) => void;
|
|
16
|
-
width?: number;
|
|
17
16
|
windowParams?: string;
|
|
18
17
|
}
|
|
19
18
|
export declare const WebComponent: React.ForwardRefExoticComponent<WebComponentProps & React.RefAttributes<WebView<{}>>>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
import type WebView from 'react-native-webview';
|
|
4
4
|
import { HeightEvent, PageMessage } from '../..//messages/webMessages/pageMessage';
|
|
5
5
|
import { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
@@ -45,7 +45,6 @@ export enum AccountAction {
|
|
|
45
45
|
|
|
46
46
|
export const UNAccountComponent = React.forwardRef<UNAccountRef, UNAccountComponentProps>(function UNAccountComponent(props, accountRef) {
|
|
47
47
|
const [height, setHeight] = useState(0);
|
|
48
|
-
const windowWidth = Dimensions.get('window').width;
|
|
49
48
|
|
|
50
49
|
const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);
|
|
51
50
|
|
|
@@ -122,7 +121,7 @@ export const UNAccountComponent = React.forwardRef<UNAccountRef, UNAccountCompon
|
|
|
122
121
|
};
|
|
123
122
|
|
|
124
123
|
return (
|
|
125
|
-
<View style={{ height }}>
|
|
124
|
+
<View style={{ height, width: '100%' }}>
|
|
126
125
|
<WebComponent
|
|
127
126
|
ref={webRef}
|
|
128
127
|
type={WebComponentType.account}
|
|
@@ -132,7 +131,6 @@ export const UNAccountComponent = React.forwardRef<UNAccountRef, UNAccountCompon
|
|
|
132
131
|
theme={props.theme}
|
|
133
132
|
language={props.language}
|
|
134
133
|
onMessage={message => handleMessage(message)}
|
|
135
|
-
width={windowWidth}
|
|
136
134
|
isScrollable={false}
|
|
137
135
|
/>
|
|
138
136
|
</View>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useImperativeHandle, useRef, useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
import type WebView from 'react-native-webview';
|
|
4
4
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
5
5
|
import { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
@@ -42,7 +42,6 @@ export interface CardRef {
|
|
|
42
42
|
|
|
43
43
|
export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(function UNCardComponent(props, cardRef) {
|
|
44
44
|
const [height, setHeight] = useState(0);
|
|
45
|
-
const windowWidth = Dimensions.get('window').width;
|
|
46
45
|
|
|
47
46
|
const webRef = useRef<WebView>(null);
|
|
48
47
|
|
|
@@ -134,7 +133,7 @@ export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(f
|
|
|
134
133
|
}, [props.pushProvisioningModule]);
|
|
135
134
|
|
|
136
135
|
return (
|
|
137
|
-
<View style={{ height }}>
|
|
136
|
+
<View style={{ height, width: '100%' }}>
|
|
138
137
|
<WebComponent
|
|
139
138
|
ref={webRef}
|
|
140
139
|
type={WebComponentType.card}
|
|
@@ -144,7 +143,6 @@ export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(f
|
|
|
144
143
|
language={props.language}
|
|
145
144
|
script={getCardScript()}
|
|
146
145
|
onMessage={message => handleMessage(message)}
|
|
147
|
-
width={windowWidth}
|
|
148
146
|
isScrollable={false}
|
|
149
147
|
/>
|
|
150
148
|
</View>
|
|
@@ -20,7 +20,7 @@ export const useCardWallet = (cardId: string) => {
|
|
|
20
20
|
return encryptedPayload;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const getCardWalletData = async ()
|
|
23
|
+
const getCardWalletData = async () => {
|
|
24
24
|
const currentProvisioningModule = UnitSDK.getPushProvisionModule();
|
|
25
25
|
if (!currentProvisioningModule) return;
|
|
26
26
|
try {
|
|
@@ -46,7 +46,7 @@ export const useCardWallet = (cardId: string) => {
|
|
|
46
46
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
const parseWalletsResponse = (walletsResponse: string): UNWallet | null
|
|
49
|
+
const parseWalletsResponse = (walletsResponse: string): UNWallet | null => {
|
|
50
50
|
try {
|
|
51
51
|
const parsedWalletsResponse = JSON.parse(walletsResponse);
|
|
52
52
|
const wallets = parsedWalletsResponse.wallets;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import type { FontWeight, UNFonts, UNFontSource, UNFontData } from '../../types/shared/fonts.types';
|
|
3
|
+
|
|
4
|
+
const getUrl = (source: UNFontSource): string => {
|
|
5
|
+
if (Platform.OS == 'ios') {
|
|
6
|
+
return `url('${source.fileName}')`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Handle '/' of dir Relative path
|
|
10
|
+
let relativeDirPath = source.assetDirRelativePath;
|
|
11
|
+
if (source.assetDirRelativePath[-1] !== '/') {
|
|
12
|
+
relativeDirPath = `${source.assetDirRelativePath}/`;
|
|
13
|
+
}
|
|
14
|
+
if (source.assetDirRelativePath[0] !== '/') {
|
|
15
|
+
relativeDirPath = `/${source.assetDirRelativePath}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `url('file:///android_asset${relativeDirPath}${source.fileName}')`;
|
|
19
|
+
};
|
|
20
|
+
const getFontFace = (fontFamily: string, fontWeight: FontWeight, sources: UNFontSource[]): string => {
|
|
21
|
+
const numOfSources = sources.length;
|
|
22
|
+
|
|
23
|
+
const sourcesString = sources
|
|
24
|
+
.map((source, index) => {
|
|
25
|
+
const suffix = index === numOfSources - 1 ? ';' : ',';
|
|
26
|
+
const url = getUrl(source);
|
|
27
|
+
const format = source?.format ? `format('${source.format}')` : '';
|
|
28
|
+
return `${url} ${format}${suffix}`;
|
|
29
|
+
})
|
|
30
|
+
.join('\n');
|
|
31
|
+
|
|
32
|
+
return `
|
|
33
|
+
@font-face {
|
|
34
|
+
font-family: '${fontFamily}';
|
|
35
|
+
src: ${sourcesString}
|
|
36
|
+
font-weight: ${fontWeight.valueOf()};
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getFontFacesString = (fonts?: UNFonts): string => {
|
|
42
|
+
if (!fonts) return '';
|
|
43
|
+
|
|
44
|
+
const fontFaces: string[] = [];
|
|
45
|
+
|
|
46
|
+
// Iterate over all the fonts and their variants
|
|
47
|
+
// create font-face for each variant
|
|
48
|
+
Object.entries(fonts).forEach(([familyName, familyFonts]) => {
|
|
49
|
+
familyFonts.forEach((fontData: UNFontData) => {
|
|
50
|
+
fontFaces.push(getFontFace(familyName, fontData.fontWeight, fontData.sources));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Combine all the font faces into a single string
|
|
55
|
+
return fontFaces.join('\n');
|
|
56
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FontWeight, UNFontData } from '../types/shared';
|
|
2
|
+
import { UnitSDK } from '../unitSdkManager/UnitSdkManager';
|
|
3
|
+
|
|
4
|
+
const getFontWeightName = (familyFonts: UNFontData[], fontWeight?: number | string) => {
|
|
5
|
+
/**
|
|
6
|
+
* Given family variants and the required weight
|
|
7
|
+
* Return the closet font that defined by the client.
|
|
8
|
+
*/
|
|
9
|
+
if (!fontWeight || fontWeight === 'normal') return 'Regular';
|
|
10
|
+
|
|
11
|
+
if (fontWeight === 'bold') return 'Bold';
|
|
12
|
+
|
|
13
|
+
const fontWeightNumber = Number(fontWeight);
|
|
14
|
+
|
|
15
|
+
// Select the closet variant
|
|
16
|
+
let selectedFontWeight = FontWeight.Regular.valueOf();
|
|
17
|
+
let minDistance = 1000;
|
|
18
|
+
|
|
19
|
+
familyFonts.forEach((fontData: UNFontData) => {
|
|
20
|
+
const currDistance = Math.abs(fontData.fontWeight - fontWeightNumber);
|
|
21
|
+
if (currDistance < minDistance) {
|
|
22
|
+
minDistance = currDistance;
|
|
23
|
+
selectedFontWeight = fontData.fontWeight.valueOf();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// FontWeight to String
|
|
28
|
+
switch (selectedFontWeight) {
|
|
29
|
+
case FontWeight.Thin:
|
|
30
|
+
return 'Thin';
|
|
31
|
+
case FontWeight.ExtraLight:
|
|
32
|
+
return 'ExtraLight';
|
|
33
|
+
case FontWeight.Light:
|
|
34
|
+
return 'Light';
|
|
35
|
+
case FontWeight.Regular:
|
|
36
|
+
return 'Regular';
|
|
37
|
+
case FontWeight.Medium:
|
|
38
|
+
return 'Medium';
|
|
39
|
+
case FontWeight.SemiBold:
|
|
40
|
+
return 'SemiBold';
|
|
41
|
+
case FontWeight.Bold:
|
|
42
|
+
return 'Bold';
|
|
43
|
+
case FontWeight.ExtraBold:
|
|
44
|
+
return 'ExtraBold';
|
|
45
|
+
case FontWeight.Black:
|
|
46
|
+
return 'Black';
|
|
47
|
+
default:
|
|
48
|
+
return 'Regular';
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getFontName = (fontFamily: string, fontWeight: number | string): string => {
|
|
53
|
+
/*
|
|
54
|
+
* Get the font family name and the font weight name from the THEME object.
|
|
55
|
+
* Then, return a possible font.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
const fontsInApp = UnitSDK.getFonts();
|
|
59
|
+
if (!fontsInApp) {
|
|
60
|
+
throw new Error('Fonts are not found in the app');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const familyFonts = fontsInApp[fontFamily];
|
|
64
|
+
if (!familyFonts) {
|
|
65
|
+
throw new Error(`Font family ${fontFamily} not found in the app's fonts`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const fontWeightName = getFontWeightName(familyFonts, fontWeight);
|
|
69
|
+
return `${fontFamily}-${fontWeightName}`;
|
|
70
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type UNFonts = {
|
|
2
|
+
[fontFamily: string]: UNFontData[];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type UNFontData = {
|
|
6
|
+
// Using 'field' instead of 'key' to account for potential variants unrelated to font weight.
|
|
7
|
+
fontWeight: FontWeight;
|
|
8
|
+
sources: UNFontSource[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type UNFontSource = {
|
|
12
|
+
// using the fileName for iOS and relative path for Android
|
|
13
|
+
fileName: string;
|
|
14
|
+
assetDirRelativePath: string;
|
|
15
|
+
format?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum FontWeight {
|
|
19
|
+
Thin = 100,
|
|
20
|
+
ExtraLight = 200,
|
|
21
|
+
Light = 300,
|
|
22
|
+
Regular = 400,
|
|
23
|
+
Medium = 500,
|
|
24
|
+
SemiBold = 600,
|
|
25
|
+
Bold = 700,
|
|
26
|
+
ExtraBold = 800,
|
|
27
|
+
Black = 900
|
|
28
|
+
}
|
|
@@ -3,6 +3,7 @@ import EventBus from '../helpers/EventBus';
|
|
|
3
3
|
import { SDKMessage } from '../messages/nativeMessages/sdkMessage';
|
|
4
4
|
import { fetchUnitScript } from './UnitSdk.api';
|
|
5
5
|
import { UnitUiManager } from './unitUiManager/unitUiManager';
|
|
6
|
+
import type { UNFonts } from '../types/shared/fonts.types';
|
|
6
7
|
|
|
7
8
|
export enum UNEnvironment {
|
|
8
9
|
sandbox = 'sandbox',
|
|
@@ -20,17 +21,20 @@ export class UnitSDK {
|
|
|
20
21
|
protected static customerToken?: string;
|
|
21
22
|
protected static theme?: string;
|
|
22
23
|
protected static language?: string;
|
|
24
|
+
protected static fonts?: UNFonts;
|
|
23
25
|
|
|
24
26
|
protected static signedNonce?: string;
|
|
25
27
|
protected static pushProvisionModule?: typeof NativeModules;
|
|
26
28
|
|
|
27
29
|
public static ui: UnitUiManager;
|
|
28
30
|
|
|
29
|
-
public static init = async (env: UNEnvironment, theme?: string, language?: string) => {
|
|
31
|
+
public static init = async (env: UNEnvironment, theme?: string, language?: string, fonts?: UNFonts) => {
|
|
30
32
|
try {
|
|
31
33
|
this.env = env;
|
|
32
34
|
this.theme = theme;
|
|
33
35
|
this.language = language;
|
|
36
|
+
this.fonts = fonts;
|
|
37
|
+
|
|
34
38
|
this.ui = new UnitUiManager();
|
|
35
39
|
await fetchUnitScript();
|
|
36
40
|
EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});
|
|
@@ -63,6 +67,10 @@ export class UnitSDK {
|
|
|
63
67
|
return this.language;
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
public static getFonts = () => {
|
|
71
|
+
return this.fonts;
|
|
72
|
+
};
|
|
73
|
+
|
|
66
74
|
public static getSignedNonce = () => {
|
|
67
75
|
return this.signedNonce;
|
|
68
76
|
};
|
|
@@ -13,6 +13,7 @@ import type { WebViewMessage } from '../messages/webMessages';
|
|
|
13
13
|
import { SDKMessage, SdkScriptFetched } from '../messages/nativeMessages/sdkMessage';
|
|
14
14
|
import { handleRequestDownload } from './WebComponent.utils';
|
|
15
15
|
import type { PresentationMode, WebComponentType } from '../types/internal/webComponent.types';
|
|
16
|
+
import { getFontFacesString } from '../scripts/html/fontFaces';
|
|
16
17
|
|
|
17
18
|
const { UNAppInfo } = NativeModules;
|
|
18
19
|
|
|
@@ -27,7 +28,6 @@ export interface WebComponentProps {
|
|
|
27
28
|
isScrollable?: boolean,
|
|
28
29
|
nestedScrollEnabled?: boolean,
|
|
29
30
|
handleScroll?: (event: any) => void,
|
|
30
|
-
width?: number;
|
|
31
31
|
windowParams?: string;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -37,7 +37,6 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
37
37
|
const [componentCurrentTheme, setComponentCurrentTheme] = useState<string | undefined>(props.theme ?? UnitSDK.getTheme());
|
|
38
38
|
const [componentCurrentLanguage, setComponentCurrentLanguage] = useState<string | undefined>(props.language ?? UnitSDK.getLanguage());
|
|
39
39
|
const [baseName, setBaseName] = useState<string>();
|
|
40
|
-
const width = props.width ?? '100%';
|
|
41
40
|
|
|
42
41
|
const updateUnitScript = (data: SdkScriptFetched) => {
|
|
43
42
|
setUnitScript(data.unitScript);
|
|
@@ -81,7 +80,11 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
81
80
|
const languageParam = componentCurrentLanguage ? ` language="${componentCurrentLanguage}"` : '';
|
|
82
81
|
|
|
83
82
|
const componentParams = (props.params || '') + themeParam + languageParam;
|
|
83
|
+
|
|
84
|
+
const fontFaces = getFontFacesString(UnitSDK.getFonts());
|
|
85
|
+
|
|
84
86
|
let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));
|
|
87
|
+
newHtml = newHtml.replace(HTML_PLACEHOLDER.FONT_FACES, fontFaces);
|
|
85
88
|
newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');
|
|
86
89
|
newHtml = newHtml.replace(HTML_PLACEHOLDER.WINDOW_PARAMS, props.windowParams || '');
|
|
87
90
|
setSourceHtml(newHtml);
|
|
@@ -131,8 +134,8 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
131
134
|
onScroll={_onScroll}
|
|
132
135
|
overScrollMode="never"
|
|
133
136
|
injectedJavaScript={unitScript}
|
|
134
|
-
style={{ width:
|
|
135
|
-
source={{ html: sourceHtml, baseUrl: `https://${baseName}` }}
|
|
137
|
+
style={{ width: '100%', flex: 1, opacity: 0.99, backgroundColor: 'transparent' }}
|
|
138
|
+
source={{ html: sourceHtml, baseUrl: Platform.OS === 'android' ? `https://${baseName}` : ''}}
|
|
136
139
|
onMessage={onMessage}
|
|
137
140
|
androidHardwareAccelerationDisabled
|
|
138
141
|
/>
|
package/src/webComponent/html.ts
CHANGED
|
@@ -5,7 +5,8 @@ export const HTML_PLACEHOLDER = {
|
|
|
5
5
|
SCRIPT_UNIT: '<SCRIPT_UNIT>',
|
|
6
6
|
BODY: '<BODY_HTML_CODE>',
|
|
7
7
|
SCRIPT_FROM_NATIVE: '<SCRIPT_FROM_NATIVE>',
|
|
8
|
-
WINDOW_PARAMS: '<WINDOW_PARAMS>'
|
|
8
|
+
WINDOW_PARAMS: '<WINDOW_PARAMS>',
|
|
9
|
+
FONT_FACES: '<FONT_FACES>'
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
const htmlText = `
|
|
@@ -23,9 +24,17 @@ const htmlText = `
|
|
|
23
24
|
${HTML_PLACEHOLDER.WINDOW_PARAMS}
|
|
24
25
|
</script>
|
|
25
26
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
|
|
27
|
+
|
|
28
|
+
<style type="text/css">
|
|
29
|
+
${HTML_PLACEHOLDER.FONT_FACES}
|
|
30
|
+
|
|
31
|
+
body {
|
|
32
|
+
margin: 0;
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
26
35
|
</head>
|
|
27
36
|
|
|
28
|
-
<body
|
|
37
|
+
<body>
|
|
29
38
|
${HTML_PLACEHOLDER.BODY}
|
|
30
39
|
|
|
31
40
|
<script>
|