react-native-unit-components 1.0.1 → 1.0.2

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 (53) hide show
  1. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +39 -8
  2. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
  3. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +0 -3
  4. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
  5. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +41 -10
  6. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
  7. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +0 -3
  8. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
  9. package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +1 -0
  10. package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
  11. package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +0 -3
  12. package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
  13. package/lib/commonjs/messages/nativeMessages/index.js +1 -0
  14. package/lib/commonjs/messages/nativeMessages/index.js.map +1 -1
  15. package/lib/commonjs/scripts/html/bodyHtml.js +1 -1
  16. package/lib/commonjs/scripts/html/bodyHtml.js.map +1 -1
  17. package/lib/commonjs/unitSdkManager/UnitSdkManager.js +8 -0
  18. package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
  19. package/lib/commonjs/webComponent/WebComponent.js +17 -4
  20. package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
  21. package/lib/module/components/UNActivityComponent/UNActivityComponent.js +33 -7
  22. package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
  23. package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +0 -2
  24. package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
  25. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +36 -9
  26. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
  27. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +0 -2
  28. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
  29. package/lib/module/components/UNCardComponent/UNCardComponent.js +1 -0
  30. package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
  31. package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +0 -2
  32. package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
  33. package/lib/module/messages/nativeMessages/index.js +1 -0
  34. package/lib/module/messages/nativeMessages/index.js.map +1 -1
  35. package/lib/module/scripts/html/bodyHtml.js +1 -1
  36. package/lib/module/scripts/html/bodyHtml.js.map +1 -1
  37. package/lib/module/unitSdkManager/UnitSdkManager.js +3 -0
  38. package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
  39. package/lib/module/webComponent/WebComponent.js +15 -4
  40. package/lib/module/webComponent/WebComponent.js.map +1 -1
  41. package/lib/typescript/messages/nativeMessages/index.d.ts +2 -1
  42. package/lib/typescript/webComponent/WebComponent.d.ts +2 -0
  43. package/package.json +1 -1
  44. package/src/components/UNActivityComponent/UNActivityComponent.tsx +33 -7
  45. package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +0 -2
  46. package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +35 -9
  47. package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +0 -2
  48. package/src/components/UNCardComponent/UNCardComponent.tsx +1 -0
  49. package/src/components/UNCardComponent/UNCardComponent.utils.ts +0 -2
  50. package/src/messages/nativeMessages/index.ts +2 -1
  51. package/src/scripts/html/bodyHtml.ts +1 -1
  52. package/src/unitSdkManager/UnitSdkManager.ts +3 -0
  53. package/src/webComponent/WebComponent.tsx +17 -5
@@ -1,23 +1,50 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
3
3
  import { PresentationMode } from '../../scripts/html/bodyHtml';
4
4
  import { getBookPaymentParams, getBookPaymentScript } from './UNBookPaymentComponent.utils';
