react-native-unit-components 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -6
- package/android/src/main/AndroidManifest.xml +12 -1
- package/android/src/main/java/com/unitreactnativecomponents/UnitReactNativeComponentsPackage.kt +2 -1
- package/android/src/main/java/com/unitreactnativecomponents/sharepdf/UNSharePDF.kt +75 -0
- package/android/src/main/res/layout/un_black_add_to_googlepay_button.xml +2 -2
- package/android/src/main/res/layout/un_view_google_push_provisioning.xml +1 -13
- package/android/src/main/res/layout/un_white_add_to_googlepay_button.xml +1 -1
- package/android/src/main/res/layout/un_white_add_to_googlepay_button_no_shadow.xml +1 -1
- package/android/src/main/res/xml/file_paths.xml +4 -0
- package/ios/UnitReactNativeComponentsViewManager.m +0 -1
- package/ios/UnitReactNativeComponentsViewManager.swift +6 -2
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +103 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js +47 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +28 -4
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +19 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +22 -10
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +4 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +3 -3
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js +114 -46
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +4 -8
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +95 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +31 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +64 -7
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +62 -8
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js +20 -0
- package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
- package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +42 -0
- package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
- package/lib/commonjs/components/index.js +13 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.js +32 -12
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
- package/lib/commonjs/helpers/EventBus.js.map +1 -1
- package/lib/commonjs/messages/nativeMessages/cardMessage.js +36 -0
- package/lib/commonjs/messages/nativeMessages/cardMessage.js.map +1 -0
- package/lib/commonjs/messages/nativeMessages/index.js +0 -8
- package/lib/commonjs/messages/nativeMessages/index.js.map +1 -1
- package/lib/commonjs/messages/nativeMessages/sdkMessage.js +14 -0
- package/lib/commonjs/messages/nativeMessages/sdkMessage.js.map +1 -0
- package/lib/commonjs/messages/webMessages/unitMessages.js +1 -0
- package/lib/commonjs/messages/webMessages/unitMessages.js.map +1 -1
- package/lib/commonjs/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
- package/lib/commonjs/nativeComponent/UnitAddToWalletButton.js.map +1 -0
- package/lib/commonjs/scripts/html/bodyScript.js +22 -5
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
- package/lib/commonjs/sharedTypes/bookPayment.types.js.map +1 -1
- package/lib/commonjs/sharedTypes/card.types.js.map +1 -1
- package/lib/commonjs/sharedTypes/index.js +13 -0
- package/lib/commonjs/sharedTypes/index.js.map +1 -1
- package/lib/commonjs/sharedTypes/onLoadResponse.types.js +6 -0
- package/lib/commonjs/sharedTypes/onLoadResponse.types.js.map +1 -0
- package/lib/commonjs/sharedTypes/wallet.types.js +22 -0
- package/lib/commonjs/sharedTypes/wallet.types.js.map +1 -0
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js +5 -3
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js.map +1 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js +12 -2
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.js +20 -8
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.utils.js +41 -0
- package/lib/commonjs/webComponent/WebComponent.utils.js.map +1 -0
- package/lib/commonjs/webComponent/html.js +9 -1
- package/lib/commonjs/webComponent/html.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js +74 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js +26 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js +28 -6
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +10 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +21 -10
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +3 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js +111 -46
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +5 -9
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +68 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +21 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.js +64 -9
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +51 -7
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js +10 -0
- package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
- package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +28 -0
- package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/helpers/BottomSheet/BottomSheet.js +30 -13
- package/lib/module/helpers/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js +2 -2
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
- package/lib/module/helpers/EventBus.js.map +1 -1
- package/lib/module/messages/nativeMessages/cardMessage.js +27 -0
- package/lib/module/messages/nativeMessages/cardMessage.js.map +1 -0
- package/lib/module/messages/nativeMessages/index.js +1 -6
- package/lib/module/messages/nativeMessages/index.js.map +1 -1
- package/lib/module/messages/nativeMessages/sdkMessage.js +7 -0
- package/lib/module/messages/nativeMessages/sdkMessage.js.map +1 -0
- package/lib/module/messages/webMessages/unitMessages.js +1 -0
- package/lib/module/messages/webMessages/unitMessages.js.map +1 -1
- package/lib/module/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
- package/lib/module/nativeComponent/UnitAddToWalletButton.js.map +1 -0
- package/lib/module/scripts/html/bodyScript.js +19 -3
- package/lib/module/scripts/html/bodyScript.js.map +1 -1
- package/lib/module/sharedTypes/bookPayment.types.js.map +1 -1
- package/lib/module/sharedTypes/card.types.js.map +1 -1
- package/lib/module/sharedTypes/index.js +1 -0
- package/lib/module/sharedTypes/index.js.map +1 -1
- package/lib/module/sharedTypes/onLoadResponse.types.js +2 -0
- package/lib/module/sharedTypes/onLoadResponse.types.js.map +1 -0
- package/lib/module/sharedTypes/wallet.types.js +14 -0
- package/lib/module/sharedTypes/wallet.types.js.map +1 -0
- package/lib/module/unitSdkManager/UnitSdk.api.js +4 -3
- package/lib/module/unitSdkManager/UnitSdk.api.js.map +1 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js +12 -2
- package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/module/webComponent/WebComponent.js +18 -7
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/module/webComponent/WebComponent.utils.js +27 -0
- package/lib/module/webComponent/WebComponent.utils.js.map +1 -0
- package/lib/module/webComponent/html.js +9 -2
- package/lib/module/webComponent/html.js.map +1 -1
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.d.ts +12 -0
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.utils.d.ts +7 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +2 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.utils.d.ts +4 -0
- package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.d.ts +2 -1
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.d.ts +1 -1
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.d.ts +9 -2
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.d.ts +2 -1
- package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.d.ts +6 -0
- package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.d.ts +17 -0
- package/lib/typescript/components/UNCardComponent/UNCardComponent.d.ts +4 -1
- package/lib/typescript/components/UNCardComponent/UNCardComponent.utils.d.ts +9 -1
- package/lib/typescript/components/UNCardComponent/networking/common/UNNetworkConstants.d.ts +8 -0
- package/lib/typescript/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.d.ts +2 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/helpers/EventBus.d.ts +3 -3
- package/lib/typescript/messages/nativeMessages/cardMessage.d.ts +28 -0
- package/lib/typescript/messages/nativeMessages/index.d.ts +7 -3
- package/lib/typescript/messages/nativeMessages/sdkMessage.d.ts +8 -0
- package/lib/typescript/messages/webMessages/unitMessages.d.ts +16 -6
- package/lib/typescript/scripts/html/bodyScript.d.ts +4 -1
- package/lib/typescript/sharedTypes/bookPayment.types.d.ts +3 -3
- package/lib/typescript/sharedTypes/card.types.d.ts +6 -6
- package/lib/typescript/sharedTypes/index.d.ts +1 -0
- package/lib/typescript/sharedTypes/onLoadResponse.types.d.ts +18 -0
- package/lib/typescript/sharedTypes/wallet.types.d.ts +14 -0
- package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +3 -0
- package/lib/typescript/webComponent/WebComponent.d.ts +2 -1
- package/lib/typescript/webComponent/WebComponent.utils.d.ts +2 -0
- package/package.json +2 -1
- package/src/components/UNAccountComponent/UNAccountComponent.tsx +82 -0
- package/src/components/UNAccountComponent/UNAccountComponent.utils.ts +30 -0
- package/src/components/UNActivityComponent/UNActivityComponent.tsx +28 -5
- package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +14 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +18 -10
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +3 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.ts +1 -1
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.tsx +120 -44
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.ts +7 -10
- package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.ts +21 -0
- package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.tsx +74 -0
- package/src/components/UNCardComponent/UNCardComponent.tsx +67 -13
- package/src/components/UNCardComponent/UNCardComponent.utils.ts +51 -7
- package/src/components/UNCardComponent/networking/common/UNNetworkConstants.ts +11 -0
- package/src/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.ts +32 -0
- package/src/components/index.ts +1 -0
- package/src/helpers/BottomSheet/BottomSheet.styles.ts +2 -2
- package/src/helpers/BottomSheet/BottomSheet.tsx +28 -12
- package/src/helpers/EventBus.ts +3 -3
- package/src/messages/nativeMessages/cardMessage.ts +37 -0
- package/src/messages/nativeMessages/index.ts +14 -3
- package/src/messages/nativeMessages/sdkMessage.ts +11 -0
- package/src/messages/webMessages/unitMessages.ts +20 -7
- package/src/scripts/html/bodyScript.ts +21 -4
- package/src/sharedTypes/bookPayment.types.ts +3 -3
- package/src/sharedTypes/card.types.ts +6 -6
- package/src/sharedTypes/index.ts +1 -0
- package/src/sharedTypes/onLoadResponse.types.ts +27 -0
- package/src/sharedTypes/wallet.types.ts +17 -0
- package/src/unitSdkManager/UnitSdk.api.ts +3 -2
- package/src/unitSdkManager/UnitSdkManager.ts +11 -2
- package/src/webComponent/WebComponent.tsx +21 -10
- package/src/webComponent/WebComponent.utils.ts +26 -0
- package/src/webComponent/html.ts +9 -2
- package/lib/commonjs/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
- package/lib/module/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
- /package/lib/typescript/nativeComponent/{UNNativeAddToWalletButton.d.ts → UnitAddToWalletButton.d.ts} +0 -0
- /package/src/nativeComponent/{UNNativeAddToWalletButton.tsx → UnitAddToWalletButton.tsx} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Dimensions, View } from 'react-native';
|
|
3
|
+
import type WebView from 'react-native-webview';
|
|
4
|
+
import { HeightEvent, PageMessage } from '../..//messages/webMessages/pageMessage';
|
|
5
|
+
import { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
6
|
+
import EventBus from '../../helpers/EventBus';
|
|
7
|
+
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
8
|
+
import { useListenerToBus } from '../../hooks/listenerToBus';
|
|
9
|
+
import type { WebViewMessage } from '../../messages/webMessages';
|
|
10
|
+
import { getAccountParams, getAccountScript, injectRefreshEventIfNeeded } from './UNAccountComponent.utils';
|
|
11
|
+
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
12
|
+
import type { BottomSheetSlotData } from '../UNBottomSheetComponent/UNBottomSheetComponent';
|
|
13
|
+
import type { ResponseUnitOnLoadEvent } from '../../sharedTypes';
|
|
14
|
+
|
|
15
|
+
export interface UNAccountComponentProps {
|
|
16
|
+
accountId?: string;
|
|
17
|
+
customerToken: string;
|
|
18
|
+
theme?: string;
|
|
19
|
+
onLoad?: (response: ResponseUnitOnLoadEvent) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export enum AccountAction {
|
|
23
|
+
List = 'account-list',
|
|
24
|
+
Menu = 'account-menu'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const UNAccountComponent = (props: UNAccountComponentProps) => {
|
|
28
|
+
const [height, setHeight] = useState(0);
|
|
29
|
+
const windowWidth = Dimensions.get('window').width;
|
|
30
|
+
|
|
31
|
+
const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);
|
|
32
|
+
|
|
33
|
+
const webRef = useRef<WebView>(null);
|
|
34
|
+
|
|
35
|
+
const requestRefresh = (data: RequestRefreshEvent) => {
|
|
36
|
+
setRequestRefreshEvent(data);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
useListenerToBus([
|
|
40
|
+
{ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
injectRefreshEventIfNeeded(webRef.current, requestRefreshEvent);
|
|
45
|
+
}, [requestRefreshEvent]);
|
|
46
|
+
|
|
47
|
+
const handleMessage = (message: WebViewMessage) => {
|
|
48
|
+
switch (message.type) {
|
|
49
|
+
case UnitMessage.UNIT_ON_LOAD:
|
|
50
|
+
props.onLoad && props.onLoad(message.details as ResponseUnitOnLoadEvent);
|
|
51
|
+
break;
|
|
52
|
+
case UnitMessage.UNIT_REQUEST_RENDERING: {
|
|
53
|
+
const event: BottomSheetSlotData = {
|
|
54
|
+
componentName: WebComponentType.account,
|
|
55
|
+
componentResourceId: props.accountId,
|
|
56
|
+
requestRenderingEvent: message.details as RequestRenderingEvent
|
|
57
|
+
};
|
|
58
|
+
EventBus.Instance.event(UnitMessage.UNIT_REQUEST_RENDERING, event);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case PageMessage.PAGE_HEIGHT:
|
|
62
|
+
setHeight((message.details as HeightEvent).height);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<View style={{ height }}>
|
|
69
|
+
<WebComponent
|
|
70
|
+
ref={webRef}
|
|
71
|
+
type={WebComponentType.account}
|
|
72
|
+
presentationMode={PresentationMode.Default}
|
|
73
|
+
params={getAccountParams(props)}
|
|
74
|
+
script={getAccountScript()}
|
|
75
|
+
theme={props.theme}
|
|
76
|
+
onMessage={message => handleMessage(message)}
|
|
77
|
+
width={windowWidth}
|
|
78
|
+
isScrollable={false}
|
|
79
|
+
/>
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AccountAction, UNAccountComponentProps } from './UNAccountComponent';
|
|
2
|
+
import { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
3
|
+
import type WebView from 'react-native-webview';
|
|
4
|
+
import { WebComponentType } from '../../webComponent/WebComponent';
|
|
5
|
+
|
|
6
|
+
export const getAccountParams = (props: UNAccountComponentProps) => {
|
|
7
|
+
return `
|
|
8
|
+
account-id="${props.accountId}"
|
|
9
|
+
customer-token="${props.customerToken}"
|
|
10
|
+
`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getAccountScript = () => {
|
|
14
|
+
return `
|
|
15
|
+
const dispatchRefreshEvent = (details) => {
|
|
16
|
+
const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_REFRESH}",{ detail: JSON.parse(details) })
|
|
17
|
+
window.dispatchEvent(event)
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null) => {
|
|
23
|
+
if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.account.valueOf())) {
|
|
24
|
+
currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getAccountActionType = (requestRendering: RequestRenderingEvent) => {
|
|
29
|
+
return requestRendering.data.nativeComponent.includes(AccountAction.List) ? AccountAction.List : AccountAction.Menu;
|
|
30
|
+
};
|
|
@@ -1,36 +1,59 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
2
|
import { Dimensions, View } from 'react-native';
|
|
3
|
+
import { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
4
|
+
import { useListenerToBus } from '../../hooks/listenerToBus';
|
|
3
5
|
import type { WebViewMessage } from '../../messages/webMessages';
|
|
4
6
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
5
7
|
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
8
|
+
import type { ResponseUnitOnLoadEvent } from '../../sharedTypes';
|
|
6
9
|
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
7
|
-
import { getActivityParams } from './UNActivityComponent.utils';
|
|
10
|
+
import { getActivityParams, getActivityScript, injectRefreshEventIfNeeded } from './UNActivityComponent.utils';
|
|
11
|
+
import type WebView from 'react-native-webview';
|
|
8
12
|
|
|
9
13
|
const DEFAULT_HEIGHT = Dimensions.get('window').height * 0.5;
|
|
10
14
|
export interface UNActivityComponentProps {
|
|
11
15
|
accountId: string;
|
|
12
16
|
customerToken: string;
|
|
13
17
|
theme?: string;
|
|
18
|
+
onLoad?: (response: ResponseUnitOnLoadEvent) => void
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export const UNActivityComponent = (props: UNActivityComponentProps) => {
|
|
22
|
+
const webRef = useRef<WebView>(null);
|
|
17
23
|
const [defaultHeight, setDefaultHeight] = useState<number>();
|
|
24
|
+
|
|
25
|
+
const requestRefresh = (data: RequestRefreshEvent) => {
|
|
26
|
+
injectRefreshEventIfNeeded(webRef.current, data);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
useListenerToBus([
|
|
30
|
+
{ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },
|
|
31
|
+
]);
|
|
32
|
+
|
|
18
33
|
const handleWebViewMessage = (message: WebViewMessage) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
switch (message.type) {
|
|
35
|
+
case UnitMessage.UNIT_ON_LOAD:
|
|
36
|
+
props.onLoad && props.onLoad(message.details as ResponseUnitOnLoadEvent);
|
|
37
|
+
break;
|
|
38
|
+
case PageMessage.PAGE_HEIGHT: {
|
|
39
|
+
const currentHeight = (message.details as HeightEvent).height;
|
|
40
|
+
currentHeight === 0 && setDefaultHeight(DEFAULT_HEIGHT);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
22
43
|
}
|
|
23
44
|
};
|
|
24
45
|
|
|
25
46
|
const renderActivityWebView = () => {
|
|
26
47
|
return (
|
|
27
48
|
<WebComponent
|
|
49
|
+
ref={webRef}
|
|
28
50
|
type={WebComponentType.activity}
|
|
29
51
|
presentationMode={PresentationMode.Inherit}
|
|
30
52
|
params={getActivityParams(props)}
|
|
31
53
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
32
54
|
nestedScrollEnabled={true}
|
|
33
55
|
theme={props.theme}
|
|
56
|
+
script={getActivityScript()}
|
|
34
57
|
/>
|
|
35
58
|
);
|
|
36
59
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { WebComponentType } from './../../webComponent/WebComponent';
|
|
2
|
+
import type { RequestRefreshEvent } from './../../messages/webMessages/unitMessages';
|
|
3
|
+
import type { WebView } from 'react-native-webview';
|
|
4
|
+
import { DISPATCH_REQUEST_REFRESH } from './../../scripts/html/bodyScript';
|
|
1
5
|
import type { UNActivityComponentProps } from './UNActivityComponent';
|
|
2
6
|
|
|
3
7
|
export const getActivityParams = (props: UNActivityComponentProps) => {
|
|
@@ -7,3 +11,13 @@ export const getActivityParams = (props: UNActivityComponentProps) => {
|
|
|
7
11
|
style="height: 100%"
|
|
8
12
|
`;
|
|
9
13
|
};
|
|
14
|
+
|
|
15
|
+
export const getActivityScript = () => {
|
|
16
|
+
return DISPATCH_REQUEST_REFRESH;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null) => {
|
|
20
|
+
if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.activity.valueOf())) {
|
|
21
|
+
currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -4,9 +4,10 @@ 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
|
-
import type { UNBookPaymentData } from '../../sharedTypes';
|
|
7
|
+
import type { ResponseUnitOnLoadEvent, UNBookPaymentData } from '../../sharedTypes';
|
|
8
8
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
9
9
|
import { View } from 'react-native';
|
|
10
|
+
import { UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
10
11
|
|
|
11
12
|
export interface UNBookPaymentComponentProps {
|
|
12
13
|
accountId: string;
|
|
@@ -16,6 +17,7 @@ export interface UNBookPaymentComponentProps {
|
|
|
16
17
|
counterPartyName: string;
|
|
17
18
|
theme?: string;
|
|
18
19
|
onPaymentCreated?: (data: UNBookPaymentData) => void;
|
|
20
|
+
onLoad?: (response: ResponseUnitOnLoadEvent) => void;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {
|
|
@@ -23,16 +25,22 @@ export const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {
|
|
|
23
25
|
const [presentationMode, setPresentationMode] = useState<PresentationMode>(PresentationMode.Inherit);
|
|
24
26
|
|
|
25
27
|
const handleWebViewMessage = (message: WebViewMessage) => {
|
|
26
|
-
if (message
|
|
27
|
-
const response = message.details as BookPaymentEvent;
|
|
28
|
-
props.onPaymentCreated(response.data);
|
|
29
|
-
}
|
|
28
|
+
if (!message || !message.details) return;
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
switch (message.type) {
|
|
31
|
+
case BookPaymentMessage.PAYMENT_CREATED:
|
|
32
|
+
props.onPaymentCreated && props.onPaymentCreated((message.details as BookPaymentEvent).data);
|
|
33
|
+
break;
|
|
34
|
+
case UnitMessage.UNIT_ON_LOAD:
|
|
35
|
+
props.onLoad && props.onLoad(message.details as ResponseUnitOnLoadEvent);
|
|
36
|
+
break;
|
|
37
|
+
case PageMessage.PAGE_HEIGHT: {
|
|
38
|
+
const currentHeight = (message.details as HeightEvent).height;
|
|
39
|
+
setHeight(currentHeight);
|
|
40
|
+
if (presentationMode === PresentationMode.Inherit && currentHeight === 0) {
|
|
41
|
+
setPresentationMode(PresentationMode.Default);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LISTENERS } from './../../scripts/html/bodyScript';
|
|
1
2
|
import type { UNBookPaymentComponentProps } from './UNBookPaymentComponent';
|
|
2
3
|
|
|
3
4
|
import { BookPaymentMessage } from '../../messages/webMessages/bookPaymentMessage';
|
|
@@ -23,5 +24,7 @@ export const getBookPaymentScript = () => {
|
|
|
23
24
|
console.log(e)
|
|
24
25
|
})
|
|
25
26
|
});
|
|
27
|
+
|
|
28
|
+
${LISTENERS.requestRefresh}
|
|
26
29
|
`;
|
|
27
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const BOTTOM_SHEET_MAX_PERCENTAGE_SIZE = 0.9;
|
|
@@ -6,7 +6,7 @@ import { Dimensions, Linking, View } from 'react-native';
|
|
|
6
6
|
import BottomSheet from '../../helpers/BottomSheet/BottomSheet';
|
|
7
7
|
import EventBus from '../../helpers/EventBus';
|
|
8
8
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
9
|
-
import { RequestOpenLinkEvent,
|
|
9
|
+
import { RequestOpenLinkEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
10
10
|
import { CardMessage, CardStatusChangedEvent } from '../../messages/webMessages/cardMessage';
|
|
11
11
|
import { useListenerToBus } from '../../hooks/listenerToBus';
|
|
12
12
|
import type { WebViewMessage } from '../../messages/webMessages';
|
|
@@ -14,54 +14,91 @@ import { getBottomSheetScript, handleHtmlFullHeight, renderingBottomSheetRequest
|
|
|
14
14
|
import { getStylesObject } from './UNBottomSheetComponent.styles';
|
|
15
15
|
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
16
16
|
import { useAppStateListener } from '../../hooks/useAppStateListener';
|
|
17
|
+
import { UNAddToWalletBottomSheetItem } from './components/UNAddToWalletBottomSheetItem';
|
|
18
|
+
import { getAccountActionType } from '../UNAccountComponent/UNAccountComponent.utils';
|
|
19
|
+
import { AccountAction } from '../UNAccountComponent/UNAccountComponent';
|
|
17
20
|
|
|
18
21
|
export enum ScrollState {
|
|
22
|
+
/*
|
|
23
|
+
Web View ScrollState -
|
|
24
|
+
- Initialization:
|
|
25
|
+
'onTop': for a scrollable webView.
|
|
26
|
+
(onTop means that the webview is onTop of the BottomSheet and we need to recognize the scroll direction).
|
|
27
|
+
Then, it recognize the scroll direction and update the scroll state as needed.
|
|
28
|
+
|
|
29
|
+
-'unScrollable': for an unscrollable webView
|
|
30
|
+
*/
|
|
19
31
|
onTop = 'onTop',
|
|
32
|
+
unScrollable = 'unScrollable',
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
These are only for maintain the bottom sheet scrollState (not an initialize scroll state).
|
|
36
|
+
It relates to the current scroll state.
|
|
37
|
+
onlyWebView means that now the scroll is on webview (only).
|
|
38
|
+
onlyBottomSheet means that now the scroll is on bottomSheet (only).
|
|
39
|
+
*/
|
|
20
40
|
onlyWebView = 'webViewScroll',
|
|
21
41
|
onlyBottomSheet = 'onlyBottomSheet',
|
|
22
|
-
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type BottomSheetSlotData = {
|
|
45
|
+
// The data that rendered by the web view
|
|
46
|
+
componentName?: WebComponentType,
|
|
47
|
+
componentResourceId?: string,
|
|
48
|
+
requestRenderingEvent: RequestRenderingEvent
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
enum CustomDialog {
|
|
52
|
+
addToWallet
|
|
23
53
|
}
|
|
24
54
|
|
|
25
55
|
export const UNBottomSheetComponent = () => {
|
|
26
56
|
const [isBottomSheetActive, setIsBottomSheetActive] = useState(false);
|
|
27
57
|
const [height, setHeight] = useState(0);
|
|
28
58
|
|
|
29
|
-
const [
|
|
59
|
+
const [bottomSheetSlotData, setBottomSheetSlotData] = useState<BottomSheetSlotData>();
|
|
60
|
+
const [requestRenderingEvent, setRequestRenderingEvent] = useState<RequestRenderingEvent>();
|
|
30
61
|
const [scrollState, setScrollState] = useState<ScrollState>(ScrollState.onTop);
|
|
31
62
|
|
|
32
63
|
const [waitForLoadingNewComponent, setWaitForLoadingNewComponent] = useState(false);
|
|
33
64
|
const [newHeightMessage, setNewHeightMessage] = useState<WebViewMessage | null>(null);
|
|
34
65
|
|
|
66
|
+
const [customDialog, setCustomDialog] = useState<CustomDialog | null>(null);
|
|
67
|
+
|
|
35
68
|
const isAppActive = useAppStateListener();
|
|
36
69
|
|
|
37
70
|
const styles = getStylesObject();
|
|
38
71
|
|
|
39
72
|
const webRef = useRef<WebView>(null);
|
|
40
73
|
|
|
41
|
-
const
|
|
42
|
-
|
|
74
|
+
const handleRequestRendering = (data: BottomSheetSlotData) => {
|
|
75
|
+
setBottomSheetSlotData(data);
|
|
43
76
|
setIsBottomSheetActive(true);
|
|
77
|
+
setRequestRenderingEvent(data.requestRenderingEvent);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleCloseFlow = () => {
|
|
81
|
+
setIsBottomSheetActive(false);
|
|
44
82
|
};
|
|
45
83
|
|
|
46
84
|
useEffect(() => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}, [isAppActive]);
|
|
85
|
+
setRequestRenderingEvent(bottomSheetSlotData?.requestRenderingEvent);
|
|
86
|
+
}, [bottomSheetSlotData]);
|
|
51
87
|
|
|
52
88
|
useEffect(() => {
|
|
53
89
|
if (!webRef.current) return;
|
|
54
|
-
if (
|
|
55
|
-
renderingBottomSheetRequest(webRef.current,
|
|
90
|
+
if (requestRenderingEvent) {
|
|
91
|
+
renderingBottomSheetRequest(webRef.current, requestRenderingEvent);
|
|
56
92
|
}
|
|
57
|
-
}, [webRef.current,
|
|
93
|
+
}, [webRef.current, requestRenderingEvent]);
|
|
58
94
|
|
|
59
95
|
useEffect(() => {
|
|
60
96
|
if (!isBottomSheetActive) {
|
|
61
97
|
webRef.current && resetHtml(webRef.current);
|
|
62
98
|
setHeight(0);
|
|
63
|
-
|
|
99
|
+
setRequestRenderingEvent(undefined);
|
|
64
100
|
setScrollState(ScrollState.onTop);
|
|
101
|
+
setCustomDialog(null);
|
|
65
102
|
}
|
|
66
103
|
}, [isBottomSheetActive]);
|
|
67
104
|
|
|
@@ -72,42 +109,71 @@ export const UNBottomSheetComponent = () => {
|
|
|
72
109
|
}
|
|
73
110
|
}, [waitForLoadingNewComponent, newHeightMessage]);
|
|
74
111
|
|
|
75
|
-
useListenerToBus([
|
|
112
|
+
useListenerToBus([
|
|
113
|
+
{ busEventKey: UnitMessage.UNIT_REQUEST_RENDERING, action: handleRequestRendering },
|
|
114
|
+
{ busEventKey: UnitMessage.UNIT_REQUEST_CLOSE_FLOW, action: handleCloseFlow }
|
|
115
|
+
]);
|
|
76
116
|
|
|
77
117
|
const setNewHeight = (message: WebViewMessage) => {
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
118
|
+
if (!requestRenderingEvent) return;
|
|
119
|
+
switch (bottomSheetSlotData?.componentName) {
|
|
120
|
+
case WebComponentType.account: {
|
|
121
|
+
const accountActionType = getAccountActionType(requestRenderingEvent);
|
|
122
|
+
setScrollState(
|
|
123
|
+
accountActionType === AccountAction.List ? ScrollState.onTop : ScrollState.unScrollable
|
|
124
|
+
);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case WebComponentType.card: {
|
|
128
|
+
if (customDialog === CustomDialog.addToWallet) {
|
|
129
|
+
setScrollState(ScrollState.unScrollable);
|
|
130
|
+
} else {
|
|
131
|
+
setScrollState(ScrollState.onTop);
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
default: {
|
|
136
|
+
const nativePlace = requestRenderingEvent?.data.nativePlace;
|
|
137
|
+
if (nativePlace == 'overFullScreen') {
|
|
138
|
+
setScrollState(ScrollState.onTop);
|
|
139
|
+
} else {
|
|
140
|
+
setScrollState(ScrollState.unScrollable);
|
|
141
|
+
}
|
|
87
142
|
}
|
|
88
143
|
}
|
|
144
|
+
const nativePlace = requestRenderingEvent?.data.nativePlace;
|
|
145
|
+
if (nativePlace == 'overFullScreen') {
|
|
146
|
+
const bottomSheetNewHeight = handleHtmlFullHeight(webRef.current, Dimensions.get('window').height);
|
|
147
|
+
setHeight(bottomSheetNewHeight);
|
|
148
|
+
} else {
|
|
149
|
+
setHeight((message.details as HeightEvent).height);
|
|
150
|
+
}
|
|
89
151
|
};
|
|
90
152
|
|
|
91
153
|
const onWebMessage = (message: WebViewMessage) => {
|
|
92
154
|
switch (message.type) {
|
|
93
155
|
case PageMessage.PAGE_HEIGHT:
|
|
94
|
-
|
|
156
|
+
requestRenderingEvent && setNewHeightMessage(message);
|
|
95
157
|
break;
|
|
96
|
-
case UnitMessage.UNIT_REQUEST_RENDERING:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
case UnitMessage.UNIT_REQUEST_RENDERING: {
|
|
159
|
+
const requestRendering = (message.details as RequestRenderingEvent);
|
|
160
|
+
if (requestRendering.data.nativeComponent != requestRenderingEvent?.data?.nativeComponent) {
|
|
161
|
+
if (requestRendering.data.nativeComponent.includes('action=AddToWallet')) {
|
|
162
|
+
setCustomDialog(CustomDialog.addToWallet);
|
|
163
|
+
}
|
|
164
|
+
|
|
100
165
|
setHeight(0);
|
|
101
|
-
|
|
166
|
+
setRequestRenderingEvent(requestRendering);
|
|
102
167
|
setWaitForLoadingNewComponent(true);
|
|
103
168
|
setTimeout(() => setWaitForLoadingNewComponent(false), 400);
|
|
104
169
|
}
|
|
105
170
|
break;
|
|
171
|
+
}
|
|
106
172
|
case CardMessage.CARD_STATUS_CHANGED:
|
|
107
173
|
EventBus.Instance.event(CardMessage.CARD_STATUS_CHANGED, (message.details as CardStatusChangedEvent).card);
|
|
108
174
|
break;
|
|
109
175
|
case UnitMessage.UNIT_REQUEST_CLOSE_FLOW:
|
|
110
|
-
|
|
176
|
+
handleCloseFlow();
|
|
111
177
|
break;
|
|
112
178
|
case UnitMessage.UNIT_REQUEST_OPEN_LINK:
|
|
113
179
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -126,7 +192,7 @@ export const UNBottomSheetComponent = () => {
|
|
|
126
192
|
setScrollState(ScrollState.onlyBottomSheet);
|
|
127
193
|
}
|
|
128
194
|
|
|
129
|
-
if (
|
|
195
|
+
if (scrollState !== ScrollState.onlyWebView && scrollState === ScrollState.onTop && currY > 5) {
|
|
130
196
|
setScrollState(ScrollState.onlyWebView);
|
|
131
197
|
}
|
|
132
198
|
};
|
|
@@ -136,6 +202,25 @@ export const UNBottomSheetComponent = () => {
|
|
|
136
202
|
setScrollState(ScrollState.onlyWebView);
|
|
137
203
|
};
|
|
138
204
|
|
|
205
|
+
const renderBottomSheetItem = () => {
|
|
206
|
+
switch (customDialog) {
|
|
207
|
+
case CustomDialog.addToWallet:
|
|
208
|
+
return <UNAddToWalletBottomSheetItem renderingRequest={requestRenderingEvent} cardId={bottomSheetSlotData?.componentResourceId} />;
|
|
209
|
+
default:
|
|
210
|
+
return (
|
|
211
|
+
<WebComponent
|
|
212
|
+
ref={webRef}
|
|
213
|
+
type={WebComponentType.slot}
|
|
214
|
+
presentationMode={PresentationMode.CoverInjectedHeight}
|
|
215
|
+
script={getBottomSheetScript()}
|
|
216
|
+
onMessage={onWebMessage}
|
|
217
|
+
isScrollable={scrollState === ScrollState.onlyWebView || scrollState === ScrollState.onTop}
|
|
218
|
+
handleScroll={onScrollWebView}
|
|
219
|
+
/>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
139
224
|
return (
|
|
140
225
|
<>
|
|
141
226
|
<View
|
|
@@ -147,21 +232,12 @@ export const UNBottomSheetComponent = () => {
|
|
|
147
232
|
height={height}
|
|
148
233
|
onClose={() => setIsBottomSheetActive(false)}
|
|
149
234
|
onOpen={() => setIsBottomSheetActive(true)}
|
|
150
|
-
handleWebViewScroll={() =>
|
|
235
|
+
handleWebViewScroll={() => handleWebViewScroll()}
|
|
151
236
|
shouldEnableBottomSheetScroll={scrollState !== ScrollState.onlyWebView}
|
|
152
237
|
>
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
type={WebComponentType.slot}
|
|
157
|
-
presentationMode={PresentationMode.CoverInjectedHeight}
|
|
158
|
-
script={getBottomSheetScript()}
|
|
159
|
-
onMessage={onWebMessage}
|
|
160
|
-
isScrollable={scrollState === ScrollState.onlyWebView || scrollState === ScrollState.onTop}
|
|
161
|
-
handleScroll={onScrollWebView}
|
|
162
|
-
/>)}
|
|
163
|
-
</BottomSheet>
|
|
164
|
-
</View>
|
|
238
|
+
{isAppActive && renderBottomSheetItem()}
|
|
239
|
+
</BottomSheet >
|
|
240
|
+
</View >
|
|
165
241
|
</>
|
|
166
242
|
);
|
|
167
243
|
};
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
+
import { LISTENERS } from './../../scripts/html/bodyScript';
|
|
1
2
|
import type WebView from 'react-native-webview';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { BOTTOM_SHEET_MAX_PERCENTAGE_SIZE } from './UNBottomSheetComponent.constants';
|
|
4
|
+
import type { RequestRenderingEvent } from '../../messages/webMessages/unitMessages';
|
|
4
5
|
|
|
5
6
|
export const getBottomSheetScript = () => {
|
|
6
|
-
return
|
|
7
|
-
window.addEventListener("${UnitMessage.UNIT_REQUEST_REFRESH}", (e) => {
|
|
8
|
-
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_REFRESH}", details: e.detail })
|
|
9
|
-
});
|
|
10
|
-
`;
|
|
7
|
+
return LISTENERS.requestRefresh;
|
|
11
8
|
};
|
|
12
9
|
|
|
13
|
-
export const renderingBottomSheetRequest = (currentWebView: WebView, renderingRequest:
|
|
10
|
+
export const renderingBottomSheetRequest = (currentWebView: WebView, renderingRequest: RequestRenderingEvent) => {
|
|
14
11
|
currentWebView?.injectJavaScript(`
|
|
15
12
|
document.activeElement && document.activeElement.blur();
|
|
16
|
-
dispatchRenderingEvent('${renderingRequest}');
|
|
13
|
+
dispatchRenderingEvent('${JSON.stringify(renderingRequest.data)}');
|
|
17
14
|
`);
|
|
18
15
|
};
|
|
19
16
|
|
|
@@ -25,7 +22,7 @@ export const resetHtml = (currentWebView: WebView) => {
|
|
|
25
22
|
};
|
|
26
23
|
|
|
27
24
|
export const handleHtmlFullHeight = (currentWebView: WebView | null, windowHeight: number) => {
|
|
28
|
-
const bottomSheetHeight = windowHeight *
|
|
25
|
+
const bottomSheetHeight = windowHeight * BOTTOM_SHEET_MAX_PERCENTAGE_SIZE;
|
|
29
26
|
currentWebView && currentWebView?.injectJavaScript(`
|
|
30
27
|
document.getElementById('webViewContainer').style.height = '${bottomSheetHeight}px';
|
|
31
28
|
`);
|
package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StyleSheet, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export const getStylesObject = () => {
|
|
4
|
+
return StyleSheet.create({
|
|
5
|
+
addToWalletButton: {
|
|
6
|
+
position: 'absolute',
|
|
7
|
+
height: Platform.OS === 'ios' ? 48 : 55,
|
|
8
|
+
bottom: 32,
|
|
9
|
+
left: 0,
|
|
10
|
+
right: 0,
|
|
11
|
+
marginHorizontal: 24
|
|
12
|
+
},
|
|
13
|
+
loader: {
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
top: 0,
|
|
16
|
+
bottom: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
right: 0,
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type WebView from 'react-native-webview';
|
|
3
|
+
import { CardAddToWalletStatus, CardAddToWalletStatusEvent, CardGetAddToWalletStatusEvent, CardNativeMessage, CardStartPushProvisioningEvent } from '../../../messages/nativeMessages/cardMessage';
|
|
4
|
+
import EventBus from '../../../helpers/EventBus';
|
|
5
|
+
import { PresentationMode } from '../../../scripts/html/bodyHtml';
|
|
6
|
+
import { WebComponent, WebComponentType } from '../../../webComponent/WebComponent';
|
|
7
|
+
import { renderingBottomSheetRequest } from '../UNBottomSheetComponent.utils';
|
|
8
|
+
import { getStylesObject } from './UNAddToWalletBottomSheetItem.styles';
|
|
9
|
+
import { ActivityIndicator } from 'react-native';
|
|
10
|
+
import { useListenerToBus } from '../../../hooks/listenerToBus';
|
|
11
|
+
import type { RequestRenderingEvent } from '../../../messages/webMessages/unitMessages';
|
|
12
|
+
import UnitAddToWalletButtonView from '../../../nativeComponent/UnitAddToWalletButton';
|
|
13
|
+
|
|
14
|
+
export interface UNAddToWalletBottomSheetItemProps {
|
|
15
|
+
renderingRequest?: RequestRenderingEvent
|
|
16
|
+
cardId?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const UNAddToWalletBottomSheetItem = (props: UNAddToWalletBottomSheetItemProps) => {
|
|
20
|
+
const styles = getStylesObject();
|
|
21
|
+
|
|
22
|
+
const webRef = useRef<WebView>(null);
|
|
23
|
+
|
|
24
|
+
const { renderingRequest, cardId } = props;
|
|
25
|
+
|
|
26
|
+
const [addToWalletStatus, setAddToWalletStatus] = useState<CardAddToWalletStatus>(CardAddToWalletStatus.pending);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!cardId) return;
|
|
30
|
+
const event: CardGetAddToWalletStatusEvent = { cardId };
|
|
31
|
+
EventBus.Instance.event(CardNativeMessage.CARD_GET_ADD_TO_WALLET_STATUS, event);
|
|
32
|
+
}, [cardId]);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!webRef.current) return;
|
|
36
|
+
if (addToWalletStatus === CardAddToWalletStatus.pending) return;
|
|
37
|
+
|
|
38
|
+
const isCardInWallet = addToWalletStatus === CardAddToWalletStatus.addedToWallet;
|
|
39
|
+
webRef.current.injectJavaScript(`window.UnitMobileSDKConfig["isCardInWallet"] = ${isCardInWallet}`);
|
|
40
|
+
|
|
41
|
+
if (renderingRequest) {
|
|
42
|
+
renderingBottomSheetRequest(webRef.current, renderingRequest);
|
|
43
|
+
}
|
|
44
|
+
}, [webRef.current, renderingRequest, addToWalletStatus]);
|
|
45
|
+
|
|
46
|
+
const gotCardWalletStatus = (data?: CardAddToWalletStatusEvent) => {
|
|
47
|
+
if (data != null) {
|
|
48
|
+
setAddToWalletStatus(data.status);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
useListenerToBus([
|
|
53
|
+
{ busEventKey: CardNativeMessage.CARD_UPDATE_ADD_TO_WALLET_STATUS, action: gotCardWalletStatus },
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const handleAddToWalletClicked = () => {
|
|
57
|
+
if (!cardId) return;
|
|
58
|
+
const startPushProvisioningEvent: CardStartPushProvisioningEvent = { cardId };
|
|
59
|
+
EventBus.Instance.event(CardNativeMessage.CARD_START_PUSH_PROVISIONING, startPushProvisioningEvent);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<WebComponent
|
|
65
|
+
ref={webRef}
|
|
66
|
+
type={WebComponentType.slot}
|
|
67
|
+
presentationMode={PresentationMode.CoverInjectedHeight}
|
|
68
|
+
isScrollable={false}
|
|
69
|
+
/>
|
|
70
|
+
{addToWalletStatus === CardAddToWalletStatus.pending && <ActivityIndicator style={styles.loader} />}
|
|
71
|
+
{addToWalletStatus === CardAddToWalletStatus.readyToProvisioning && <UnitAddToWalletButtonView style={styles.addToWalletButton} onAddToWalletClicked={handleAddToWalletClicked} />}
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|