react-native-unit-components 1.7.1 → 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.
Files changed (45) hide show
  1. package/lib/commonjs/helpers/pushProvisioningService/hooks/useCardWallet.js.map +1 -1
  2. package/lib/commonjs/scripts/html/fontFaces.js +56 -0
  3. package/lib/commonjs/scripts/html/fontFaces.js.map +1 -0
  4. package/lib/commonjs/styles/fonts.js +71 -0
  5. package/lib/commonjs/styles/fonts.js.map +1 -0
  6. package/lib/commonjs/types/shared/fonts.types.js +20 -0
  7. package/lib/commonjs/types/shared/fonts.types.js.map +1 -0
  8. package/lib/commonjs/types/shared/index.js +22 -0
  9. package/lib/commonjs/types/shared/index.js.map +1 -1
  10. package/lib/commonjs/unitSdkManager/UnitSdkManager.js +6 -1
  11. package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
  12. package/lib/commonjs/webComponent/WebComponent.js +4 -1
  13. package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
  14. package/lib/commonjs/webComponent/html.js +11 -2
  15. package/lib/commonjs/webComponent/html.js.map +1 -1
  16. package/lib/module/helpers/pushProvisioningService/hooks/useCardWallet.js.map +1 -1
  17. package/lib/module/scripts/html/fontFaces.js +49 -0
  18. package/lib/module/scripts/html/fontFaces.js.map +1 -0
  19. package/lib/module/styles/fonts.js +64 -0
  20. package/lib/module/styles/fonts.js.map +1 -0
  21. package/lib/module/types/shared/fonts.types.js +13 -0
  22. package/lib/module/types/shared/fonts.types.js.map +1 -0
  23. package/lib/module/types/shared/index.js +2 -0
  24. package/lib/module/types/shared/index.js.map +1 -1
  25. package/lib/module/unitSdkManager/UnitSdkManager.js +6 -1
  26. package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
  27. package/lib/module/webComponent/WebComponent.js +4 -1
  28. package/lib/module/webComponent/WebComponent.js.map +1 -1
  29. package/lib/module/webComponent/html.js +11 -2
  30. package/lib/module/webComponent/html.js.map +1 -1
  31. package/lib/typescript/scripts/html/fontFaces.d.ts +2 -0
  32. package/lib/typescript/styles/fonts.d.ts +1 -0
  33. package/lib/typescript/types/shared/fonts.types.d.ts +23 -0
  34. package/lib/typescript/types/shared/index.d.ts +2 -0
  35. package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +4 -1
  36. package/lib/typescript/webComponent/html.d.ts +1 -0
  37. package/package.json +1 -1
  38. package/src/helpers/pushProvisioningService/hooks/useCardWallet.ts +2 -2
  39. package/src/scripts/html/fontFaces.ts +56 -0
  40. package/src/styles/fonts.ts +70 -0
  41. package/src/types/shared/fonts.types.ts +28 -0
  42. package/src/types/shared/index.ts +2 -0
  43. package/src/unitSdkManager/UnitSdkManager.ts +9 -1
  44. package/src/webComponent/WebComponent.tsx +6 -1
  45. package/src/webComponent/html.ts +11 -2
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FontWeight","UnitSDK","getFontWeightName","familyFonts","fontWeight","fontWeightNumber","Number","selectedFontWeight","Regular","valueOf","minDistance","forEach","fontData","currDistance","Math","abs","Thin","ExtraLight","Light","Medium","SemiBold","Bold","ExtraBold","Black","getFontName","fontFamily","fontsInApp","getFonts","Error","fontWeightName"],"sources":["fonts.ts"],"sourcesContent":["import { FontWeight, UNFontData } from '../types/shared';\nimport { UnitSDK } from '../unitSdkManager/UnitSdkManager';\n\nconst getFontWeightName = (familyFonts: UNFontData[], fontWeight?: number | string) => {\n /**\n * Given family variants and the required weight\n * Return the closet font that defined by the client.\n */\n if (!fontWeight || fontWeight === 'normal') return 'Regular';\n\n if (fontWeight === 'bold') return 'Bold';\n\n const fontWeightNumber = Number(fontWeight);\n\n // Select the closet variant\n let selectedFontWeight = FontWeight.Regular.valueOf();\n let minDistance = 1000;\n\n familyFonts.forEach((fontData: UNFontData) => {\n const currDistance = Math.abs(fontData.fontWeight - fontWeightNumber);\n if (currDistance < minDistance) {\n minDistance = currDistance;\n selectedFontWeight = fontData.fontWeight.valueOf();\n }\n });\n\n // FontWeight to String\n switch (selectedFontWeight) {\n case FontWeight.Thin:\n return 'Thin';\n case FontWeight.ExtraLight:\n return 'ExtraLight';\n case FontWeight.Light:\n return 'Light';\n case FontWeight.Regular:\n return 'Regular';\n case FontWeight.Medium:\n return 'Medium';\n case FontWeight.SemiBold:\n return 'SemiBold';\n case FontWeight.Bold:\n return 'Bold';\n case FontWeight.ExtraBold:\n return 'ExtraBold';\n case FontWeight.Black:\n return 'Black';\n default:\n return 'Regular';\n }\n};\n\nexport const getFontName = (fontFamily: string, fontWeight: number | string): string => {\n /*\n * Get the font family name and the font weight name from the THEME object.\n * Then, return a possible font.\n */\n\n const fontsInApp = UnitSDK.getFonts();\n if (!fontsInApp) {\n throw new Error('Fonts are not found in the app');\n }\n\n const familyFonts = fontsInApp[fontFamily];\n if (!familyFonts) {\n throw new Error(`Font family ${fontFamily} not found in the app's fonts`);\n }\n\n const fontWeightName = getFontWeightName(familyFonts, fontWeight);\n return `${fontFamily}-${fontWeightName}`;\n};\n"],"mappings":"AAAA,SAASA,UAAU,QAAoB,iBAAiB;AACxD,SAASC,OAAO,QAAQ,kCAAkC;AAE1D,MAAMC,iBAAiB,GAAGA,CAACC,WAAyB,EAAEC,UAA4B,KAAK;EACrF;AACF;AACA;AACA;EACE,IAAI,CAACA,UAAU,IAAIA,UAAU,KAAK,QAAQ,EAAE,OAAO,SAAS;EAE5D,IAAIA,UAAU,KAAK,MAAM,EAAE,OAAO,MAAM;EAExC,MAAMC,gBAAgB,GAAGC,MAAM,CAACF,UAAU,CAAC;;EAE3C;EACA,IAAIG,kBAAkB,GAAGP,UAAU,CAACQ,OAAO,CAACC,OAAO,EAAE;EACrD,IAAIC,WAAW,GAAG,IAAI;EAEtBP,WAAW,CAACQ,OAAO,CAAEC,QAAoB,IAAK;IAC5C,MAAMC,YAAY,GAAGC,IAAI,CAACC,GAAG,CAACH,QAAQ,CAACR,UAAU,GAAGC,gBAAgB,CAAC;IACrE,IAAIQ,YAAY,GAAGH,WAAW,EAAE;MAC9B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thin";
4
+ FontWeight[FontWeight["ExtraLight"] = 200] = "ExtraLight";
5
+ FontWeight[FontWeight["Light"] = 300] = "Light";
6
+ FontWeight[FontWeight["Regular"] = 400] = "Regular";
7
+ FontWeight[FontWeight["Medium"] = 500] = "Medium";
8
+ FontWeight[FontWeight["SemiBold"] = 600] = "SemiBold";
9
+ FontWeight[FontWeight["Bold"] = 700] = "Bold";
10
+ FontWeight[FontWeight["ExtraBold"] = 800] = "ExtraBold";
11
+ FontWeight[FontWeight["Black"] = 900] = "Black";
12
+ })(FontWeight || (FontWeight = {}));
13
+ //# sourceMappingURL=fonts.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FontWeight"],"sources":["fonts.types.ts"],"sourcesContent":["export type UNFonts = {\n [fontFamily: string]: UNFontData[];\n}\n\nexport type UNFontData = {\n // Using 'field' instead of 'key' to account for potential variants unrelated to font weight.\n fontWeight: FontWeight;\n sources: UNFontSource[];\n}\n\nexport type UNFontSource = {\n // using the fileName for iOS and relative path for Android\n fileName: string;\n assetDirRelativePath: string;\n format?: string;\n}\n\nexport enum FontWeight {\n Thin = 100,\n ExtraLight = 200,\n Light = 300,\n Regular = 400,\n Medium = 500,\n SemiBold = 600,\n Bold = 700,\n ExtraBold = 800,\n Black = 900\n}\n"],"mappings":"AAiBA,WAAYA,UAAU;AAUrB,WAVWA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;AAAA,GAAVA,UAAU,KAAVA,UAAU"}
@@ -5,4 +5,6 @@ export * from './achCredit.types';
5
5
  export * from './payments.types';