5
5
  import { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';
6
+ import { PageMessage } from '../../messages/webMessages/pageMessage';
7
+ import { View } from 'react-native';
6
8
  export const UNBookPaymentComponent = props => {
9
+ const [height, setHeight] = useState(0);
10
+ const [presentationMode, setPresentationMode] = useState(PresentationMode.Inherit);
11
+
7
12
  const handleWebViewMessage = message => {
8
13
  if (message.type === BookPaymentMessage.PAYMENT_CREATED && props.onPaymentCreated) {
9
14
  const response = message.details;
10
15
  props.onPaymentCreated(response.data);
11
16
  }
17
+
18
+ if (message.type === PageMessage.PAGE_HEIGHT) {
19
+ const currentHeight = message.details.height;
20
+ setHeight(currentHeight);
21
+
22
+ if (presentationMode === PresentationMode.Inherit && currentHeight === 0) {
23
+ setPresentationMode(PresentationMode.Default);
24
+ }
25
+ }
12
26
  };
13
27
 
14
- return /*#__PURE__*/React.createElement(WebComponent, {
15
- type: WebComponentType.bookPayment,
16
- presentationMode: PresentationMode.Inherit,
17
- params: getBookPaymentParams(props),
18
- script: getBookPaymentScript(),
19
- onMessage: message => handleWebViewMessage(message),
20
- isScrollable: false
21
- });
28
+ const renderBookPaymentWebView = () => {
29
+ return /*#__PURE__*/React.createElement(WebComponent, {
30
+ type: WebComponentType.bookPayment,
31
+ presentationMode: presentationMode,
32
+ params: getBookPaymentParams(props),
33
+ script: getBookPaymentScript(),
34
+ onMessage: message => handleWebViewMessage(message),
35
+ isScrollable: false,
36
+ theme: props.theme
37
+ });
38
+ };
39
+
40
+ if (presentationMode === PresentationMode.Inherit) {
41
+ return renderBookPaymentWebView();
42
+ }
43
+
44
+ return /*#__PURE__*/React.createElement(View, {
45
+ style: {
46
+ height: height
47
+ }
48
+ }, renderBookPaymentWebView());
22
49
  };
23
50
  //# sourceMappingURL=UNBookPaymentComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","WebComponent","WebComponentType","PresentationMode","getBookPaymentParams","getBookPaymentScript","BookPaymentMessage","UNBookPaymentComponent","props","handleWebViewMessage","message","type","PAYMENT_CREATED","onPaymentCreated","response","details","data","bookPayment","Inherit"],"sources":["UNBookPaymentComponent.tsx"],"sourcesContent":["import React from 'react';\nimport { WebComponent, WebComponentType } from '../../webComponent/WebComponent';\nimport { PresentationMode } from '../../scripts/html/bodyHtml';\nimport { getBookPaymentParams, getBookPaymentScript } from './UNBookPaymentComponent.utils';\nimport type { WebViewMessage } from '../../messages/webMessages';\nimport { BookPaymentEvent, BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';\nimport type { UNBookPaymentData } from '../../sharedTypes';\n\nexport interface UNBookPaymentComponentProps {\n accountId: string;\n customerToken: string;\n isSameCustomer: boolean;\n counterPartyAccountId: string;\n counterPartyName: string;\n theme?: string;\n onPaymentCreated?: (data: UNBookPaymentData) => void;\n}\n\nexport const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {\n const handleWebViewMessage = (message: WebViewMessage) => {\n if (message.type === BookPaymentMessage.PAYMENT_CREATED && props.onPaymentCreated) {\n const response = message.details as BookPaymentEvent;\n props.onPaymentCreated(response.data);\n }\n };\n\n return (\n <WebComponent\n type={WebComponentType.bookPayment}\n presentationMode={PresentationMode.Inherit}\n params={getBookPaymentParams(props)}\n script={getBookPaymentScript()}\n onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}\n isScrollable={false}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,iCAA/C;AACA,SAASC,gBAAT,QAAiC,6BAAjC;AACA,SAASC,oBAAT,EAA+BC,oBAA/B,QAA2D,gCAA3D;AAEA,SAA2BC,kBAA3B,QAAqD,+CAArD;AAaA,OAAO,MAAMC,sBAAsB,GAAIC,KAAD,IAAwC;EAC5E,MAAMC,oBAAoB,GAAIC,OAAD,IAA6B;IACxD,IAAIA,OAAO,CAACC,IAAR,KAAiBL,kBAAkB,CAACM,eAApC,IAAuDJ,KAAK,CAACK,gBAAjE,EAAmF;MACjF,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,OAAzB;MACAP,KAAK,CAACK,gBAAN,CAAuBC,QAAQ,CAACE,IAAhC;IACD;EACF,CALD;;EAOA,oBACE,oBAAC,YAAD;IACE,IAAI,EAAEd,gBAAgB,CAACe,WADzB;IAEE,gBAAgB,EAAEd,gBAAgB,CAACe,OAFrC;IAGE,MAAM,EAAEd,oBAAoB,CAACI,KAAD,CAH9B;IAIE,MAAM,EAAEH,oBAAoB,EAJ9B;IAKE,SAAS,EAAGK,OAAD,IAA6BD,oBAAoB,CAACC,OAAD,CAL9D;IAME,YAAY,EAAE;EANhB,EADF;AAUD,CAlBM"}
1
+ {"version":3,"names":["React","useState","WebComponent","WebComponentType","PresentationMode","getBookPaymentParams","getBookPaymentScript","BookPaymentMessage","PageMessage","View","UNBookPaymentComponent","props","height","setHeight","presentationMode","setPresentationMode","Inherit","handleWebViewMessage","message","type","PAYMENT_CREATED","onPaymentCreated","response","details","data","PAGE_HEIGHT","currentHeight","Default","renderBookPaymentWebView","bookPayment","theme"],"sources":["UNBookPaymentComponent.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { WebComponent, WebComponentType } from '../../webComponent/WebComponent';\nimport { PresentationMode } from '../../scripts/html/bodyHtml';\nimport { getBookPaymentParams, getBookPaymentScript } from './UNBookPaymentComponent.utils';\nimport type { WebViewMessage } from '../../messages/webMessages';\nimport { BookPaymentEvent, BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';\nimport type { UNBookPaymentData } from '../../sharedTypes';\nimport { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';\nimport { View } from 'react-native';\n\nexport interface UNBookPaymentComponentProps {\n accountId: string;\n customerToken: string;\n isSameCustomer: boolean;\n counterPartyAccountId: string;\n counterPartyName: string;\n theme?: string;\n onPaymentCreated?: (data: UNBookPaymentData) => void;\n}\n\nexport const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {\n const [height, setHeight] = useState<number>(0);\n const [presentationMode, setPresentationMode] = useState<PresentationMode>(PresentationMode.Inherit);\n\n const handleWebViewMessage = (message: WebViewMessage) => {\n if (message.type === BookPaymentMessage.PAYMENT_CREATED && props.onPaymentCreated) {\n const response = message.details as BookPaymentEvent;\n props.onPaymentCreated(response.data);\n }\n\n if (message.type === PageMessage.PAGE_HEIGHT) {\n const currentHeight = (message.details as HeightEvent).height;\n setHeight(currentHeight);\n if (presentationMode === PresentationMode.Inherit && currentHeight === 0) {\n setPresentationMode(PresentationMode.Default);\n }\n }\n };\n\n const renderBookPaymentWebView = () => {\n return (\n <WebComponent\n type={WebComponentType.bookPayment}\n presentationMode={presentationMode}\n params={getBookPaymentParams(props)}\n script={getBookPaymentScript()}\n onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}\n isScrollable={false}\n theme={props.theme}\n />\n );\n };\n\n if (presentationMode === PresentationMode.Inherit) {\n return renderBookPaymentWebView();\n }\n\n return (\n <View style={{ height: height }}>\n {renderBookPaymentWebView()}\n </View>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,iCAA/C;AACA,SAASC,gBAAT,QAAiC,6BAAjC;AACA,SAASC,oBAAT,EAA+BC,oBAA/B,QAA2D,gCAA3D;AAEA,SAA2BC,kBAA3B,QAAqD,+CAArD;AAEA,SAAsBC,WAAtB,QAAyC,wCAAzC;AACA,SAASC,IAAT,QAAqB,cAArB;AAYA,OAAO,MAAMC,sBAAsB,GAAIC,KAAD,IAAwC;EAC5E,MAAM,CAACC,MAAD,EAASC,SAAT,IAAsBZ,QAAQ,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AKD,CA1CM"}
@@ -1,5 +1,4 @@
1
1
  import { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';
2
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
3
2
  export const getBookPaymentParams = props => {
4
3
  return `
5
4
  account-id="${props.accountId}"
@@ -7,7 +6,6 @@ export const getBookPaymentParams = props => {
7
6
  is-same-customer="${props.isSameCustomer}"
8
7
  counterparty-account-id="${props.counterPartyAccountId}"
9
8
  counterparty-name="${props.counterPartyName}"
10
- theme="${props.theme ?? UnitSDK.getTheme()}"
11
9
  style="height: 100%"
12
10
  `;
13
11
  };
@@ -1 +1 @@
1
- {"version":3,"names":["BookPaymentMessage","UnitSDK","getBookPaymentParams","props","accountId","customerToken","isSameCustomer","counterPartyAccountId","counterPartyName","theme","getTheme","getBookPaymentScript","PAYMENT_CREATED"],"sources":["UNBookPaymentComponent.utils.ts"],"sourcesContent":["import type { UNBookPaymentComponentProps } from './UNBookPaymentComponent';\n\nimport { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';\nimport { UnitSDK } from '../../unitSdkManager/UnitSdkManager';\n\nexport const getBookPaymentParams = (props: UNBookPaymentComponentProps) => {\n return `\n account-id=\"${props.accountId}\"\n customer-token=\"${props.customerToken}\"\n is-same-customer=\"${props.isSameCustomer}\"\n counterparty-account-id=\"${props.counterPartyAccountId}\"\n counterparty-name=\"${props.counterPartyName}\"\n theme=\"${props.theme ?? UnitSDK.getTheme()}\"\n style=\"height: 100%\"\n `;\n};\n\nexport const getBookPaymentScript = () => {\n return `\n window.addEventListener(\"${BookPaymentMessage.PAYMENT_CREATED}\", (e) => {\n const response = e.detail\n response.then((data) => {\n postMessageToSDK({ type: \"${BookPaymentMessage.PAYMENT_CREATED}\", details: { data: JSON.stringify(data.data) }})\n }).catch((e) => {\n console.log(e)\n })\n });\n `;\n};\n"],"mappings":"AAEA,SAASA,kBAAT,QAAmC,+CAAnC;AACA,SAASC,OAAT,QAAwB,qCAAxB;AAEA,OAAO,MAAMC,oBAAoB,GAAIC,KAAD,IAAwC;EAC1E,OAAQ;AACV,kBAAkBA,KAAK,CAACC,SAAU;AAClC,sBAAsBD,KAAK,CAACE,aAAc;AAC1C,wBAAwBF,KAAK,CAACG,cAAe;AAC7C,+BAA+BH,KAAK,CAACI,qBAAsB;AAC3D,yBAAyBJ,KAAK,CAACK,gBAAiB;AAChD,aAAaL,KAAK,CAACM,KAAN,IAAeR,OAAO,CAACS,QAAR,EAAmB;AAC/C;AACA,GARE;AASD,CAVM;AAYP,OAAO,MAAMC,oBAAoB,GAAG,MAAM;EACxC,OAAQ;AACV,+BAA+BX,kBAAkB,CAACY,eAAgB;AAClE;AACA;AACA,sCAAsCZ,kBAAkB,CAACY,eAAgB;AACzE;AACA;AACA;AACA;AACA,GATE;AAUD,CAXM"}
1
+ {"version":3,"names":["BookPaymentMessage","getBookPaymentParams","props","accountId","customerToken","isSameCustomer","counterPartyAccountId","counterPartyName","getBookPaymentScript","PAYMENT_CREATED"],"sources":["UNBookPaymentComponent.utils.ts"],"sourcesContent":["import type { UNBookPaymentComponentProps } from './UNBookPaymentComponent';\n\nimport { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';\n\nexport const getBookPaymentParams = (props: UNBookPaymentComponentProps) => {\n return `\n account-id=\"${props.accountId}\"\n customer-token=\"${props.customerToken}\"\n is-same-customer=\"${props.isSameCustomer}\"\n counterparty-account-id=\"${props.counterPartyAccountId}\"\n counterparty-name=\"${props.counterPartyName}\"\n style=\"height: 100%\"\n `;\n};\n\nexport const getBookPaymentScript = () => {\n return `\n window.addEventListener(\"${BookPaymentMessage.PAYMENT_CREATED}\", (e) => {\n const response = e.detail\n response.then((data) => {\n postMessageToSDK({ type: \"${BookPaymentMessage.PAYMENT_CREATED}\", details: { data: JSON.stringify(data.data) }})\n }).catch((e) => {\n console.log(e)\n })\n });\n `;\n};\n"],"mappings":"AAEA,SAASA,kBAAT,QAAmC,+CAAnC;AAEA,OAAO,MAAMC,oBAAoB,GAAIC,KAAD,IAAwC;EAC1E,OAAQ;AACV,kBAAkBA,KAAK,CAACC,SAAU;AAClC,sBAAsBD,KAAK,CAACE,aAAc;AAC1C,wBAAwBF,KAAK,CAACG,cAAe;AAC7C,+BAA+BH,KAAK,CAACI,qBAAsB;AAC3D,yBAAyBJ,KAAK,CAACK,gBAAiB;AAChD;AACA,GAPE;AAQD,CATM;AAWP,OAAO,MAAMC,oBAAoB,GAAG,MAAM;EACxC,OAAQ;AACV,+BAA+BR,kBAAkB,CAACS,eAAgB;AAClE;AACA;AACA,sCAAsCT,kBAAkB,CAACS,eAAgB;AACzE;AACA;AACA;AACA;AACA,GATE;AAUD,CAXM"}
@@ -56,6 +56,7 @@ export const UNCardComponent = props => {
56
56
  type: WebComponentType.card,
57
57
  presentationMode: PresentationMode.Default,
58
58
  params: getCardParams(props),
59
+ theme: props.theme,
59
60
  script: getCardScript(),
60
61
  onMessage: message => handleMessage(message),
61
62
  width: windowWidth,
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useRef","useState","Dimensions","View","PageMessage","UnitMessage","EventBus","WebComponent","WebComponentType","useListenerToBus","getCardParams","getCardScript","injectRefreshEventIfNeeded","PresentationMode","CardMessage","UNCardComponent","props","height","setHeight","requestRefreshEvent","setRequestRefreshEvent","windowWidth","get","width","webRef","cardStatusChanged","card","onStatusChanged","requestRefresh","data","busEventKey","CARD_STATUS_CHANGED","action","UNIT_REQUEST_REFRESH","current","cardId","handleMessage","message","type","UNIT_REQUEST_RENDERING","Instance","event","details","PAGE_HEIGHT","Default"],"sources":["UNCardComponent.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { Dimensions, View } from 'react-native';\nimport type WebView from 'react-native-webview';\nimport { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';\nimport { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';\nimport EventBus from '../../helpers/EventBus';\nimport { WebComponent, WebComponentType } from '../../webComponent/WebComponent';\nimport { useListenerToBus } from '../../hooks/listenerToBus';\nimport type { WebViewMessage } from '../../messages/webMessages';\nimport { getCardParams, getCardScript, injectRefreshEventIfNeeded } from './UNCardComponent.utils';\nimport { PresentationMode } from '../../scripts/html/bodyHtml';\nimport type { UNCardData } from '../../sharedTypes';\nimport { CardMessage } from '../../messages/webMessages/cardMessage';\n\nexport interface UNCardComponentProps {\n cardId: string;\n customerToken: string;\n theme?: string;\n onStatusChanged?: (card: UNCardData) => void;\n}\n\nexport const UNCardComponent = (props: UNCardComponentProps) => {\n const [height, setHeight] = useState(0);\n const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);\n const windowWidth = Dimensions.get('window').width;\n\n const webRef = useRef<WebView>(null);\n\n const cardStatusChanged = (card: UNCardData) => {\n if (props.onStatusChanged) {\n props.onStatusChanged(card);\n }\n };\n\n const requestRefresh = (data: RequestRefreshEvent) => {\n setRequestRefreshEvent(data);\n };\n\n useListenerToBus([\n { busEventKey: CardMessage.CARD_STATUS_CHANGED, action: cardStatusChanged },\n { busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },\n ]);\n\n useEffect(() => {\n injectRefreshEventIfNeeded(webRef.current, requestRefreshEvent, props.cardId);\n }, [requestRefreshEvent]);\n\n const handleMessage = (message: WebViewMessage) => {\n switch (message.type) {\n case UnitMessage.UNIT_REQUEST_RENDERING:\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_RENDERING, (message.details as RequestRenderingEvent).data);\n break;\n case PageMessage.PAGE_HEIGHT:\n setHeight((message.details as HeightEvent).height);\n break;\n }\n };\n\n return (\n <View style={{ height }}>\n <WebComponent\n ref={webRef}\n type={WebComponentType.card}\n presentationMode={PresentationMode.Default}\n params={getCardParams(props)}\n script={getCardScript()}\n onMessage={message => handleMessage(message)}\n width={windowWidth}\n isScrollable={false}\n />\n </View>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA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AjB,EAAsCH,KAAK,CAACmB,MAA5C,CAA1B;EACD,CAFQ,EAEN,CAAChB,mBAAD,CAFM,CAAT;;EAIA,MAAMiB,aAAa,GAAIC,OAAD,IAA6B;IACjD,QAAQA,OAAO,CAACC,IAAhB;MACE,KAAKjC,WAAW,CAACkC,sBAAjB;QACEjC,QAAQ,CAACkC,QAAT,CAAkBC,KAAlB,CAAwBpC,WAAW,CAACkC,sBAApC,EAA6DF,OAAO,CAACK,OAAT,CAA2Cb,IAAvG;QACA;;MACF,KAAKzB,WAAW,CAACuC,WAAjB;QACEzB,SAAS,CAAEmB,OAAO,CAACK,OAAT,CAAiCzB,MAAlC,CAAT;QACA;IANJ;EAQD,CATD;;EAWA,oBACE,oBAAC,IAAD;IAAM,KAAK,EAAE;MAAEA;IAAF;EAAb,gBACE,oBAAC,YAAD;IACE,GAAG,EAAEO,MADP;IAEE,IAAI,EAAEhB,gBAAgB,CAACkB,IAFzB;IAGE,gBAAgB,EAAEb,gBAAgB,CAAC+B,OAHrC;IAIE,MAAM,EAAElC,aAAa,CAACM,KAAD,CAJvB;IAKE,MAAM,EAAEL,aAAa,EALvB;IAME,SAAS,EAAE0B,OAAO,IAAID,aAAa,CAACC,OAAD,CANrC;IAOE,KAAK,EAAEhB,WAPT;IAQE,YAAY,EAAE;EARhB,EADF,CADF;AAcD,CAnDM"}
1
+ {"version":3,"names":["React","useEffect","useRef","useState","Dimensions","View","PageMessage","UnitMessage","EventBus","WebComponent","WebComponentType","useListenerToBus","getCardParams","getCardScript","injectRefreshEventIfNeeded","PresentationMode","CardMessage","UNCardComponent","props","height","setHeight","requestRefreshEvent","setRequestRefreshEvent","windowWidth","get","width","webRef","cardStatusChanged","card","onStatusChanged","requestRefresh","data","busEventKey","CARD_STATUS_CHANGED","action","UNIT_REQUEST_REFRESH","current","cardId","handleMessage","message","type","UNIT_REQUEST_RENDERING","Instance","event","details","PAGE_HEIGHT","Default","theme"],"sources":["UNCardComponent.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { Dimensions, View } from 'react-native';\nimport type WebView from 'react-native-webview';\nimport { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';\nimport { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';\nimport EventBus from '../../helpers/EventBus';\nimport { WebComponent, WebComponentType } from '../../webComponent/WebComponent';\nimport { useListenerToBus } from '../../hooks/listenerToBus';\nimport type { WebViewMessage } from '../../messages/webMessages';\nimport { getCardParams, getCardScript, injectRefreshEventIfNeeded } from './UNCardComponent.utils';\nimport { PresentationMode } from '../../scripts/html/bodyHtml';\nimport type { UNCardData } from '../../sharedTypes';\nimport { CardMessage } from '../../messages/webMessages/cardMessage';\n\nexport interface UNCardComponentProps {\n cardId: string;\n customerToken: string;\n theme?: string;\n onStatusChanged?: (card: UNCardData) => void;\n}\n\nexport const UNCardComponent = (props: UNCardComponentProps) => {\n const [height, setHeight] = useState(0);\n const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);\n const windowWidth = Dimensions.get('window').width;\n\n const webRef = useRef<WebView>(null);\n\n const cardStatusChanged = (card: UNCardData) => {\n if (props.onStatusChanged) {\n props.onStatusChanged(card);\n }\n };\n\n const requestRefresh = (data: RequestRefreshEvent) => {\n setRequestRefreshEvent(data);\n };\n\n useListenerToBus([\n { busEventKey: CardMessage.CARD_STATUS_CHANGED, action: cardStatusChanged },\n { busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },\n ]);\n\n useEffect(() => {\n injectRefreshEventIfNeeded(webRef.current, requestRefreshEvent, props.cardId);\n }, [requestRefreshEvent]);\n\n const handleMessage = (message: WebViewMessage) => {\n switch (message.type) {\n case UnitMessage.UNIT_REQUEST_RENDERING:\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_RENDERING, (message.details as RequestRenderingEvent).data);\n break;\n case PageMessage.PAGE_HEIGHT:\n setHeight((message.details as HeightEvent).height);\n break;\n }\n };\n\n return (\n <View style={{ height }}>\n <WebComponent\n ref={webRef}\n type={WebComponentType.card}\n presentationMode={PresentationMode.Default}\n params={getCardParams(props)}\n theme={props.theme}\n script={getCardScript()}\n onMessage={message => handleMessage(message)}\n width={windowWidth}\n isScrollable={false}\n />\n </View>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,EAAmCC,QAAnC,QAAmD,OAAnD;AACA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AAEA,SAAsBC,WAAtB,QAAyC,wCAAzC;AACA,SAAqDC,WAArD,QAAwE,yCAAxE;AACA,OAAOC,QAAP,MAAqB,wBAArB;AACA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,iCAA/C;AACA,SAASC,gBAAT,QAAiC,2BAAjC;AAEA,SAASC,aAAT,EAAwBC,aAAxB,EAAuCC,0BAAvC,QAAyE,yBAAzE;AACA,SAASC,gBAAT,QAAiC,6BAAjC;AAEA,SAASC,WAAT,QAA4B,wCAA5B;AASA,OAAO,MAAMC,eAAe,GAAIC,KAAD,IAAiC;EAC9D,MAAM,CAACC,MAAD,EAASC,SAAT,IAAsBjB,QAAQ,CAAC,CAAD,CAApC;EACA,MAAM,CAACkB,mBAAD,EAAsBC,sBAAtB,IAAgDnB,QAAQ,CAA6B,IAA7B,CAA9D;EACA,MAAMoB,WAAW,GAAGnB,UAAU,CAACoB,GAAX,CAAe,QAAf,EAAyBC,KAA7C;EAEA,MAAMC,MAAM,GAAGxB,MAAM,CAAU,IAAV,CAArB;;EAEA,MAAMyB,iBAAiB,GAAIC,IAAD,IAAsB;IAC9C,IAAIV,KAAK,CAACW,eAAV,EAA2B;MACzBX,KAAK,CAACW,eAAN,CAAsBD,IAAtB;IACD;EACF,CAJD;;EAMA,MAAME,cAAc,GAAIC,IAAD,IAA+B;IACpDT,sBAAsB,CAACS,IAAD,CAAtB;EACD,CAFD;;EAIApB,gBAAgB,CAAC,CACf;IAAEqB,WAAW,EAAEhB,WAAW,CAACiB,mBAA3B;IAAgDC,MAAM,EAAEP;EAAxD,CADe,EAEf;IAAEK,WAAW,EAAEzB,WAAW,CAAC4B,oBAA3B;IAAiDD,MAAM,EAAEJ;EAAzD,CAFe,CAAD,CAAhB;EAKA7B,SAAS,CAAC,MAAM;IACda,0BAA0B,CAACY,MAAM,CAACU,OAAR,EAAiBf,mBAAjB,EAAsCH,KAAK,CAACmB,MAA5C,CAA1B;EACD,CAFQ,EAEN,CAAChB,mBAAD,CAFM,CAAT;;EAIA,MAAMiB,aAAa,GAAIC,OAAD,IAA6B;IACjD,QAAQA,OAAO,CAACC,IAAhB;MACE,KAAKjC,WAAW,CAACkC,sBAAjB;QACEjC,QAAQ,CAACkC,QAAT,CAAkBC,KAAlB,CAAwBpC,WAAW,CAACkC,sBAApC,EAA6DF,OAAO,CAACK,OAAT,CAA2Cb,IAAvG;QACA;;MACF,KAAKzB,WAAW,CAACuC,WAAjB;QACEzB,SAAS,CAAEmB,OAAO,CAACK,OAAT,CAAiCzB,MAAlC,CAAT;QACA;IANJ;EAQD,CATD;;EAWA,oBACE,oBAAC,IAAD;IAAM,KAAK,EAAE;MAAEA;IAAF;EAAb,gBACE,oBAAC,YAAD;IACE,GAAG,EAAEO,MADP;IAEE,IAAI,EAAEhB,gBAAgB,CAACkB,IAFzB;IAGE,gBAAgB,EAAEb,gBAAgB,CAAC+B,OAHrC;IAIE,MAAM,EAAElC,aAAa,CAACM,KAAD,CAJvB;IAKE,KAAK,EAAEA,KAAK,CAAC6B,KALf;IAME,MAAM,EAAElC,aAAa,EANvB;IAOE,SAAS,EAAE0B,OAAO,IAAID,aAAa,CAACC,OAAD,CAPrC;IAQE,KAAK,EAAEhB,WART;IASE,YAAY,EAAE;EAThB,EADF,CADF;AAeD,CApDM"}
@@ -1,11 +1,9 @@
1
1
  import { WebComponentType } from '../../webComponent/WebComponent';
2
2
  import { UnitMessage } from '../../messages/webMessages/unitMessages';
3
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
4
3
  export const getCardParams = props => {
5
4
  return `
6
5
  card-id="${props.cardId}"
7
6
  customer-token="${props.customerToken}"
8
- theme="${props.theme ?? UnitSDK.getTheme()}"
9
7
  `;
10
8
  };
11
9
  export const getCardScript = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["WebComponentType","UnitMessage","UnitSDK","getCardParams","props","cardId","customerToken","theme","getTheme","getCardScript","UNIT_REQUEST_REFRESH","injectRefreshEventIfNeeded","currentWeb","requestRefreshEvent","dependencies","includes","card","valueOf","resourceId","injectJavaScript","JSON","stringify"],"sources":["UNCardComponent.utils.ts"],"sourcesContent":["import type WebView from 'react-native-webview';\nimport type { UNCardComponentProps } from './UNCardComponent';\nimport { WebComponentType } from '../../webComponent/WebComponent';\nimport { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';\nimport { UnitSDK } from '../../unitSdkManager/UnitSdkManager';\n\nexport const getCardParams = (props: UNCardComponentProps) => {\n return `\n card-id=\"${props.cardId}\"\n customer-token=\"${props.customerToken}\"\n theme=\"${props.theme ?? UnitSDK.getTheme()}\"\n `;\n};\n\nexport const getCardScript = () => {\n return `\n const dispatchRefreshEvent = (details) => {\n const event = new CustomEvent(\"${UnitMessage.UNIT_REQUEST_REFRESH}\",{ detail: JSON.parse(details) })\n window.dispatchEvent(event)\n }\n `;\n};\n\nexport const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => {\n if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.card.valueOf()) && requestRefreshEvent.resourceId == cardId) {\n currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);\n }\n};\n"],"mappings":"AAEA,SAASA,gBAAT,QAAiC,iCAAjC;AACA,SAA8BC,WAA9B,QAAiD,yCAAjD;AACA,SAASC,OAAT,QAAwB,qCAAxB;AAEA,OAAO,MAAMC,aAAa,GAAIC,KAAD,IAAiC;EAC5D,OAAQ;AACV,eAAeA,KAAK,CAACC,MAAO;AAC5B,sBAAsBD,KAAK,CAACE,aAAc;AAC1C,aAAaF,KAAK,CAACG,KAAN,IAAeL,OAAO,CAACM,QAAR,EAAmB;AAC/C,GAJE;AAKD,CANM;AAQP,OAAO,MAAMC,aAAa,GAAG,MAAM;EACjC,OAAQ;AACV;AACA,qCAAqCR,WAAW,CAACS,oBAAqB;AACtE;AACA;AACA,GALE;AAMD,CAPM;AASP,OAAO,MAAMC,0BAA0B,GAAG,CAACC,UAAD,EAA6BC,mBAA7B,EAA8ER,MAA9E,KAAiG;EACzI,IAAIQ,mBAAmB,IAAIA,mBAAmB,CAACC,YAApB,CAAiCC,QAAjC,CAA0Cf,gBAAgB,CAACgB,IAAjB,CAAsBC,OAAtB,EAA1C,CAAvB,IAAqGJ,mBAAmB,CAACK,UAApB,IAAkCb,MAA3I,EAAmJ;IACjJO,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEO,gBAAZ,CAA8B,yBAAwBC,IAAI,CAACC,SAAL,CAAeR,mBAAf,CAAoC,IAA1F;EACD;AACF,CAJM"}
1
+ {"version":3,"names":["WebComponentType","UnitMessage","getCardParams","props","cardId","customerToken","getCardScript","UNIT_REQUEST_REFRESH","injectRefreshEventIfNeeded","currentWeb","requestRefreshEvent","dependencies","includes","card","valueOf","resourceId","injectJavaScript","JSON","stringify"],"sources":["UNCardComponent.utils.ts"],"sourcesContent":["import type WebView from 'react-native-webview';\nimport type { UNCardComponentProps } from './UNCardComponent';\nimport { WebComponentType } from '../../webComponent/WebComponent';\nimport { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';\n\nexport const getCardParams = (props: UNCardComponentProps) => {\n return `\n card-id=\"${props.cardId}\"\n customer-token=\"${props.customerToken}\"\n `;\n};\n\nexport const getCardScript = () => {\n return `\n const dispatchRefreshEvent = (details) => {\n const event = new CustomEvent(\"${UnitMessage.UNIT_REQUEST_REFRESH}\",{ detail: JSON.parse(details) })\n window.dispatchEvent(event)\n }\n `;\n};\n\nexport const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => {\n if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.card.valueOf()) && requestRefreshEvent.resourceId == cardId) {\n currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);\n }\n};\n"],"mappings":"AAEA,SAASA,gBAAT,QAAiC,iCAAjC;AACA,SAA8BC,WAA9B,QAAiD,yCAAjD;AAEA,OAAO,MAAMC,aAAa,GAAIC,KAAD,IAAiC;EAC5D,OAAQ;AACV,eAAeA,KAAK,CAACC,MAAO;AAC5B,sBAAsBD,KAAK,CAACE,aAAc;AAC1C,GAHE;AAID,CALM;AAOP,OAAO,MAAMC,aAAa,GAAG,MAAM;EACjC,OAAQ;AACV;AACA,qCAAqCL,WAAW,CAACM,oBAAqB;AACtE;AACA;AACA,GALE;AAMD,CAPM;AASP,OAAO,MAAMC,0BAA0B,GAAG,CAACC,UAAD,EAA6BC,mBAA7B,EAA8EN,MAA9E,KAAiG;EACzI,IAAIM,mBAAmB,IAAIA,mBAAmB,CAACC,YAApB,CAAiCC,QAAjC,CAA0CZ,gBAAgB,CAACa,IAAjB,CAAsBC,OAAtB,EAA1C,CAAvB,IAAqGJ,mBAAmB,CAACK,UAApB,IAAkCX,MAA3I,EAAmJ;IACjJK,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEO,gBAAZ,CAA8B,yBAAwBC,IAAI,CAACC,SAAL,CAAeR,mBAAf,CAAoC,IAA1F;EACD;AACF,CAJM"}
@@ -2,5 +2,6 @@ export let NativeMessage;
2
2
 
3
3
  (function (NativeMessage) {
4
4
  NativeMessage["IS_SCRIPT_FETCHED"] = "isScriptFetched";
5
+ NativeMessage["IS_SDK_INITIALIZED"] = "isSdkInitialized";
5
6
  })(NativeMessage || (NativeMessage = {}));
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeMessage"],"sources":["index.ts"],"sourcesContent":["export enum NativeMessage {\n IS_SCRIPT_FETCHED = 'isScriptFetched'\n}\n"],"mappings":"AAAA,WAAYA,aAAZ;;WAAYA,a;EAAAA,a;GAAAA,a,KAAAA,a"}
1
+ {"version":3,"names":["NativeMessage"],"sources":["index.ts"],"sourcesContent":["export enum NativeMessage {\n IS_SCRIPT_FETCHED = 'isScriptFetched',\n IS_SDK_INITIALIZED = 'isSdkInitialized'\n}\n"],"mappings":"AAAA,WAAYA,aAAZ;;WAAYA,a;EAAAA,a;EAAAA,a;GAAAA,a,KAAAA,a"}
@@ -8,7 +8,7 @@ export let PresentationMode;
8
8
  })(PresentationMode || (PresentationMode = {}));
9
9
 
10
10
  export const getHtmlBody = (unitComponent, unitComponentProps, presentationMode) => {
11
- const currentComponent = `<${unitComponent} ${unitComponentProps || ''}> </${unitComponent}>`;
11
+ const currentComponent = `<${unitComponent} ${unitComponentProps || ''} }> </${unitComponent}>`;
12
12
 
13
13
  switch (presentationMode) {
14
14
  case PresentationMode.CoverInjectedHeight:
@@ -1 +1 @@
1
- {"version":3,"names":["webViewId","PresentationMode","getHtmlBody","unitComponent","unitComponentProps","presentationMode","currentComponent","CoverInjectedHeight","getCoverInjectedHeightBodyScript","Inherit","getInheritParentSizeScript","currentUnitScript"],"sources":["bodyHtml.ts"],"sourcesContent":["export const webViewId = 'webViewContainer';\n\nexport enum PresentationMode {\n /*\n CoverInjectedHeight - give id (<webViewId> param) to enable style injection to the root. Then cover the injected height.\n\n Inherit - inherit the parent size by style of 100 view height\n\n Default - return the unit component script\n */\n\n CoverInjectedHeight = 'coverInjectedHeight',\n Inherit = 'inherit',\n Default = 'deafult'\n}\n\nexport const getHtmlBody = (unitComponent: string, unitComponentProps?: string, presentationMode?: PresentationMode) => {\n const currentComponent = `<${unitComponent} ${unitComponentProps || ''}> </${unitComponent}>`;\n\n switch (presentationMode) {\n case PresentationMode.CoverInjectedHeight:\n return getCoverInjectedHeightBodyScript(currentComponent);\n case PresentationMode.Inherit:\n return getInheritParentSizeScript(currentComponent);\n default:\n return currentComponent;\n }\n};\n\nconst getCoverInjectedHeightBodyScript = (currentUnitScript: string) => {\n return `\n <div id=${webViewId}>\n <div style=\"height: 100%; display: block; padding: 1px;\">\n ${currentUnitScript}\n </div>\n </div>\n `;\n};\n\nconst getInheritParentSizeScript = (currentUnitScript: string) => {\n return `\n <div style=\"height: 100vh\">\n ${currentUnitScript}\n </div>\n `;\n};\n"],"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG,kBAAlB;AAEP,WAAYC,gBAAZ;;WAAYA,gB;EAAAA,gB;EAAAA,gB;EAAAA,gB;GAAAA,gB,KAAAA,gB;;AAcZ,OAAO,MAAMC,WAAW,GAAG,CAACC,aAAD,EAAwBC,kBAAxB,EAAqDC,gBAArD,KAA6F;EACtH,MAAMC,gBAAgB,GAAI,IAAGH,aAAc,IAAGC,kBAAkB,IAAI,EAAG,OAAMD,aAAc,GAA3F;;EAEA,QAAQE,gBAAR;IACE,KAAKJ,gBAAgB,CAACM,mBAAtB;MACE,OAAOC,gCAAgC,CAACF,gBAAD,CAAvC;;IACF,KAAKL,gBAAgB,CAACQ,OAAtB;MACE,OAAOC,0BAA0B,CAACJ,gBAAD,CAAjC;;IACF;MACE,OAAOA,gBAAP;EANJ;AAQD,CAXM;;AAaP,MAAME,gCAAgC,GAAIG,iBAAD,IAA+B;EACtE,OAAQ;AACV,cAAcX,SAAU;AACxB;AACA,UAAUW,iBAAkB;AAC5B;AACA;AACA,GANE;AAOD,CARD;;AAUA,MAAMD,0BAA0B,GAAIC,iBAAD,IAA+B;EAChE,OAAQ;AACV;AACA,QAAQA,iBAAkB;AAC1B;AACA,GAJE;AAKD,CAND"}
1
+ {"version":3,"names":["webViewId","PresentationMode","getHtmlBody","unitComponent","unitComponentProps","presentationMode","currentComponent","CoverInjectedHeight","getCoverInjectedHeightBodyScript","Inherit","getInheritParentSizeScript","currentUnitScript"],"sources":["bodyHtml.ts"],"sourcesContent":["export const webViewId = 'webViewContainer';\n\nexport enum PresentationMode {\n /*\n CoverInjectedHeight - give id (<webViewId> param) to enable style injection to the root. Then cover the injected height.\n\n Inherit - inherit the parent size by style of 100 view height\n\n Default - return the unit component script\n */\n\n CoverInjectedHeight = 'coverInjectedHeight',\n Inherit = 'inherit',\n Default = 'deafult'\n}\n\nexport const getHtmlBody = (unitComponent: string, unitComponentProps?: string, presentationMode?: PresentationMode) => {\n const currentComponent = `<${unitComponent} ${unitComponentProps || ''} }> </${unitComponent}>`;\n\n switch (presentationMode) {\n case PresentationMode.CoverInjectedHeight:\n return getCoverInjectedHeightBodyScript(currentComponent);\n case PresentationMode.Inherit:\n return getInheritParentSizeScript(currentComponent);\n default:\n return currentComponent;\n }\n};\n\nconst getCoverInjectedHeightBodyScript = (currentUnitScript: string) => {\n return `\n <div id=${webViewId}>\n <div style=\"height: 100%; display: block; padding: 1px;\">\n ${currentUnitScript}\n </div>\n </div>\n `;\n};\n\nconst getInheritParentSizeScript = (currentUnitScript: string) => {\n return `\n <div style=\"height: 100vh\">\n ${currentUnitScript}\n </div>\n `;\n};\n"],"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG,kBAAlB;AAEP,WAAYC,gBAAZ;;WAAYA,gB;EAAAA,gB;EAAAA,gB;EAAAA,gB;GAAAA,gB,KAAAA,gB;;AAcZ,OAAO,MAAMC,WAAW,GAAG,CAACC,aAAD,EAAwBC,kBAAxB,EAAqDC,gBAArD,KAA6F;EACtH,MAAMC,gBAAgB,GAAI,IAAGH,aAAc,IAAGC,kBAAkB,IAAI,EAAG,SAAQD,aAAc,GAA7F;;EAEA,QAAQE,gBAAR;IACE,KAAKJ,gBAAgB,CAACM,mBAAtB;MACE,OAAOC,gCAAgC,CAACF,gBAAD,CAAvC;;IACF,KAAKL,gBAAgB,CAACQ,OAAtB;MACE,OAAOC,0BAA0B,CAACJ,gBAAD,CAAjC;;IACF;MACE,OAAOA,gBAAP;EANJ;AAQD,CAXM;;AAaP,MAAME,gCAAgC,GAAIG,iBAAD,IAA+B;EACtE,OAAQ;AACV,cAAcX,SAAU;AACxB;AACA,UAAUW,iBAAkB;AAC5B;AACA;AACA,GANE;AAOD,CARD;;AAUA,MAAMD,0BAA0B,GAAIC,iBAAD,IAA+B;EAChE,OAAQ;AACV;AACA,QAAQA,iBAAkB;AAC1B;AACA,GAJE;AAKD,CAND"}
@@ -1,5 +1,7 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
+ import EventBus from '../helpers/EventBus';
4
+ import { NativeMessage } from '../messages/nativeMessages';
3
5
  import { fetchUnitScript } from './UnitSdk.api';
4
6
  export let UNEnvironment;
5
7
 
@@ -23,6 +25,7 @@ _defineProperty(UnitSDK, "init", async (env, theme) => {
23
25
  UnitSDK.env = env;
24
26
  UnitSDK.theme = theme;
25
27
  await fetchUnitScript();
28
+ EventBus.Instance.event(NativeMessage.IS_SDK_INITIALIZED, {});
26
29
  } catch (e) {
27
30
  console.log(e);
28
31
  }
@@ -1 +1 @@
1
- {"version":3,"names":["fetchUnitScript","UNEnvironment","UNIT_SCRIPT_URL","sandbox","production","UnitSDK","env","theme","e","console","log"],"sources":["UnitSdkManager.ts"],"sourcesContent":["import { fetchUnitScript } from './UnitSdk.api';\n\nexport enum UNEnvironment {\n sandbox = 'sandbox',\n production = 'production'\n}\n\nexport const UNIT_SCRIPT_URL = {\n [UNEnvironment.sandbox]: 'https://ui.s.unit.sh/components.js',\n [UNEnvironment.production]: 'https://ui.unit.co/components.js'\n};\nexport class UnitSDK {\n protected static env?: UNEnvironment;\n protected static theme?: string;\n\n public static init = async (env: UNEnvironment, theme?: string) => {\n try {\n this.env = env;\n this.theme = theme;\n await fetchUnitScript();\n } catch (e) {\n console.log(e);\n }\n };\n\n public static getEnv = () => {\n return this.env;\n };\n\n public static getTheme = () => {\n return this.theme;\n };\n}\n"],"mappings":";;AAAA,SAASA,eAAT,QAAgC,eAAhC;AAEA,WAAYC,aAAZ;;WAAYA,a;EAAAA,a;EAAAA,a;GAAAA,a,KAAAA,a;;AAKZ,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACD,aAAa,CAACE,OAAf,GAAyB,oCADI;EAE7B,CAACF,aAAa,CAACG,UAAf,GAA4B;AAFC,CAAxB;AAIP,OAAO,MAAMC,OAAN,CAAc;;gBAARA,O;;gBAAAA,O;;gBAAAA,O,UAIU,OAAOC,GAAP,EAA2BC,KAA3B,KAA8C;EACjE,IAAI;IALKF,OAMP,CAAKC,GAAL,GAAWA,GAAX;IANOD,OAOP,CAAKE,KAAL,GAAaA,KAAb;IACA,MAAMP,eAAe,EAArB;EACD,CAJD,CAIE,OAAOQ,CAAP,EAAU;IACVC,OAAO,CAACC,GAAR,CAAYF,CAAZ;EACD;AACF,C;;gBAZUH,O,YAcY,MAAM;EAC3B,OAfSA,OAeF,CAAKC,GAAZ;AACD,C;;gBAhBUD,O,cAkBc,MAAM;EAC7B,OAnBSA,OAmBF,CAAKE,KAAZ;AACD,C"}
1
+ {"version":3,"names":["EventBus","NativeMessage","fetchUnitScript","UNEnvironment","UNIT_SCRIPT_URL","sandbox","production","UnitSDK","env","theme","Instance","event","IS_SDK_INITIALIZED","e","console","log"],"sources":["UnitSdkManager.ts"],"sourcesContent":["import EventBus from '../helpers/EventBus';\nimport { NativeMessage } from '../messages/nativeMessages';\nimport { fetchUnitScript } from './UnitSdk.api';\n\nexport enum UNEnvironment {\n sandbox = 'sandbox',\n production = 'production'\n}\n\nexport const UNIT_SCRIPT_URL = {\n [UNEnvironment.sandbox]: 'https://ui.s.unit.sh/components.js',\n [UNEnvironment.production]: 'https://ui.unit.co/components.js'\n};\nexport class UnitSDK {\n protected static env?: UNEnvironment;\n protected static theme?: string;\n\n public static init = async (env: UNEnvironment, theme?: string) => {\n try {\n this.env = env;\n this.theme = theme;\n await fetchUnitScript();\n EventBus.Instance.event(NativeMessage.IS_SDK_INITIALIZED, { });\n } catch (e) {\n console.log(e);\n }\n };\n\n public static getEnv = () => {\n return this.env;\n };\n\n public static getTheme = () => {\n return this.theme;\n };\n}\n"],"mappings":";;AAAA,OAAOA,QAAP,MAAqB,qBAArB;AACA,SAASC,aAAT,QAA8B,4BAA9B;AACA,SAASC,eAAT,QAAgC,eAAhC;AAEA,WAAYC,aAAZ;;WAAYA,a;EAAAA,a;EAAAA,a;GAAAA,a,KAAAA,a;;AAKZ,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACD,aAAa,CAACE,OAAf,GAAyB,oCADI;EAE7B,CAACF,aAAa,CAACG,UAAf,GAA4B;AAFC,CAAxB;AAIP,OAAO,MAAMC,OAAN,CAAc;;gBAARA,O;;gBAAAA,O;;gBAAAA,O,UAIU,OAAOC,GAAP,EAA2BC,KAA3B,KAA8C;EACjE,IAAI;IALKF,OAMP,CAAKC,GAAL,GAAWA,GAAX;IANOD,OAOP,CAAKE,KAAL,GAAaA,KAAb;IACA,MAAMP,eAAe,EAArB;IACAF,QAAQ,CAACU,QAAT,CAAkBC,KAAlB,CAAwBV,aAAa,CAACW,kBAAtC,EAA0D,EAA1D;EACD,CALD,CAKE,OAAOC,CAAP,EAAU;IACVC,OAAO,CAACC,GAAR,CAAYF,CAAZ;EACD;AACF,C;;gBAbUN,O,YAeY,MAAM;EAC3B,OAhBSA,OAgBF,CAAKC,GAAZ;AACD,C;;gBAjBUD,O,cAmBc,MAAM;EAC7B,OApBSA,OAoBF,CAAKE,KAAZ;AACD,C"}
@@ -8,6 +8,7 @@ import { useListenerToBus } from '../hooks/listenerToBus';
8
8
  import { getHtmlBody } from '../scripts/html/bodyHtml';
9
9
  import { fetchUnitScript, globalUnitScript } from '../unitSdkManager/UnitSdk.api';
10
10
  import { NativeMessage } from '../messages/nativeMessages';
11
+ import { UnitSDK } from '../unitSdkManager/UnitSdkManager';
11
12
  export let WebComponentType;
12
13
 
13
14
  (function (WebComponentType) {
@@ -20,15 +21,23 @@ export let WebComponentType;
20
21
  export const WebComponent = /*#__PURE__*/React.forwardRef(function WebComponent(props, webRef) {
21
22
  const [unitScript, setUnitScript] = useState(globalUnitScript);
22
23
  const [sourceHtml, setSourceHtml] = useState(null);
24
+ const [componentCurrentTheme, setComponentCurrentTheme] = useState(props.theme ?? UnitSDK.getTheme());
23
25
  const width = props.width ?? '100%';
24
26
 
25
- const listenerAction = data => {
27
+ const updateUnitScript = data => {
26
28
  setUnitScript(data.unitScript);
27
29
  };
28
30
 
31
+ const updateInitializedParams = () => {
32
+ setComponentCurrentTheme(props.theme ?? UnitSDK.getTheme());
33
+ };
34
+
29
35
  useListenerToBus([{
30
36
  busEventKey: NativeMessage.IS_SCRIPT_FETCHED,
31
- action: listenerAction
37
+ action: updateUnitScript
38
+ }, {
39
+ busEventKey: NativeMessage.IS_SDK_INITIALIZED,
40
+ action: updateInitializedParams
32
41
  }]);
33
42
  useEffect(() => {
34
43
  if (!unitScript) {
@@ -36,10 +45,11 @@ export const WebComponent = /*#__PURE__*/React.forwardRef(function WebComponent(
36
45
  return;
37
46
  }
38
47
 
39
- let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), props.params, props.presentationMode));
48
+ const componentParams = (props.params || '') + (componentCurrentTheme ? ` theme="${componentCurrentTheme}"` : '');
49
+ let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));
40
50
  newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');
41
51
  setSourceHtml(newHtml);
42
- }, [props.params, unitScript]);
52
+ }, [props.params, unitScript, props.presentationMode, componentCurrentTheme]);
43
53
 
44
54
  const onMessage = e => {
45
55
  const message = JSON.parse(e.nativeEvent.data);
@@ -65,6 +75,7 @@ export const WebComponent = /*#__PURE__*/React.forwardRef(function WebComponent(
65
75
  ref: webRef,
66
76
  cacheEnabled: false,
67
77
  scrollEnabled: props.isScrollable,
78
+ nestedScrollEnabled: props.nestedScrollEnabled,
68
79
  onScroll: _onScroll,
69
80
  overScrollMode: "never",
70
81
  injectedJavaScript: unitScript,
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useState","WebView","EventBus","html","HTML_PLACEHOLDER","UnitMessage","useListenerToBus","getHtmlBody","fetchUnitScript","globalUnitScript","NativeMessage","WebComponentType","WebComponent","forwardRef","props","webRef","unitScript","setUnitScript","sourceHtml","setSourceHtml","width","listenerAction","data","busEventKey","IS_SCRIPT_FETCHED","action","newHtml","replace","BODY","type","valueOf","params","presentationMode","SCRIPT_FROM_NATIVE","script","onMessage","e","message","JSON","parse","nativeEvent","UNIT_REQUEST_REFRESH","details","Instance","event","_onScroll","handleScroll","isScrollable","flex"],"sources":["WebComponent.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React, { useEffect, useState } from 'react';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport EventBus from '../helpers/EventBus';\nimport html, { HTML_PLACEHOLDER } from './html';\nimport { RequestRefreshEvent, UnitMessage } from '../messages/webMessages/unitMessages';\nimport { useListenerToBus } from '../hooks/listenerToBus';\nimport { getHtmlBody, PresentationMode } from '../scripts/html/bodyHtml';\nimport { fetchUnitScript, globalUnitScript } from '../unitSdkManager/UnitSdk.api';\nimport { NativeMessage } from '../messages/nativeMessages';\nimport type { WebViewMessage } from '../messages/webMessages';\n\nexport interface WebComponentProps {\n type: WebComponentType;\n presentationMode?: PresentationMode,\n params?: string;\n onMessage?: (message: WebViewMessage) => void;\n script?: string;\n isScrollable?: boolean,\n handleScroll?: (event: any) => void,\n width?: number;\n}\n\nexport enum WebComponentType {\n card = 'unit-elements-card',\n bookPayment = 'unit-elements-book-payment',\n activity = 'unit-elements-activity',\n slot = 'unit-elements-sdk-slot'\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 width = props.width ?? '100%';\n\n const listenerAction = (data: { unitScript?: string }) => {\n setUnitScript(data.unitScript);\n };\n\n useListenerToBus([{ busEventKey: NativeMessage.IS_SCRIPT_FETCHED, action: listenerAction }]);\n\n useEffect(() => {\n if (!unitScript) {\n fetchUnitScript();\n return;\n }\n\n let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), props.params, props.presentationMode));\n newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');\n setSourceHtml(newHtml);\n\n }, [props.params, unitScript]);\n\n const onMessage = (e: WebViewMessageEvent) => {\n const message = JSON.parse(e.nativeEvent.data) as WebViewMessage;\n if (message.type == UnitMessage.UNIT_REQUEST_REFRESH && message.details) {\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_REFRESH, message.details as RequestRefreshEvent);\n } else {\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 return (\n <WebView\n ref={webRef}\n cacheEnabled={false}\n scrollEnabled={props.isScrollable}\n onScroll={_onScroll}\n overScrollMode=\"never\"\n injectedJavaScript={unitScript}\n style={{ width: width, flex: 1 }}\n source={{ html: sourceHtml }}\n onMessage={onMessage} />\n );\n});\n"],"mappings":"AAAA;AACA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,OAAOC,QAAP,MAAqB,qBAArB;AACA,OAAOC,IAAP,IAAeC,gBAAf,QAAuC,QAAvC;AACA,SAA8BC,WAA9B,QAAiD,sCAAjD;AACA,SAASC,gBAAT,QAAiC,wBAAjC;AACA,SAASC,WAAT,QAA8C,0BAA9C;AACA,SAASC,eAAT,EAA0B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C,CAAD,IAA4B;IAC5C,MAAMC,OAAO,GAAGC,IAAI,CAACC,KAAL,CAAWH,CAAC,CAACI,WAAF,CAAclB,IAAzB,CAAhB;;IACA,IAAIe,OAAO,CAACR,IAAR,IAAgBxB,WAAW,CAACoC,oBAA5B,IAAoDJ,OAAO,CAACK,OAAhE,EAAyE;MACvExC,QAAQ,CAACyC,QAAT,CAAkBC,KAAlB,CAAwBvC,WAAW,CAACoC,oBAApC,EAA0DJ,OAAO,CAACK,OAAlE;IACD,CAFD,MAEO;MACL5B,KAAK,CAACqB,SAAN,IAAmBrB,KAAK,CAACqB,SAAN,CAAgBE,OAAhB,CAAnB;IACD;EACF,CAPD;;EASA,IAAI,CAACnB,UAAL,EAAiB,OAAO,IAAP;;EAEjB,MAAM2B,SAAS,GAAID,KAAD,IAAgB;IAChC,IAAI9B,KAAK,CAACgC,YAAV,EAAwB;MACtBhC,KAAK,CAACgC,YAAN,CAAmBF,KAAnB;IACD;;IAED,OAAO,IAAP;EACD,CAND;;EAQA,oBACE,oBAAC,OAAD;IACE,GAAG,EAAE7B,MADP;IAEE,YAAY,EAAE,KAFhB;IAGE,aAAa,EAAED,KAAK,CAACiC,YAHvB;IAIE,QAAQ,EAAEF,SAJZ;IAKE,cAAc,EAAC,OALjB;IAME,kBAAkB,EAAE7B,UANtB;IAOE,KAAK,EAAE;MAAEI,KAAK,EAAEA,KAAT;MAAgB4B,IAAI,EAAE;IAAtB,CAPT;IAQE,MAAM,EAAE;MAAE7C,IAAI,EAAEe;IAAR,CARV;IASE,SAAS,EAAEiB;EATb,EADF;AAYD,CAtD2B,CAArB"}
1
+ {"version":3,"names":["React","useEffect","useState","WebView","EventBus","html","HTML_PLACEHOLDER","UnitMessage","useListenerToBus","getHtmlBody","fetchUnitScript","globalUnitScript","NativeMessage","UnitSDK","WebComponentType","WebComponent","forwardRef","props","webRef","unitScript","setUnitScript","sourceHtml","setSourceHtml","componentCurrentTheme","setComponentCurrentTheme","theme","getTheme","width","updateUnitScript","data","updateInitializedParams","busEventKey","IS_SCRIPT_FETCHED","action","IS_SDK_INITIALIZED","componentParams","params","newHtml","replace","BODY","type","valueOf","presentationMode","SCRIPT_FROM_NATIVE","script","onMessage","e","message","JSON","parse","nativeEvent","UNIT_REQUEST_REFRESH","details","Instance","event","_onScroll","handleScroll","isScrollable","nestedScrollEnabled","flex"],"sources":["WebComponent.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React, { useEffect, useState } from 'react';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport EventBus from '../helpers/EventBus';\nimport html, { HTML_PLACEHOLDER } from './html';\nimport { RequestRefreshEvent, UnitMessage } from '../messages/webMessages/unitMessages';\nimport { useListenerToBus } from '../hooks/listenerToBus';\nimport { getHtmlBody, PresentationMode } from '../scripts/html/bodyHtml';\nimport { fetchUnitScript, globalUnitScript } from '../unitSdkManager/UnitSdk.api';\nimport { NativeMessage } from '../messages/nativeMessages';\nimport { UnitSDK } from '../unitSdkManager/UnitSdkManager';\nimport type { WebViewMessage } from '../messages/webMessages';\n\nexport interface WebComponentProps {\n type: WebComponentType;\n presentationMode?: PresentationMode,\n params?: string;\n theme?: string;\n onMessage?: (message: WebViewMessage) => void;\n script?: string;\n isScrollable?: boolean,\n nestedScrollEnabled?: boolean,\n handleScroll?: (event: any) => void,\n width?: number;\n}\n\nexport enum WebComponentType {\n card = 'unit-elements-card',\n bookPayment = 'unit-elements-book-payment',\n activity = 'unit-elements-activity',\n slot = 'unit-elements-sdk-slot'\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 width = props.width ?? '100%';\n\n const updateUnitScript = (data: { unitScript?: string }) => {\n setUnitScript(data.unitScript);\n };\n\n const updateInitializedParams = () => {\n setComponentCurrentTheme(props.theme ?? UnitSDK.getTheme());\n };\n\n useListenerToBus([\n { busEventKey: NativeMessage.IS_SCRIPT_FETCHED, action: updateUnitScript },\n { busEventKey: NativeMessage.IS_SDK_INITIALIZED, action: updateInitializedParams },\n ]);\n\n useEffect(() => {\n if (!unitScript) {\n fetchUnitScript();\n return;\n }\n\n const componentParams = (props.params || '') + (componentCurrentTheme ? ` theme=\"${componentCurrentTheme}\"` : '');\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 setSourceHtml(newHtml);\n }, [props.params, unitScript, props.presentationMode, componentCurrentTheme]);\n\n const onMessage = (e: WebViewMessageEvent) => {\n const message = JSON.parse(e.nativeEvent.data) as WebViewMessage;\n if (message.type == UnitMessage.UNIT_REQUEST_REFRESH && message.details) {\n EventBus.Instance.event(UnitMessage.UNIT_REQUEST_REFRESH, message.details as RequestRefreshEvent);\n } else {\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 return (\n <WebView\n ref={webRef}\n cacheEnabled={false}\n scrollEnabled={props.isScrollable}\n nestedScrollEnabled={props.nestedScrollEnabled}\n onScroll={_onScroll}\n overScrollMode=\"never\"\n injectedJavaScript={unitScript}\n style={{ width: width, flex: 1 }}\n source={{ html: sourceHtml }}\n onMessage={onMessage} />\n );\n});\n"],"mappings":"AAAA;AACA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,OAAOC,QAAP,MAAqB,qBAArB;AACA,OAAOC,IAAP,IAAeC,gBAAf,QAAuC,QAAvC;AACA,SAA8BC,WAA9B,QAAiD,sCAAjD;AACA,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;;IAED,OAAO,IAAP;EACD,CAND;;EAQA,oBACE,oBAAC,OAAD;IACE,GAAG,EAAEpC,MADP;IAEE,YAAY,EAAE,KAFhB;IAGE,aAAa,EAAED,KAAK,CAACwC,YAHvB;IAIE,mBAAmB,EAAExC,KAAK,CAACyC,mBAJ7B;IAKE,QAAQ,EAAEH,SALZ;IAME,cAAc,EAAC,OANjB;IAOE,kBAAkB,EAAEpC,UAPtB;IAQE,KAAK,EAAE;MAAEQ,KAAK,EAAEA,KAAT;MAAgBgC,IAAI,EAAE;IAAtB,CART;IASE,MAAM,EAAE;MAAEtD,IAAI,EAAEgB;IAAR,CATV;IAUE,SAAS,EAAEwB;EAVb,EADF;AAaD,CA/D2B,CAArB"}
@@ -1,3 +1,4 @@
1
1
  export declare enum NativeMessage {
2
- IS_SCRIPT_FETCHED = "isScriptFetched"
2
+ IS_SCRIPT_FETCHED = "isScriptFetched",
3
+ IS_SDK_INITIALIZED = "isSdkInitialized"
3
4
  }
@@ -6,9 +6,11 @@ export interface WebComponentProps {
6
6
  type: WebComponentType;
7
7
  presentationMode?: PresentationMode;
8
8
  params?: string;
9
+ theme?: string;
9
10
  onMessage?: (message: WebViewMessage) => void;
10
11
  script?: string;
11
12
  isScrollable?: boolean;
13
+ nestedScrollEnabled?: boolean;
12
14
  handleScroll?: (event: any) => void;
13
15
  width?: number;
14
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unit-components",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Unit React Native components",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,8 +1,12 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
+ import { Dimensions, View } from 'react-native';
3
+ import type { WebViewMessage } from '../../messages/webMessages';
4
+ import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
2
5
  import { PresentationMode } from '../../scripts/html/bodyHtml';
3
6
  import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
4
7
  import { getActivityParams } from './UNActivityComponent.utils';
5
8
 
9
+ const DEFAULT_HEIGHT = Dimensions.get('window').height * 0.5;
6
10
  export interface UNActivityComponentProps {
7
11
  accountId: string;
8
12
  customerToken: string;
@@ -10,12 +14,34 @@ export interface UNActivityComponentProps {
10
14
  }
11
15
 
12
16
  export const UNActivityComponent = (props: UNActivityComponentProps) => {
17
+ const [defaultHeight, setDefaultHeight] = useState<number>();
18
+ const handleWebViewMessage = (message: WebViewMessage) => {
19
+ if (message.type === PageMessage.PAGE_HEIGHT) {
20
+ const currentHeight = (message.details as HeightEvent).height;
21
+ currentHeight === 0 && setDefaultHeight(DEFAULT_HEIGHT);
22
+ }
23
+ };
24
+
25
+ const renderActivityWebView = () => {
26
+ return (
27
+ <WebComponent
28
+ type={WebComponentType.activity}
29
+ presentationMode={PresentationMode.Inherit}
30
+ params={getActivityParams(props)}
31
+ onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
32
+ nestedScrollEnabled={true}
33
+ theme={props.theme}
34
+ />
35
+ );
36
+ };
37
+
38
+ if (!defaultHeight) {
39
+ return renderActivityWebView();
40
+ }
41
+
13
42
  return (
14
- <WebComponent
15
- type={WebComponentType.activity}
16
- presentationMode={PresentationMode.Inherit}
17
- params={getActivityParams(props)}
18
- isScrollable={false}
19
- />
43
+ <View style={{ height: defaultHeight }}>
44
+ {renderActivityWebView()}
45
+ </View>
20
46
  );
21
47
  };
@@ -1,11 +1,9 @@
1
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
2
1
  import type { UNActivityComponentProps } from './UNActivityComponent';
3
2
 
4
3
  export const getActivityParams = (props: UNActivityComponentProps) => {
5
4
  return `
6
5
  account-id="${props.accountId}"
7
6
  customer-token="${props.customerToken}"
8
- theme="${props.theme ?? UnitSDK.getTheme()}"
9
7
  style="height: 100%"
10
8
  `;
11
9
  };
@@ -1,10 +1,12 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
3
3
  import { PresentationMode } from '../../scripts/html/bodyHtml';
4
4
  import { getBookPaymentParams, getBookPaymentScript } from './UNBookPaymentComponent.utils';
5
5
  import type { WebViewMessage } from '../../messages/webMessages';
6
6
  import { BookPaymentEvent, BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';
7
7
  import type { UNBookPaymentData } from '../../sharedTypes';
8
+ import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
9
+ import { View } from 'react-native';
8
10
 
9
11
  export interface UNBookPaymentComponentProps {
10
12
  accountId: string;
@@ -17,21 +19,45 @@ export interface UNBookPaymentComponentProps {
17
19
  }
18
20
 
19
21
  export const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {
22
+ const [height, setHeight] = useState<number>(0);
23
+ const [presentationMode, setPresentationMode] = useState<PresentationMode>(PresentationMode.Inherit);
24
+
20
25
  const handleWebViewMessage = (message: WebViewMessage) => {
21
26
  if (message.type === BookPaymentMessage.PAYMENT_CREATED && props.onPaymentCreated) {
22
27
  const response = message.details as BookPaymentEvent;
23
28
  props.onPaymentCreated(response.data);
24
29
  }
30
+
31
+ if (message.type === PageMessage.PAGE_HEIGHT) {
32
+ const currentHeight = (message.details as HeightEvent).height;
33
+ setHeight(currentHeight);
34
+ if (presentationMode === PresentationMode.Inherit && currentHeight === 0) {
35
+ setPresentationMode(PresentationMode.Default);
36
+ }
37
+ }
25
38
  };
26
39
 
40
+ const renderBookPaymentWebView = () => {
41
+ return (
42
+ <WebComponent
43
+ type={WebComponentType.bookPayment}
44
+ presentationMode={presentationMode}
45
+ params={getBookPaymentParams(props)}
46
+ script={getBookPaymentScript()}
47
+ onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
48
+ isScrollable={false}
49
+ theme={props.theme}
50
+ />
51
+ );
52
+ };
53
+
54
+ if (presentationMode === PresentationMode.Inherit) {
55
+ return renderBookPaymentWebView();
56
+ }
57
+
27
58
  return (
28
- <WebComponent
29
- type={WebComponentType.bookPayment}
30
- presentationMode={PresentationMode.Inherit}
31
- params={getBookPaymentParams(props)}
32
- script={getBookPaymentScript()}
33
- onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
34
- isScrollable={false}
35
- />
59
+ <View style={{ height: height }}>
60
+ {renderBookPaymentWebView()}
61
+ </View>
36
62
  );
37
63
  };
@@ -1,7 +1,6 @@
1
1
  import type { UNBookPaymentComponentProps } from './UNBookPaymentComponent';
2
2
 
3
3
  import { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';
4
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
5
4
 
6
5
  export const getBookPaymentParams = (props: UNBookPaymentComponentProps) => {
7
6
  return `
@@ -10,7 +9,6 @@ export const getBookPaymentParams = (props: UNBookPaymentComponentProps) => {
10
9
  is-same-customer="${props.isSameCustomer}"
11
10
  counterparty-account-id="${props.counterPartyAccountId}"
12
11
  counterparty-name="${props.counterPartyName}"
13
- theme="${props.theme ?? UnitSDK.getTheme()}"
14
12
  style="height: 100%"
15
13
  `;
16
14
  };
@@ -63,6 +63,7 @@ export const UNCardComponent = (props: UNCardComponentProps) => {
63
63
  type={WebComponentType.card}
64
64
  presentationMode={PresentationMode.Default}
65
65
  params={getCardParams(props)}
66
+ theme={props.theme}
66
67
  script={getCardScript()}
67
68
  onMessage={message => handleMessage(message)}
68
69
  width={windowWidth}
@@ -2,13 +2,11 @@ import type WebView from 'react-native-webview';
2
2
  import type { UNCardComponentProps } from './UNCardComponent';
3
3
  import { WebComponentType } from '../../webComponent/WebComponent';
4
4
  import { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
5
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
6
5
 
7
6
  export const getCardParams = (props: UNCardComponentProps) => {
8
7
  return `
9
8
  card-id="${props.cardId}"
10
9
  customer-token="${props.customerToken}"
11
- theme="${props.theme ?? UnitSDK.getTheme()}"
12
10
  `;
13
11
  };
14
12
 
@@ -1,3 +1,4 @@
1
1
  export enum NativeMessage {
2
- IS_SCRIPT_FETCHED = 'isScriptFetched'
2
+ IS_SCRIPT_FETCHED = 'isScriptFetched',
3
+ IS_SDK_INITIALIZED = 'isSdkInitialized'
3
4
  }
@@ -15,7 +15,7 @@ export enum PresentationMode {
15
15
  }
16
16
 
17
17
  export const getHtmlBody = (unitComponent: string, unitComponentProps?: string, presentationMode?: PresentationMode) => {
18
- const currentComponent = `<${unitComponent} ${unitComponentProps || ''}> </${unitComponent}>`;
18
+ const currentComponent = `<${unitComponent} ${unitComponentProps || ''} }> </${unitComponent}>`;
19
19
 
20
20
  switch (presentationMode) {
21
21
  case PresentationMode.CoverInjectedHeight:
@@ -1,3 +1,5 @@
1
+ import EventBus from '../helpers/EventBus';
2
+ import { NativeMessage } from '../messages/nativeMessages';
1
3
  import { fetchUnitScript } from './UnitSdk.api';
2
4
 
3
5
  export enum UNEnvironment {
@@ -18,6 +20,7 @@ export class UnitSDK {
18
20
  this.env = env;
19
21
  this.theme = theme;
20
22
  await fetchUnitScript();
23
+ EventBus.Instance.event(NativeMessage.IS_SDK_INITIALIZED, { });
21
24
  } catch (e) {
22
25
  console.log(e);
23
26
  }