6
6
  export * from './account.types';
7
7
  export * from './checkDeposit.types';
8
+ export * from './activity.types';
9
+ export * from './fonts.types';
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './bookPayment.types';\nexport * from './card.types';\nexport * from './onLoadResponse.types';\nexport * from './achCredit.types';\nexport * from './payments.types';\nexport * from './account.types';\nexport * from './checkDeposit.types';\n"],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,cAAc;AAC5B,cAAc,wBAAwB;AACtC,cAAc,mBAAmB;AACjC,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAC/B,cAAc,sBAAsB"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './bookPayment.types';\nexport * from './card.types';\nexport * from './onLoadResponse.types';\nexport * from './achCredit.types';\nexport * from './payments.types';\nexport * from './account.types';\nexport * from './checkDeposit.types';\nexport * from './activity.types';\nexport * from './fonts.types';\n"],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,cAAc;AAC5B,cAAc,wBAAwB;AACtC,cAAc,mBAAmB;AACjC,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAC/B,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,eAAe"}
@@ -20,14 +20,16 @@ _defineProperty(UnitSDK, "env", void 0);
20
20
  _defineProperty(UnitSDK, "customerToken", void 0);
21
21
  _defineProperty(UnitSDK, "theme", void 0);
22
22
  _defineProperty(UnitSDK, "language", void 0);
23
+ _defineProperty(UnitSDK, "fonts", void 0);
23
24
  _defineProperty(UnitSDK, "signedNonce", void 0);
24
25
  _defineProperty(UnitSDK, "pushProvisionModule", void 0);
25
26
  _defineProperty(UnitSDK, "ui", void 0);
26
- _defineProperty(UnitSDK, "init", async (env, theme, language) => {
27
+ _defineProperty(UnitSDK, "init", async (env, theme, language, fonts) => {
27
28
  try {
28
29
  UnitSDK.env = env;
29
30
  UnitSDK.theme = theme;
30
31
  UnitSDK.language = language;
32
+ UnitSDK.fonts = fonts;
31
33
  UnitSDK.ui = new UnitUiManager();
32
34
  await fetchUnitScript();
33
35
  EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});
@@ -53,6 +55,9 @@ _defineProperty(UnitSDK, "getTheme", () => {
53
55
  _defineProperty(UnitSDK, "getLanguage", () => {
54
56
  return UnitSDK.language;
55
57
  });
58
+ _defineProperty(UnitSDK, "getFonts", () => {
59
+ return UnitSDK.fonts;
60
+ });
56
61
  _defineProperty(UnitSDK, "getSignedNonce", () => {
57
62
  return UnitSDK.signedNonce;
58
63
  });
@@ -1 +1 @@
1
- {"version":3,"names":["EventBus","SDKMessage","fetchUnitScript","UnitUiManager","UNEnvironment","UNIT_WEB_VERSION","UNIT_SCRIPT_URL","sandbox","production","UnitSDK","_defineProperty","env","theme","language","ui","Instance","event","IS_SDK_INITIALIZED","e","console","log","pushProvisionModule","signedNonce","customerToken"],"sources":["UnitSdkManager.ts"],"sourcesContent":["import type { NativeModules } from 'react-native';\nimport EventBus from '../helpers/EventBus';\nimport { SDKMessage } from '../messages/nativeMessages/sdkMessage';\nimport { fetchUnitScript } from './UnitSdk.api';\nimport { UnitUiManager } from './unitUiManager/unitUiManager';\n\nexport enum UNEnvironment {\n sandbox = 'sandbox',\n production = 'production'\n}\n\nconst UNIT_WEB_VERSION = '1';\n\nexport const UNIT_SCRIPT_URL = {\n [UNEnvironment.sandbox]: `https://ui.s.unit.sh/release/${UNIT_WEB_VERSION}/components.js`,\n [UNEnvironment.production]: `https://ui.unit.co/release/${UNIT_WEB_VERSION}/components.js`\n};\nexport class UnitSDK {\n protected static env?: UNEnvironment;\n protected static customerToken?: string;\n protected static theme?: string;\n protected static language?: string;\n\n protected static signedNonce?: string;\n protected static pushProvisionModule?: typeof NativeModules;\n\n public static ui: UnitUiManager;\n\n public static init = async (env: UNEnvironment, theme?: string, language?: string) => {\n try {\n this.env = env;\n this.theme = theme;\n this.language = language;\n this.ui = new UnitUiManager();\n await fetchUnitScript();\n EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});\n } catch (e) {\n console.log(e);\n }\n };\n\n public static setPushProvisioningModule = (pushProvisionModule: typeof NativeModules) => {\n this.pushProvisionModule = pushProvisionModule;\n };\n\n public static getPushProvisionModule = () => {\n return this.pushProvisionModule;\n };\n\n public static setSignedNonce = (signedNonce: string) => {\n this.signedNonce = signedNonce;\n };\n\n public static getEnv = () => {\n return this.env;\n };\n\n public static getTheme = () => {\n return this.theme;\n };\n\n public static getLanguage = () => {\n return this.language;\n };\n\n public static getSignedNonce = () => {\n return this.signedNonce;\n };\n\n public static setCustomerToken = (customerToken: string) => {\n this.customerToken = customerToken;\n };\n\n public static getCustomerToken = () => {\n return this.customerToken;\n };\n}\n"],"mappings":";;;AACA,OAAOA,QAAQ,MAAM,qBAAqB;AAC1C,SAASC,UAAU,QAAQ,uCAAuC;AAClE,SAASC,eAAe,QAAQ,eAAe;AAC/C,SAASC,aAAa,QAAQ,+BAA+B;AAE7D,WAAYC,aAAa;AAGxB,WAHWA,aAAa;EAAbA,aAAa;EAAbA,aAAa;AAAA,GAAbA,aAAa,KAAbA,aAAa;AAKzB,MAAMC,gBAAgB,GAAG,GAAG;AAE5B,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACF,aAAa,CAACG,OAAO,GAAI,gCAA+BF,gBAAiB,gBAAe;EACzF,CAACD,aAAa,CAACI,UAAU,GAAI,8BAA6BH,gBAAiB;AAC7E,CAAC;AACD,OAAO,MAAMI,OAAO,CAAC;AA2DpBC,eAAA,CA3DYD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO,UAWG,OAAOE,GAAkB,EAAEC,KAAc,EAAEC,QAAiB,KAAK;EACpF,IAAI;IAZKJ,OAAO,CAaTE,GAAG,GAAGA,GAAG;IAbPF,OAAO,C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DKMessage","fetchUnitScript","UnitUiManager","UNEnvironment","UNIT_WEB_VERSION","UNIT_SCRIPT_URL","sandbox","production","UnitSDK","_defineProperty","env","theme","language","fonts","ui","Instance","event","IS_SDK_INITIALIZED","e","console","log","pushProvisionModule","signedNonce","customerToken"],"sources":["UnitSdkManager.ts"],"sourcesContent":["import type { NativeModules } from 'react-native';\nimport EventBus from '../helpers/EventBus';\nimport { SDKMessage } from '../messages/nativeMessages/sdkMessage';\nimport { fetchUnitScript } from './UnitSdk.api';\nimport { UnitUiManager } from './unitUiManager/unitUiManager';\nimport type { UNFonts } from '../types/shared/fonts.types';\n\nexport enum UNEnvironment {\n sandbox = 'sandbox',\n production = 'production'\n}\n\nconst UNIT_WEB_VERSION = '1';\n\nexport const UNIT_SCRIPT_URL = {\n [UNEnvironment.sandbox]: `https://ui.s.unit.sh/release/${UNIT_WEB_VERSION}/components.js`,\n [UNEnvironment.production]: `https://ui.unit.co/release/${UNIT_WEB_VERSION}/components.js`\n};\nexport class UnitSDK {\n protected static env?: UNEnvironment;\n protected static customerToken?: string;\n protected static theme?: string;\n protected static language?: string;\n protected static fonts?: UNFonts;\n\n protected static signedNonce?: string;\n protected static pushProvisionModule?: typeof NativeModules;\n\n public static ui: UnitUiManager;\n\n public static init = async (env: UNEnvironment, theme?: string, language?: string, fonts?: UNFonts) => {\n try {\n this.env = env;\n this.theme = theme;\n this.language = language;\n this.fonts = fonts;\n\n this.ui = new UnitUiManager();\n await fetchUnitScript();\n EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});\n } catch (e) {\n console.log(e);\n }\n };\n\n public static setPushProvisioningModule = (pushProvisionModule: typeof NativeModules) => {\n this.pushProvisionModule = pushProvisionModule;\n };\n\n public static getPushProvisionModule = () => {\n return this.pushProvisionModule;\n };\n\n public static setSignedNonce = (signedNonce: string) => {\n this.signedNonce = signedNonce;\n };\n\n public static getEnv = () => {\n return this.env;\n };\n\n public static getTheme = () => {\n return this.theme;\n };\n\n public static getLanguage = () => {\n return this.language;\n };\n\n public static getFonts = () => {\n return this.fonts;\n };\n\n public static getSignedNonce = () => {\n return this.signedNonce;\n };\n\n public static setCustomerToken = (customerToken: string) => {\n this.customerToken = customerToken;\n };\n\n public static getCustomerToken = () => {\n return this.customerToken;\n };\n}\n"],"mappings":";;;AACA,OAAOA,QAAQ,MAAM,qBAAqB;AAC1C,SAASC,UAAU,QAAQ,uCAAuC;AAClE,SAASC,eAAe,QAAQ,eAAe;AAC/C,SAASC,aAAa,QAAQ,+BAA+B;AAG7D,WAAYC,aAAa;AAGxB,WAHWA,aAAa;EAAbA,aAAa;EAAbA,aAAa;AAAA,GAAbA,aAAa,KAAbA,aAAa;AAKzB,MAAMC,gBAAgB,GAAG,GAAG;AAE5B,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACF,aAAa,CAACG,OAAO,GAAI,gCAA+BF,gBAAiB,gBAAe;EACzF,CAACD,aAAa,CAACI,UAAU,GAAI,8BAA6BH,gBAAiB;AAC7E,CAAC;AACD,OAAO,MAAMI,OAAO,CAAC;AAkEpBC,eAAA,CAlEYD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO;AAAAC,eAAA,CAAPD,OAAO,UAYG,OAAOE,GAAkB,EAAEC,KAAc,EAAEC,QAAiB,EAAEC,KAAe,KAAK;EACrG,IAAI;IAbKL,OAAO,CAcTE,GAAG,GAAGA,GAAG;IAdPF,OAAO,CAeTG,KAAK,GAAGA,KAAK;IAfXH,OAAO,CAgBTI,QAAQ,GAAGA,QAAQ;IAhBjBJ,OAAO,CAiBTK,KAAK,GAAGA,KAAK;IAjBXL,OAAO,CAmBTM,EAAE,GAAG,IAAIZ,aAAa,EAAE;IAC7B,MAAMD,eAAe,EAAE;IACvBF,QAAQ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ager/UnitSdkManager';
12
12
  import { SDKMessage } from '../messages/nativeMessages/sdkMessage';
13
13
  import { handleRequestDownload } from './WebComponent.utils';
14
+ import { getFontFacesString } from '../scripts/html/fontFaces';
14
15
  const {
15
16
  UNAppInfo
16
17
  } = NativeModules;
@@ -61,7 +62,9 @@ export const WebComponent = /*#__PURE__*/React.forwardRef(function WebComponent(
61
62
  const themeParam = componentCurrentTheme ? ` theme="${componentCurrentTheme}"` : '';
62
63
  const languageParam = componentCurrentLanguage ? ` language="${componentCurrentLanguage}"` : '';
63
64
  const componentParams = (props.params || '') + themeParam + languageParam;
65
+ const fontFaces = getFontFacesString(UnitSDK.getFonts());
64
66
  let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));
67
+ newHtml = newHtml.replace(HTML_PLACEHOLDER.FONT_FACES, fontFaces);
65
68
  newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');
66
69
  newHtml = newHtml.replace(HTML_PLACEHOLDER.WINDOW_PARAMS, props.windowParams || '');
67
70
  setSourceHtml(newHtml);
@@ -110,7 +113,7 @@ export const WebComponent = /*#__PURE__*/React.forwardRef(function WebComponent(
110
113
  },
111
114
  source: {
112
115
  html: sourceHtml,
113
- baseUrl: `https://${baseName}`
116
+ baseUrl: Platform.OS === 'android' ? `https://${baseName}` : ''
114
117
  },
115
118
  onMessage: onMessage,
116
119
  androidHardwareAccelerationDisabled: true
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useState","NativeModules","Platform","WebView","EventBus","html","HTML_PLACEHOLDER","UnitMessage","useListenerToBus","getHtmlBody","fetchUnitScript","globalUnitScript","UnitSDK","SDKMessage","handleRequestDownload","UNAppInfo","WebComponent","forwardRef","props","webRef","unitScript","setUnitScript","sourceHtml","setSourceHtml","componentCurrentTheme","setComponentCurrentTheme","theme","getTheme","componentCurrentLanguage","setComponentCurrentLanguage","language","getLanguage","baseName","setBaseName","updateUnitScript","data","updateInitializedParams","busEventKey","IS_SCRIPT_FETCHED","action","IS_SDK_INITIALIZED","getAppName","OS","name","getBundleName","replace","error","console","themeParam","languageParam","componentParams","params","newHtml","BODY","type","valueOf","presentationMode","SCRIPT_FROM_NATIVE","script","WINDOW_PARAMS","windowParams","onMessage","e","message","JSON","parse","nativeEvent","UNIT_REQUEST_REFRESH","details","Instance","event","UNIT_REQUEST_DOWNLOAD","UNIT_REQUEST_CLOSE_FLOW","_onScroll","handleScroll","createElement","ref","originWhitelist","mediaPlaybackRequiresUserAction","allowsInlineMediaPlayback","cacheEnabled","scrollEnabled","isScrollable","nestedScrollEnabled","onScroll","overScrollMode","injectedJavaScript","style","width","flex","opacity","backgroundColor","source","baseUrl","androidHardwareAccelerationDisabled"],"sources":["WebComponent.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React, { useEffect, useState } from 'react';\nimport { NativeModules, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport EventBus from '../helpers/EventBus';\nimport html, { HTML_PLACEHOLDER } from './html';\nimport { RequestRefreshEvent, UnitMessage, RequestDownloadEvent } from '../messages/webMessages/unitMessages';\nimport { useListenerToBus } from '../hooks/listenerToBus';\nimport { getHtmlBody } from '../scripts/html/bodyHtml';\nimport { fetchUnitScript, globalUnitScript } from '../unitSdkManager/UnitSdk.api';\nimport { UnitSDK } from '../unitSdkManager/UnitSdkManager';\nimport type { WebViewMessage } from '../messages/webMessages';\nimport { SDKMessage, SdkScriptFetched } from '../messages/nativeMessages/sdkMessage';\nimport { handleRequestDownload } from './WebComponent.utils';\nimport type { PresentationMode, WebComponentType } from '../types/internal/webComponent.types';\n\nconst { UNAppInfo } = NativeModules;\n\nexport interface WebComponentProps {\n type: WebComponentType;\n presentationMode?: PresentationMode,\n params?: string;\n theme?: string;\n language?: string;\n onMessage?: (message: WebViewMessage) => void;\n script?: string;\n isScrollable?: boolean,\n nestedScrollEnabled?: boolean,\n handleScroll?: (event: any) => void,\n windowParams?: string;\n}\n\nexport const WebComponent = React.forwardRef<WebView, WebComponentProps>(function WebComponent(props, webRef) {\n const [unitScript, setUnitScript] = useState<string | undefined>(globalUnitScript);\n const [sourceHtml, setSourceHtml] = useState<string | null>(null);\n const [componentCurrentTheme, setComponentCurrentTheme] = useState<string | undefined>(props.theme ?? UnitSDK.getTheme());\n const [componentCurrentLanguage, setComponentCurrentLanguage] = useState<string | undefined>(props.language ?? UnitSDK.getLanguage());\n const [baseName, setBaseName] = useState<string>();\n\n const updateUnitScript = (data: SdkScriptFetched) => {\n setUnitScript(data.unitScript);\n };\n\n const updateInitializedParams = () => {\n setComponentCurrentTheme(props.theme ?? UnitSDK.getTheme());\n setComponentCurrentLanguage(props.language ?? UnitSDK.getLanguage());\n };\n\n useListenerToBus({ busEventKey: SDKMessage.IS_SCRIPT_FETCHED, action: updateUnitScript });\n useListenerToBus({ busEventKey: SDKMessage.IS_SDK_INITIALIZED, action: updateInitializedParams });\n\n useEffect(() => {\n\n const getAppName = async () => {\n // For iOS, we extend the app name from the HTML to display a prettier access request message.\n // On Android, there is no request message sent from HTML.\n try {\n if (Platform.OS == 'ios') {\n const name = await UNAppInfo.getBundleName();\n setBaseName(name.replace(/ /g, '-'));\n } else { // android\n setBaseName('unit');\n }\n } catch (error: any) {\n console.error(error);\n }\n };\n\n getAppName();\n }, []);\n\n useEffect(() => {\n if (!unitScript) {\n fetchUnitScript();\n return;\n }\n\n const themeParam = componentCurrentTheme ? ` theme=\"${componentCurrentTheme}\"` : '';\n const languageParam = componentCurrentLanguage ? ` language=\"${componentCurrentLanguage}\"` : '';\n\n const componentParams = (props.params || '') + themeParam + languageParam;\n let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));\n newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');\n newHtml = newHtml.replace(HTML_PLACEHOLDER.WINDOW_PARAMS, props.windowParams || '');\n setSourceHtml(newHtml);\n }, [props.params, unitScript, props.presentationMode, componentCurrentTheme, componentCurrentLanguage, props.script, props.windowParams]);\n\n const onMessage = (e: WebViewMessageEvent) => {\n const message = JSON.parse(e.nativeEvent.data) as WebViewMessage;\n switch (message.type) {\n case UnitMessage.UNIT_REQUEST_REFRESH:\n message.details &&\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_REFRESH, message.details as RequestRefreshEvent);\n break;\n case UnitMessage.UNIT_REQUEST_DOWNLOAD:\n message.details &&\n handleRequestDownload(message.details as RequestDownloadEvent, () => {\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_CLOSE_FLOW, {});\n });\n break;\n default:\n props.onMessage && props.onMessage(message);\n }\n };\n\n if (!sourceHtml) return null;\n\n const _onScroll = (event: any) => {\n if (props.handleScroll) {\n props.handleScroll(event);\n }\n\n return null;\n };\n\n if (!baseName) {\n return null;\n }\n\n return (\n <WebView\n ref={webRef}\n originWhitelist={['*']}\n mediaPlaybackRequiresUserAction={false}\n allowsInlineMediaPlayback={true}\n cacheEnabled={false}\n scrollEnabled={props.isScrollable}\n nestedScrollEnabled={props.nestedScrollEnabled}\n onScroll={_onScroll}\n overScrollMode=\"never\"\n injectedJavaScript={unitScript}\n style={{ width: '100%', flex: 1, opacity: 0.99, backgroundColor: 'transparent' }}\n source={{ html: sourceHtml, baseUrl: `https://${baseName}` }}\n onMessage={onMessage}\n androidHardwareAccelerationDisabled\n />\n );\n});\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SAASC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SAASC,OAAO,QAA6B,sBAAsB;AACnE,OAAOC,QAAQ,MAAM,qBAAqB;AAC1C,OAAOC,IAAI,IAAIC,gBAAgB,QAAQ,QAAQ;AAC/C,SAA8BC,WAAW,QAA8B,sCAAsC;AAC7G,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,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ED,IAAI,CAACtC,QAAQ,EAAE;IACb,OAAO,IAAI;EACb;EAEA,oBACElC,KAAA,CAAA6E,aAAA,CAACxE,OAAO;IACNyE,GAAG,EAAEzD,MAAO;IACZ0D,eAAe,EAAE,CAAC,GAAG,CAAE;IACvBC,+BAA+B,EAAE,KAAM;IACvCC,yBAAyB,EAAE,IAAK;IAChCC,YAAY,EAAE,KAAM;IACpBC,aAAa,EAAE/D,KAAK,CAACgE,YAAa;IAClCC,mBAAmB,EAAEjE,KAAK,CAACiE,mBAAoB;IAC/CC,QAAQ,EAAEX,SAAU;IACpBY,cAAc,EAAC,OAAO;IACtBC,kBAAkB,EAAElE,UAAW;IAC/BmE,KAAK,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEC,IAAI,EAAE,CAAC;MAAEC,OAAO,EAAE,IAAI;MAAEC,eAAe,EAAE;IAAc,CAAE;IACjFC,MAAM,EAAE;MAAEvF,IAAI,EAAEiB,UAAU;MAAEuE,OAAO,EAAG,WAAU7D,QAAS;IAAE,CAAE;IAC7D6B,SAAS,EAAEA,SAAU;IACrBiC,mCAAmC;EAAA,EACnC;AAEN,CAAC,CAAC"}
1
+ {"version":3,"names":["React","useEffect","useState","NativeModules","Platform","WebView","EventBus","html","HTML_PLACEHOLDER","UnitMessage","useListenerToBus","getHtmlBody","fetchUnitScript","globalUnitScript","UnitSDK","SDKMessage","handleRequestDownload","getFontFacesString","UNAppInfo","WebComponent","forwardRef","props","webRef","unitScript","setUnitScript","sourceHtml","setSourceHtml","componentCurrentTheme","setComponentCurrentTheme","theme","getTheme","componentCurrentLanguage","setComponentCurrentLanguage","language","getLanguage","baseName","setBaseName","updateUnitScript","data","updateInitializedParams","busEventKey","IS_SCRIPT_FETCHED","action","IS_SDK_INITIALIZED","getAppName","OS","name","getBundleName","replace","error","console","themeParam","languageParam","componentParams","params","fontFaces","getFonts","newHtml","BODY","type","valueOf","presentationMode","FONT_FACES","SCRIPT_FROM_NATIVE","script","WINDOW_PARAMS","windowParams","onMessage","e","message","JSON","parse","nativeEvent","UNIT_REQUEST_REFRESH","details","Instance","event","UNIT_REQUEST_DOWNLOAD","UNIT_REQUEST_CLOSE_FLOW","_onScroll","handleScroll","createElement","ref","originWhitelist","mediaPlaybackRequiresUserAction","allowsInlineMediaPlayback","cacheEnabled","scrollEnabled","isScrollable","nestedScrollEnabled","onScroll","overScrollMode","injectedJavaScript","style","width","flex","opacity","backgroundColor","source","baseUrl","androidHardwareAccelerationDisabled"],"sources":["WebComponent.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React, { useEffect, useState } from 'react';\nimport { NativeModules, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport EventBus from '../helpers/EventBus';\nimport html, { HTML_PLACEHOLDER } from './html';\nimport { RequestRefreshEvent, UnitMessage, RequestDownloadEvent } from '../messages/webMessages/unitMessages';\nimport { useListenerToBus } from '../hooks/listenerToBus';\nimport { getHtmlBody } from '../scripts/html/bodyHtml';\nimport { fetchUnitScript, globalUnitScript } from '../unitSdkManager/UnitSdk.api';\nimport { UnitSDK } from '../unitSdkManager/UnitSdkManager';\nimport type { WebViewMessage } from '../messages/webMessages';\nimport { SDKMessage, SdkScriptFetched } from '../messages/nativeMessages/sdkMessage';\nimport { handleRequestDownload } from './WebComponent.utils';\nimport type { PresentationMode, WebComponentType } from '../types/internal/webComponent.types';\nimport { getFontFacesString } from '../scripts/html/fontFaces';\n\nconst { UNAppInfo } = NativeModules;\n\nexport interface WebComponentProps {\n type: WebComponentType;\n presentationMode?: PresentationMode,\n params?: string;\n theme?: string;\n language?: string;\n onMessage?: (message: WebViewMessage) => void;\n script?: string;\n isScrollable?: boolean,\n nestedScrollEnabled?: boolean,\n handleScroll?: (event: any) => void,\n windowParams?: string;\n}\n\nexport const WebComponent = React.forwardRef<WebView, WebComponentProps>(function WebComponent(props, webRef) {\n const [unitScript, setUnitScript] = useState<string | undefined>(globalUnitScript);\n const [sourceHtml, setSourceHtml] = useState<string | null>(null);\n const [componentCurrentTheme, setComponentCurrentTheme] = useState<string | undefined>(props.theme ?? UnitSDK.getTheme());\n const [componentCurrentLanguage, setComponentCurrentLanguage] = useState<string | undefined>(props.language ?? UnitSDK.getLanguage());\n const [baseName, setBaseName] = useState<string>();\n\n const updateUnitScript = (data: SdkScriptFetched) => {\n setUnitScript(data.unitScript);\n };\n\n const updateInitializedParams = () => {\n setComponentCurrentTheme(props.theme ?? UnitSDK.getTheme());\n setComponentCurrentLanguage(props.language ?? UnitSDK.getLanguage());\n };\n\n useListenerToBus({ busEventKey: SDKMessage.IS_SCRIPT_FETCHED, action: updateUnitScript });\n useListenerToBus({ busEventKey: SDKMessage.IS_SDK_INITIALIZED, action: updateInitializedParams });\n\n useEffect(() => {\n\n const getAppName = async () => {\n // For iOS, we extend the app name from the HTML to display a prettier access request message.\n // On Android, there is no request message sent from HTML.\n try {\n if (Platform.OS == 'ios') {\n const name = await UNAppInfo.getBundleName();\n setBaseName(name.replace(/ /g, '-'));\n } else { // android\n setBaseName('unit');\n }\n } catch (error: any) {\n console.error(error);\n }\n };\n\n getAppName();\n }, []);\n\n useEffect(() => {\n if (!unitScript) {\n fetchUnitScript();\n return;\n }\n\n const themeParam = componentCurrentTheme ? ` theme=\"${componentCurrentTheme}\"` : '';\n const languageParam = componentCurrentLanguage ? ` language=\"${componentCurrentLanguage}\"` : '';\n\n const componentParams = (props.params || '') + themeParam + languageParam;\n\n const fontFaces = getFontFacesString(UnitSDK.getFonts());\n\n let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));\n newHtml = newHtml.replace(HTML_PLACEHOLDER.FONT_FACES, fontFaces);\n newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');\n newHtml = newHtml.replace(HTML_PLACEHOLDER.WINDOW_PARAMS, props.windowParams || '');\n setSourceHtml(newHtml);\n }, [props.params, unitScript, props.presentationMode, componentCurrentTheme, componentCurrentLanguage, props.script, props.windowParams]);\n\n const onMessage = (e: WebViewMessageEvent) => {\n const message = JSON.parse(e.nativeEvent.data) as WebViewMessage;\n switch (message.type) {\n case UnitMessage.UNIT_REQUEST_REFRESH:\n message.details &&\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_REFRESH, message.details as RequestRefreshEvent);\n break;\n case UnitMessage.UNIT_REQUEST_DOWNLOAD:\n message.details &&\n handleRequestDownload(message.details as RequestDownloadEvent, () => {\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_CLOSE_FLOW, {});\n });\n break;\n default:\n props.onMessage && props.onMessage(message);\n }\n };\n\n if (!sourceHtml) return null;\n\n const _onScroll = (event: any) => {\n if (props.handleScroll) {\n props.handleScroll(event);\n }\n\n return null;\n };\n\n if (!baseName) {\n return null;\n }\n\n return (\n <WebView\n ref={webRef}\n originWhitelist={['*']}\n mediaPlaybackRequiresUserAction={false}\n allowsInlineMediaPlayback={true}\n cacheEnabled={false}\n scrollEnabled={props.isScrollable}\n nestedScrollEnabled={props.nestedScrollEnabled}\n onScroll={_onScroll}\n overScrollMode=\"never\"\n injectedJavaScript={unitScript}\n style={{ width: '100%', flex: 1, opacity: 0.99, backgroundColor: 'transparent' }}\n source={{ html: sourceHtml, baseUrl: Platform.OS === 'android' ? `https://${baseName}` : ''}}\n onMessage={onMessage}\n androidHardwareAccelerationDisabled\n />\n );\n});\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SAASC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SAASC,OAAO,QAA6B,sBAAsB;AACnE,OAAOC,QAAQ,MAAM,qBAAqB;AAC1C,OAAOC,IAAI,IAAIC,gBAAgB,QAAQ,QAAQ;AAC/C,SAA8BC,WAAW,QAA8B,sCAAsC;AAC7G,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,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  <!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 style="margin: 0;">
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 </head>\n\n <body style=\"margin: 0;\">\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;AACjB,CAAC;AAED,MAAMC,QAAQ,GAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAad,QAAQ,CAACe,EAAG;AACzB,qBAAqBf,QAAQ,CAACe,EAAE,KAAK,KAAK,GAAG,OAAO,GAAG,QAAS;AAChE;AACA,MAAMN,gBAAgB,CAACI,aAAc;AACrC;AACA;AACA;AACA;AACA;AACA,MAAMJ,gBAAgB,CAACE,IAAK;AAC5B;AACA;AACA,QAAQR,mBAAoB;AAC5B;AACA,QAAQC,gBAAiB;AACzB;AACA,QAAQF,SAAS,CAACc,YAAa;AAC/B;AACA,QAAQd,SAAS,CAACe,MAAO;AACzB;AACA,QAAQf,SAAS,CAACgB,mBAAoB;AACtC;AACA,QAAQhB,SAAS,CAACiB,gBAAiB;AACnC;AACA,QAAQjB,SAAS,CAACkB,eAAgB;AAClC;AACA,QAAQlB,SAAS,CAACmB,gBAAiB;AACnC;AACA,QAAQnB,SAAS,CAACoB,aAAc;AAChC;AACA,QAAQpB,SAAS,CAACqB,gBAAiB;AACnC;AACA,QAAQrB,SAAS,CAACsB,sBAAuB;AACzC;AACA,QAAQtB,SAAS,CAACuB,kBAAmB;AACrC;AACA,QAAQvB,SAAS,CAACwB,0BAA2B;AAC7C;AACA,QAAQzB,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,eAAeE,QAAQ"}
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,2 @@
1
+ import type { UNFonts } from '../../types/shared/fonts.types';
2
+ export declare const getFontFacesString: (fonts?: UNFonts) => string;
@@ -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
+ }
@@ -5,3 +5,5 @@ export * from './achCredit.types';
5
5
  export * from './payments.types';
6
6
  export * from './account.types';
7
7
  export * from './checkDeposit.types';
8
+ export * from './activity.types';
9
+ export * from './fonts.types';
@@ -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;
@@ -3,6 +3,7 @@ export declare const HTML_PLACEHOLDER: {
3
3
  BODY: string;
4
4
  SCRIPT_FROM_NATIVE: string;
5
5
  WINDOW_PARAMS: string;
6
+ FONT_FACES: string;
6
7
  };
7
8
  declare const htmlText: string;
8
9
  export default htmlText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unit-components",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "Unit React Native components",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -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
+ }
@@ -5,3 +5,5 @@ export * from './achCredit.types';
5
5
  export * from './payments.types';
6
6
  export * from './account.types';
7
7
  export * from './checkDeposit.types';
8
+ export * from './activity.types';
9
+ export * from './fonts.types';
@@ -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
 
@@ -79,7 +80,11 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
79
80
  const languageParam = componentCurrentLanguage ? ` language="${componentCurrentLanguage}"` : '';
80
81
 
81
82
  const componentParams = (props.params || '') + themeParam + languageParam;
83
+
84
+ const fontFaces = getFontFacesString(UnitSDK.getFonts());
85
+
82
86
  let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));
87
+ newHtml = newHtml.replace(HTML_PLACEHOLDER.FONT_FACES, fontFaces);
83
88
  newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');
84
89
  newHtml = newHtml.replace(HTML_PLACEHOLDER.WINDOW_PARAMS, props.windowParams || '');
85
90
  setSourceHtml(newHtml);
@@ -130,7 +135,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
130
135
  overScrollMode="never"
131
136
  injectedJavaScript={unitScript}
132
137
  style={{ width: '100%', flex: 1, opacity: 0.99, backgroundColor: 'transparent' }}
133
- source={{ html: sourceHtml, baseUrl: `https://${baseName}` }}
138
+ source={{ html: sourceHtml, baseUrl: Platform.OS === 'android' ? `https://${baseName}` : ''}}
134
139
  onMessage={onMessage}
135
140
  androidHardwareAccelerationDisabled
136
141
  />
@@ -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 style="margin: 0;">
37
+ <body>
29
38
  ${HTML_PLACEHOLDER.BODY}
30
39
 
31
40
  <script>