react-native-unit-components 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -2
- package/lib/commonjs/assets/images/close.png +0 -0
- package/lib/commonjs/assets/images/index.js +16 -0
- package/lib/commonjs/assets/images/index.js.map +1 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +28 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +20 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +39 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +40 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +9 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -0
- package/lib/commonjs/components/{BottomSheet/BottomSheetComponent.js → UNBottomSheetComponent/UNBottomSheetComponent.js} +84 -65
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.js +23 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.js.map +1 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +49 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -0
- package/lib/commonjs/components/{Card/CardComponent.js → UNCardComponent/UNCardComponent.js} +42 -46
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +42 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -0
- package/lib/commonjs/components/index.js +34 -8
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/custom.d.js +2 -0
- package/lib/commonjs/custom.d.js.map +1 -0
- package/lib/commonjs/helpers/{BottomSheet.js → BottomSheet/BottomSheet.js} +36 -82
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.js.map +1 -0
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js +82 -0
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js.map +1 -0
- package/lib/commonjs/helpers/EventBus.js +5 -13
- package/lib/commonjs/helpers/EventBus.js.map +1 -1
- package/lib/commonjs/hooks/listenerToBus.js +31 -0
- package/lib/commonjs/hooks/listenerToBus.js.map +1 -0
- package/lib/commonjs/hooks/useAppStateListener.js +34 -0
- package/lib/commonjs/hooks/useAppStateListener.js.map +1 -0
- package/lib/commonjs/index.js +33 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/messages/nativeMessages/index.js +13 -0
- package/lib/commonjs/messages/nativeMessages/index.js.map +1 -0
- package/lib/commonjs/messages/webMessages/bookPaymentMessage.js +13 -0
- package/lib/commonjs/messages/webMessages/bookPaymentMessage.js.map +1 -0
- package/lib/commonjs/{webComponent → messages}/webMessages/cardMessage.js +1 -1
- package/lib/commonjs/messages/webMessages/cardMessage.js.map +1 -0
- package/lib/commonjs/messages/webMessages/index.js +6 -0
- package/lib/commonjs/messages/webMessages/index.js.map +1 -0
- package/lib/commonjs/{webComponent → messages}/webMessages/pageMessage.js +0 -0
- package/lib/commonjs/{webComponent → messages}/webMessages/pageMessage.js.map +0 -0
- package/lib/commonjs/{webComponent → messages}/webMessages/unitMessages.js +0 -0
- package/lib/commonjs/messages/webMessages/unitMessages.js.map +1 -0
- package/lib/commonjs/nativeComponenet/NativeComponentExample.js +2 -2
- package/lib/commonjs/nativeComponenet/NativeComponentExample.js.map +1 -1
- package/lib/commonjs/scripts/html/bodyHtml.js +52 -0
- package/lib/commonjs/scripts/html/bodyHtml.js.map +1 -0
- package/lib/commonjs/scripts/html/bodyScript.js +78 -0
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -0
- package/lib/commonjs/sharedTypes/bookPayment.types.js +6 -0
- package/lib/commonjs/sharedTypes/bookPayment.types.js.map +1 -0
- package/lib/commonjs/sharedTypes/card.types.js +6 -0
- package/lib/commonjs/sharedTypes/card.types.js.map +1 -0
- package/lib/commonjs/sharedTypes/index.js +32 -0
- package/lib/commonjs/sharedTypes/index.js.map +1 -0
- package/lib/commonjs/sharedTypes/types.js +2 -0
- package/lib/commonjs/sharedTypes/types.js.map +1 -0
- package/lib/commonjs/styles/variables.js +17 -0
- package/lib/commonjs/styles/variables.js.map +1 -0
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js +54 -0
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js.map +1 -0
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js +51 -0
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -0
- package/lib/commonjs/webComponent/WebComponent.js +35 -15
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/commonjs/webComponent/html.js +22 -45
- package/lib/commonjs/webComponent/html.js.map +1 -1
- package/lib/module/assets/images/close.png +0 -0
- package/lib/module/assets/images/index.js +2 -0
- package/lib/module/assets/images/index.js.map +1 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js +13 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +10 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +23 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +26 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +2 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js +131 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.js +13 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +29 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.js +65 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +24 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -0
- package/lib/module/components/index.js +4 -2
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/custom.d.js +2 -0
- package/lib/module/custom.d.js.map +1 -0
- package/lib/module/helpers/{BottomSheet.js → BottomSheet/BottomSheet.js} +34 -81
- package/lib/module/helpers/BottomSheet/BottomSheet.js.map +1 -0
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js +70 -0
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js.map +1 -0
- package/lib/module/helpers/EventBus.js +4 -11
- package/lib/module/helpers/EventBus.js.map +1 -1
- package/lib/module/hooks/listenerToBus.js +18 -0
- package/lib/module/hooks/listenerToBus.js.map +1 -0
- package/lib/module/hooks/useAppStateListener.js +23 -0
- package/lib/module/hooks/useAppStateListener.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/messages/nativeMessages/index.js +6 -0
- package/lib/module/messages/nativeMessages/index.js.map +1 -0
- package/lib/module/messages/webMessages/bookPaymentMessage.js +6 -0
- package/lib/module/messages/webMessages/bookPaymentMessage.js.map +1 -0
- package/lib/module/messages/webMessages/cardMessage.js +6 -0
- package/lib/module/messages/webMessages/cardMessage.js.map +1 -0
- package/lib/module/messages/webMessages/index.js +2 -0
- package/lib/module/messages/webMessages/index.js.map +1 -0
- package/lib/module/{webComponent → messages}/webMessages/pageMessage.js +0 -0
- package/lib/module/{webComponent → messages}/webMessages/pageMessage.js.map +0 -0
- package/lib/module/{webComponent → messages}/webMessages/unitMessages.js +0 -0
- package/lib/module/messages/webMessages/unitMessages.js.map +1 -0
- package/lib/module/nativeComponenet/NativeComponentExample.js +2 -2
- package/lib/module/nativeComponenet/NativeComponentExample.js.map +1 -1
- package/lib/module/scripts/html/bodyHtml.js +42 -0
- package/lib/module/scripts/html/bodyHtml.js.map +1 -0
- package/lib/module/scripts/html/bodyScript.js +64 -0
- package/lib/module/scripts/html/bodyScript.js.map +1 -0
- package/lib/module/sharedTypes/bookPayment.types.js +2 -0
- package/lib/module/sharedTypes/bookPayment.types.js.map +1 -0
- package/lib/module/sharedTypes/card.types.js +2 -0
- package/lib/module/sharedTypes/card.types.js.map +1 -0
- package/lib/module/sharedTypes/index.js +3 -0
- package/lib/module/sharedTypes/index.js.map +1 -0
- package/lib/module/sharedTypes/types.js +2 -0
- package/lib/module/sharedTypes/types.js.map +1 -0
- package/lib/module/styles/variables.js +10 -0
- package/lib/module/styles/variables.js.map +1 -0
- package/lib/module/unitSdkManager/UnitSdk.api.js +37 -0
- package/lib/module/unitSdkManager/UnitSdk.api.js.map +1 -0
- package/lib/module/unitSdkManager/UnitSdkManager.js +38 -0
- package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -0
- package/lib/module/webComponent/WebComponent.js +34 -14
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/module/webComponent/html.js +18 -44
- package/lib/module/webComponent/html.js.map +1 -1
- package/lib/typescript/assets/images/index.d.ts +1 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +6 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.utils.d.ts +2 -0
- package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.d.ts +11 -0
- package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.d.ts +3 -0
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.d.ts +1 -0
- package/lib/typescript/components/{BottomSheet/BottomSheetComponent.d.ts → UNBottomSheetComponent/UNBottomSheetComponent.d.ts} +0 -0
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.d.ts +9 -0
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.d.ts +5 -0
- package/lib/typescript/components/{Card/CardComponent.d.ts → UNCardComponent/UNCardComponent.d.ts} +3 -1
- package/lib/typescript/components/UNCardComponent/UNCardComponent.utils.d.ts +6 -0
- package/lib/typescript/components/index.d.ts +4 -2
- package/lib/typescript/helpers/{BottomSheet.d.ts → BottomSheet/BottomSheet.d.ts} +1 -0
- package/lib/typescript/helpers/BottomSheet/BottomSheet.styles.d.ts +63 -0
- package/lib/typescript/helpers/EventBus.d.ts +5 -7
- package/lib/typescript/hooks/listenerToBus.d.ts +7 -0
- package/lib/typescript/hooks/useAppStateListener.d.ts +1 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/messages/nativeMessages/index.d.ts +3 -0
- package/lib/typescript/messages/webMessages/bookPaymentMessage.d.ts +8 -0
- package/lib/typescript/{webComponent → messages}/webMessages/cardMessage.d.ts +3 -2
- package/lib/typescript/messages/webMessages/index.d.ts +11 -0
- package/lib/typescript/{webComponent → messages}/webMessages/pageMessage.d.ts +0 -0
- package/lib/typescript/{webComponent → messages}/webMessages/unitMessages.d.ts +0 -0
- package/lib/typescript/scripts/html/bodyHtml.d.ts +7 -0
- package/lib/typescript/scripts/html/bodyScript.d.ts +11 -0
- package/lib/typescript/sharedTypes/bookPayment.types.d.ts +26 -0
- package/lib/typescript/sharedTypes/card.types.d.ts +56 -0
- package/lib/typescript/sharedTypes/index.d.ts +2 -0
- package/lib/typescript/sharedTypes/types.d.ts +27 -0
- package/lib/typescript/styles/variables.d.ts +9 -0
- package/lib/typescript/unitSdkManager/UnitSdk.api.d.ts +3 -0
- package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +15 -0
- package/lib/typescript/webComponent/WebComponent.d.ts +8 -11
- package/lib/typescript/webComponent/html.d.ts +6 -1
- package/package.json +9 -5
- package/{unit-react-native-components.podspec → react-native-unit-components.podspec} +1 -1
- package/src/assets/images/close.png +0 -0
- package/src/assets/images/index.ts +1 -0
- package/src/components/UNActivityComponent/UNActivityComponent.tsx +21 -0
- package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +11 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +37 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +29 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.ts +1 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.styles.ts +13 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.tsx +136 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.ts +34 -0
- package/src/components/UNCardComponent/UNCardComponent.tsx +73 -0
- package/src/components/UNCardComponent/UNCardComponent.utils.ts +28 -0
- package/src/components/index.ts +4 -2
- package/src/custom.d.ts +5 -0
- package/src/helpers/BottomSheet/BottomSheet.styles.ts +70 -0
- package/src/helpers/{BottomSheet.tsx → BottomSheet/BottomSheet.tsx} +72 -110
- package/src/helpers/EventBus.ts +13 -13
- package/src/hooks/listenerToBus.ts +23 -0
- package/src/hooks/useAppStateListener.ts +25 -0
- package/src/index.tsx +5 -1
- package/src/messages/nativeMessages/index.ts +3 -0
- package/src/messages/webMessages/bookPaymentMessage.ts +12 -0
- package/src/{webComponent → messages}/webMessages/cardMessage.ts +4 -2
- package/src/messages/webMessages/index.ts +21 -0
- package/src/{webComponent → messages}/webMessages/pageMessage.ts +0 -0
- package/src/{webComponent → messages}/webMessages/unitMessages.ts +1 -0
- package/src/nativeComponenet/NativeComponentExample.tsx +2 -2
- package/src/scripts/html/bodyHtml.ts +46 -0
- package/src/scripts/html/bodyScript.ts +67 -0
- package/src/sharedTypes/bookPayment.types.ts +27 -0
- package/src/sharedTypes/card.types.ts +59 -0
- package/src/sharedTypes/index.ts +2 -0
- package/src/sharedTypes/types.ts +35 -0
- package/src/styles/variables.ts +9 -0
- package/src/unitSdkManager/UnitSdk.api.ts +31 -0
- package/src/unitSdkManager/UnitSdkManager.ts +33 -0
- package/src/webComponent/WebComponent.tsx +43 -45
- package/src/webComponent/html.ts +22 -46
- package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js.map +0 -1
- package/lib/commonjs/components/Card/CardComponent.js.map +0 -1
- package/lib/commonjs/helpers/BottomSheet.js.map +0 -1
- package/lib/commonjs/webComponent/webMessages/cardMessage.js.map +0 -1
- package/lib/commonjs/webComponent/webMessages/unitMessages.js.map +0 -1
- package/lib/module/components/BottomSheet/BottomSheetComponent.js +0 -118
- package/lib/module/components/BottomSheet/BottomSheetComponent.js.map +0 -1
- package/lib/module/components/Card/CardComponent.js +0 -75
- package/lib/module/components/Card/CardComponent.js.map +0 -1
- package/lib/module/helpers/BottomSheet.js.map +0 -1
- package/lib/module/webComponent/webMessages/cardMessage.js +0 -6
- package/lib/module/webComponent/webMessages/cardMessage.js.map +0 -1
- package/lib/module/webComponent/webMessages/unitMessages.js.map +0 -1
- package/src/components/BottomSheet/BottomSheetComponent.tsx +0 -113
- package/src/components/Card/CardComponent.tsx +0 -75
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type WebView from 'react-native-webview';
|
|
3
|
+
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
4
|
+
import { Dimensions, Linking, View } from 'react-native';
|
|
5
|
+
import BottomSheet from '../../helpers/BottomSheet/BottomSheet';
|
|
6
|
+
import EventBus from '../../helpers/EventBus';
|
|
7
|
+
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
8
|
+
import { RequestOpenLinkEvent, RequestRenderingData, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
9
|
+
import { CardMessage, CardStatusChangedEvent } from '../../messages/webMessages/cardMessage';
|
|
10
|
+
import { useListenerToBus } from '../../hooks/listenerToBus';
|
|
11
|
+
import type { WebViewMessage } from '../../messages/webMessages';
|
|
12
|
+
import { getBottomSheetScript, handleHtmlFullHeight, renderingBottomSheetRequest, resetHtml } from './UNBottomSheetComponent.utils';
|
|
13
|
+
import { getStylesObject } from './UNBottomSheetComponent.styles';
|
|
14
|
+
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
15
|
+
import { useAppStateListener } from '../../hooks/useAppStateListener';
|
|
16
|
+
|
|
17
|
+
export const UNBottomSheetComponent = () => {
|
|
18
|
+
const [isBottomSheetActive, setIsBottomSheetActive] = useState(false);
|
|
19
|
+
const [height, setHeight] = useState(0);
|
|
20
|
+
|
|
21
|
+
const [renderingRequest, setRenderingRequest] = useState<string | null>(null);
|
|
22
|
+
const [shouldEnableWebViewScroll, setShouldEnableWebViewScroll] = useState(false);
|
|
23
|
+
|
|
24
|
+
const [waitForLoadingNewComponent, setWaitForLoadingNewComponent] = useState(false);
|
|
25
|
+
const [newHeightMessage, setNewHeightMessage] = useState<WebViewMessage | null>(null);
|
|
26
|
+
|
|
27
|
+
const isAppActive = useAppStateListener();
|
|
28
|
+
|
|
29
|
+
const styles = getStylesObject();
|
|
30
|
+
|
|
31
|
+
const webRef = useRef<WebView>(null);
|
|
32
|
+
|
|
33
|
+
const listenerAction = (data: string) => {
|
|
34
|
+
setRenderingRequest(data);
|
|
35
|
+
setIsBottomSheetActive(true);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!isAppActive) {
|
|
40
|
+
setIsBottomSheetActive(false);
|
|
41
|
+
}
|
|
42
|
+
}, [isAppActive]);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!webRef.current) return;
|
|
46
|
+
if (renderingRequest) {
|
|
47
|
+
renderingBottomSheetRequest(webRef.current, renderingRequest);
|
|
48
|
+
}
|
|
49
|
+
}, [webRef.current, renderingRequest]);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!isBottomSheetActive) {
|
|
53
|
+
webRef.current && resetHtml(webRef.current);
|
|
54
|
+
setHeight(0);
|
|
55
|
+
setRenderingRequest(null);
|
|
56
|
+
}
|
|
57
|
+
}, [isBottomSheetActive]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!waitForLoadingNewComponent && newHeightMessage) {
|
|
61
|
+
setWaitForLoadingNewComponent(false);
|
|
62
|
+
setNewHeight(newHeightMessage);
|
|
63
|
+
}
|
|
64
|
+
}, [waitForLoadingNewComponent, newHeightMessage]);
|
|
65
|
+
|
|
66
|
+
useListenerToBus([{ busEventKey: UnitMessage.UNIT_REQUEST_RENDERING, action: listenerAction }]);
|
|
67
|
+
|
|
68
|
+
const setNewHeight = (message: WebViewMessage) => {
|
|
69
|
+
if (renderingRequest) {
|
|
70
|
+
const nativePlace = (JSON.parse(renderingRequest) as RequestRenderingData).nativePlace;
|
|
71
|
+
if (nativePlace == 'overFullScreen') {
|
|
72
|
+
const bottomSheetNewHeight = handleHtmlFullHeight(webRef.current, Dimensions.get('window').height);
|
|
73
|
+
setHeight(bottomSheetNewHeight);
|
|
74
|
+
setShouldEnableWebViewScroll(true);
|
|
75
|
+
} else {
|
|
76
|
+
setHeight((message.details as HeightEvent).height);
|
|
77
|
+
setShouldEnableWebViewScroll(false);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const onWebMessage = (message: WebViewMessage) => {
|
|
83
|
+
switch (message.type) {
|
|
84
|
+
case PageMessage.PAGE_HEIGHT:
|
|
85
|
+
renderingRequest && setNewHeightMessage(message);
|
|
86
|
+
break;
|
|
87
|
+
case UnitMessage.UNIT_REQUEST_RENDERING:
|
|
88
|
+
// eslint-disable-next-line no-case-declarations
|
|
89
|
+
const { data } = (message.details as RequestRenderingEvent);
|
|
90
|
+
if (data != renderingRequest) {
|
|
91
|
+
setHeight(0);
|
|
92
|
+
setRenderingRequest(data);
|
|
93
|
+
setWaitForLoadingNewComponent(true);
|
|
94
|
+
setTimeout(() => setWaitForLoadingNewComponent(false), 400);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case CardMessage.CARD_STATUS_CHANGED:
|
|
98
|
+
EventBus.Instance.event(CardMessage.CARD_STATUS_CHANGED, (message.details as CardStatusChangedEvent).card);
|
|
99
|
+
break;
|
|
100
|
+
case UnitMessage.UNIT_REQUEST_CLOSE_FLOW:
|
|
101
|
+
setIsBottomSheetActive(false);
|
|
102
|
+
break;
|
|
103
|
+
case UnitMessage.UNIT_REQUEST_OPEN_LINK:
|
|
104
|
+
// eslint-disable-next-line no-case-declarations
|
|
105
|
+
const { href } = (message.details as RequestOpenLinkEvent);
|
|
106
|
+
Linking.openURL(href);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<View
|
|
114
|
+
pointerEvents={isBottomSheetActive ? undefined : 'none'}
|
|
115
|
+
style={styles.container}
|
|
116
|
+
>
|
|
117
|
+
<BottomSheet
|
|
118
|
+
isOpen={isBottomSheetActive}
|
|
119
|
+
height={height}
|
|
120
|
+
onClose={() => setIsBottomSheetActive(false)}
|
|
121
|
+
onOpen={() => setIsBottomSheetActive(true)}
|
|
122
|
+
>
|
|
123
|
+
{ isAppActive && (
|
|
124
|
+
<WebComponent
|
|
125
|
+
ref={webRef}
|
|
126
|
+
type={WebComponentType.slot}
|
|
127
|
+
presentationMode={PresentationMode.CoverInjectedHeight}
|
|
128
|
+
script={getBottomSheetScript()}
|
|
129
|
+
onMessage={onWebMessage}
|
|
130
|
+
shouldEnableWebViewScroll={shouldEnableWebViewScroll}
|
|
131
|
+
/>)}
|
|
132
|
+
</BottomSheet>
|
|
133
|
+
</View>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type WebView from 'react-native-webview';
|
|
2
|
+
import { UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
3
|
+
import { BOTTOM_SHEET_MAX_PRECANTAGE_SIZE } from './UNBottomSheetComponent.constants';
|
|
4
|
+
|
|
5
|
+
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
|
+
`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const renderingBottomSheetRequest = (currentWebView: WebView, renderingRequest: string) => {
|
|
14
|
+
currentWebView?.injectJavaScript(`
|
|
15
|
+
document.activeElement && document.activeElement.blur();
|
|
16
|
+
dispatchRenderingEvent('${renderingRequest}');
|
|
17
|
+
`);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const resetHtml = (currentWebView: WebView) => {
|
|
21
|
+
currentWebView?.injectJavaScript(`
|
|
22
|
+
document.activeElement && document.activeElement.blur();
|
|
23
|
+
document.getElementById('webViewContainer').style.height = null;
|
|
24
|
+
`);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const handleHtmlFullHeight = (currentWebView: WebView | null, windowHeight: number) => {
|
|
28
|
+
const bottomSheetHeight = windowHeight * BOTTOM_SHEET_MAX_PRECANTAGE_SIZE;
|
|
29
|
+
currentWebView && currentWebView?.injectJavaScript(`
|
|
30
|
+
document.getElementById('webViewContainer').style.height = '${bottomSheetHeight}px';
|
|
31
|
+
`);
|
|
32
|
+
|
|
33
|
+
return bottomSheetHeight;
|
|
34
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { getCardParams, getCardScript, injectRefreshEventIfNeeded } from './UNCardComponent.utils';
|
|
11
|
+
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
12
|
+
import type { UNCardData } from '../../sharedTypes';
|
|
13
|
+
import { CardMessage } from '../../messages/webMessages/cardMessage';
|
|
14
|
+
|
|
15
|
+
export interface UNCardComponentProps {
|
|
16
|
+
cardId: string;
|
|
17
|
+
customerToken: string;
|
|
18
|
+
theme?: string;
|
|
19
|
+
onStatusChanged?: (card: UNCardData) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const UNCardComponent = (props: UNCardComponentProps) => {
|
|
23
|
+
const [height, setHeight] = useState(0);
|
|
24
|
+
const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);
|
|
25
|
+
const windowWidth = Dimensions.get('window').width;
|
|
26
|
+
|
|
27
|
+
const webRef = useRef<WebView>(null);
|
|
28
|
+
|
|
29
|
+
const cardStatusChanged = (card: UNCardData) => {
|
|
30
|
+
if (props.onStatusChanged) {
|
|
31
|
+
props.onStatusChanged(card);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const requestRefresh = (data: RequestRefreshEvent) => {
|
|
36
|
+
setRequestRefreshEvent(data);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
useListenerToBus([
|
|
40
|
+
{ busEventKey: CardMessage.CARD_STATUS_CHANGED, action: cardStatusChanged },
|
|
41
|
+
{ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
injectRefreshEventIfNeeded(webRef.current, requestRefreshEvent, props.cardId);
|
|
46
|
+
}, [requestRefreshEvent]);
|
|
47
|
+
|
|
48
|
+
const handleMessage = (message: WebViewMessage) => {
|
|
49
|
+
switch (message.type) {
|
|
50
|
+
case UnitMessage.UNIT_REQUEST_RENDERING:
|
|
51
|
+
EventBus.Instance.event(UnitMessage.UNIT_REQUEST_RENDERING, (message.details as RequestRenderingEvent).data);
|
|
52
|
+
break;
|
|
53
|
+
case PageMessage.PAGE_HEIGHT:
|
|
54
|
+
setHeight((message.details as HeightEvent).height);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<View style={{ height }}>
|
|
61
|
+
<WebComponent
|
|
62
|
+
ref={webRef}
|
|
63
|
+
type={WebComponentType.card}
|
|
64
|
+
presentationMode={PresentationMode.Default}
|
|
65
|
+
params={getCardParams(props)}
|
|
66
|
+
script={getCardScript()}
|
|
67
|
+
onMessage={message => handleMessage(message)}
|
|
68
|
+
width={windowWidth}
|
|
69
|
+
shouldEnableWebViewScroll={false}
|
|
70
|
+
/>
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type WebView from 'react-native-webview';
|
|
2
|
+
import type { UNCardComponentProps } from './UNCardComponent';
|
|
3
|
+
import { WebComponentType } from '../../webComponent/WebComponent';
|
|
4
|
+
import { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
5
|
+
import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
|
|
6
|
+
|
|
7
|
+
export const getCardParams = (props: UNCardComponentProps) => {
|
|
8
|
+
return `
|
|
9
|
+
card-id="${props.cardId}"
|
|
10
|
+
customer-token="${props.customerToken}"
|
|
11
|
+
theme="${props.theme ?? UnitSDK.getTheme()}"
|
|
12
|
+
`;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getCardScript = () => {
|
|
16
|
+
return `
|
|
17
|
+
const dispatchRefreshEvent = (details) => {
|
|
18
|
+
const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_REFRESH}",{ detail: JSON.parse(details) })
|
|
19
|
+
window.dispatchEvent(event)
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => {
|
|
25
|
+
if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.card.valueOf()) && requestRefreshEvent.resourceId == cardId) {
|
|
26
|
+
currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
|
|
27
|
+
}
|
|
28
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './UNCardComponent/UNCardComponent';
|
|
2
|
+
export * from './UNBottomSheetComponent/UNBottomSheetComponent';
|
|
3
|
+
export * from './UNBookPaymentComponent/UNBookPaymentComponent';
|
|
4
|
+
export * from './UNActivityComponent/UNActivityComponent';
|
package/src/custom.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Dimensions, StyleSheet } from 'react-native';
|
|
2
|
+
import { BOTTOM_SHEET_MAX_PRECANTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
|
|
3
|
+
import { VARIABLES } from '../../styles/variables';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
export const getStylesObject = (fadeAnim: any) => {
|
|
7
|
+
return StyleSheet.create({
|
|
8
|
+
outsideContainer: {
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
top: 0,
|
|
11
|
+
bottom: 0,
|
|
12
|
+
right: 0,
|
|
13
|
+
left: 0
|
|
14
|
+
},
|
|
15
|
+
animation: {
|
|
16
|
+
backgroundColor: 'black',
|
|
17
|
+
flex: 1,
|
|
18
|
+
opacity: fadeAnim,
|
|
19
|
+
},
|
|
20
|
+
container: {
|
|
21
|
+
position: 'relative',
|
|
22
|
+
flex: 1,
|
|
23
|
+
marginTop: Dimensions.get('window').height * (1 - BOTTOM_SHEET_MAX_PRECANTAGE_SIZE),
|
|
24
|
+
shadowColor: VARIABLES.COLORS.BLACK,
|
|
25
|
+
shadowOffset: {
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 6,
|
|
28
|
+
},
|
|
29
|
+
shadowOpacity: 0.37,
|
|
30
|
+
shadowRadius: 7.49,
|
|
31
|
+
elevation: 12,
|
|
32
|
+
borderTopLeftRadius: 15,
|
|
33
|
+
borderTopRightRadius: 15,
|
|
34
|
+
backgroundColor: VARIABLES.COLORS.WHITE,
|
|
35
|
+
overflow: 'hidden'
|
|
36
|
+
},
|
|
37
|
+
lineContainer: {
|
|
38
|
+
borderTopLeftRadius: 30,
|
|
39
|
+
borderTopRightRadius: 30,
|
|
40
|
+
alignItems: 'center'
|
|
41
|
+
},
|
|
42
|
+
line: {
|
|
43
|
+
width: 35,
|
|
44
|
+
height: 4,
|
|
45
|
+
borderRadius: 2,
|
|
46
|
+
marginTop: 18,
|
|
47
|
+
backgroundColor: VARIABLES.COLORS.SILVER_FLAKE,
|
|
48
|
+
},
|
|
49
|
+
outerContent: {
|
|
50
|
+
flex: -1,
|
|
51
|
+
},
|
|
52
|
+
innerContent: {
|
|
53
|
+
flex: -1,
|
|
54
|
+
},
|
|
55
|
+
closeButton: {
|
|
56
|
+
position: 'absolute',
|
|
57
|
+
display: 'flex',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
justifyContent: 'center',
|
|
60
|
+
width: 36,
|
|
61
|
+
height: 36,
|
|
62
|
+
backgroundColor: VARIABLES.COLORS.WHITE,
|
|
63
|
+
borderRadius: 18,
|
|
64
|
+
padding: 7,
|
|
65
|
+
top: 12,
|
|
66
|
+
right: 12,
|
|
67
|
+
zIndex: 100
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
@@ -4,14 +4,17 @@ import {
|
|
|
4
4
|
BackHandler,
|
|
5
5
|
Dimensions,
|
|
6
6
|
Easing,
|
|
7
|
-
|
|
7
|
+
Image,
|
|
8
|
+
KeyboardAvoidingView,
|
|
8
9
|
LayoutChangeEvent,
|
|
9
10
|
PanResponder,
|
|
10
|
-
StyleSheet,
|
|
11
11
|
TouchableOpacity,
|
|
12
12
|
View,
|
|
13
13
|
} from 'react-native';
|
|
14
14
|
import PropTypes from 'prop-types';
|
|
15
|
+
import { CloseIcon } from '../../assets/images';
|
|
16
|
+
import { BOTTOM_SHEET_MAX_PRECANTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
|
|
17
|
+
import { getStylesObject } from './BottomSheet.styles';
|
|
15
18
|
|
|
16
19
|
export interface BottomSheetProps {
|
|
17
20
|
isOpen: boolean
|
|
@@ -19,6 +22,7 @@ export interface BottomSheetProps {
|
|
|
19
22
|
sliderMaxHeight: number
|
|
20
23
|
onOpen: () => void
|
|
21
24
|
onClose: () => void
|
|
25
|
+
height: number,
|
|
22
26
|
animationDuration: number,
|
|
23
27
|
expandToMaxHeightEnabled: boolean
|
|
24
28
|
}
|
|
@@ -26,62 +30,64 @@ export interface BottomSheetProps {
|
|
|
26
30
|
const BottomSheet = (props: BottomSheetProps) => {
|
|
27
31
|
const panelHeightValue = useRef(new Animated.Value(props.sliderMaxHeight)).current;
|
|
28
32
|
const fadeAnim = useRef(new Animated.Value(0)).current;
|
|
33
|
+
const styles = getStylesObject(fadeAnim);
|
|
34
|
+
const [isPanelOpened, setIsPanelOpened] = useState(props.isOpen);
|
|
35
|
+
const [contentHeight, setContentHeight] = useState<number | undefined>(undefined);
|
|
29
36
|
|
|
30
|
-
const [
|
|
31
|
-
const [contentHeight, setContentHeight] = useState<number | undefined>(undefined)
|
|
37
|
+
const [currentHeight, setCurrentHeight] = useState<number>(props.sliderMaxHeight);
|
|
32
38
|
|
|
33
|
-
const [
|
|
34
|
-
|
|
35
|
-
const [dy, setDy] = useState(0)
|
|
39
|
+
const [dy, setDy] = useState(0);
|
|
36
40
|
|
|
37
41
|
const _parentPanResponder = PanResponder.create({
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
onMoveShouldSetPanResponderCapture: (_,) => { //gestureState) => {
|
|
44
|
+
return false;
|
|
45
|
+
// return Math.abs(gestureState.dy) > 10
|
|
40
46
|
},
|
|
41
47
|
onPanResponderMove(_, gestureState) {
|
|
42
|
-
if (currentHeight + gestureState.dy < 0) return
|
|
43
|
-
if (!props.expandToMaxHeightEnabled && currentHeight + gestureState.dy < sliderMaxHeight - contentHeight
|
|
44
|
-
panelHeightValue.setValue(currentHeight + gestureState.dy)
|
|
45
|
-
setDy(gestureState.dy)
|
|
48
|
+
if (currentHeight + gestureState.dy < 0) return;
|
|
49
|
+
if (!props.expandToMaxHeightEnabled && contentHeight && currentHeight + gestureState.dy < sliderMaxHeight - contentHeight) return;
|
|
50
|
+
panelHeightValue.setValue(currentHeight + gestureState.dy);
|
|
51
|
+
setDy(gestureState.dy);
|
|
46
52
|
},
|
|
47
53
|
onPanResponderRelease: () => {
|
|
48
54
|
if (dy > 0) {
|
|
49
|
-
collapse()
|
|
55
|
+
collapse();
|
|
50
56
|
} else if (!props.expandToMaxHeightEnabled) {
|
|
51
|
-
setToContentHeight(contentHeight
|
|
57
|
+
contentHeight && setToContentHeight(contentHeight);
|
|
52
58
|
} else if (dy < 0) {
|
|
53
|
-
expand()
|
|
59
|
+
expand();
|
|
54
60
|
} else {
|
|
55
|
-
expand()
|
|
61
|
+
expand();
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
});
|
|
59
65
|
|
|
60
66
|
useEffect(() => {
|
|
61
67
|
if (props.isOpen && !isPanelOpened) {
|
|
62
|
-
fadeIn()
|
|
68
|
+
fadeIn();
|
|
63
69
|
} else if (isPanelOpened) {
|
|
64
|
-
setContentHeight(0)
|
|
65
|
-
_dismiss()
|
|
70
|
+
setContentHeight(0);
|
|
71
|
+
_dismiss();
|
|
66
72
|
}
|
|
67
|
-
}, [props.isOpen])
|
|
73
|
+
}, [props.isOpen]);
|
|
68
74
|
|
|
69
75
|
useEffect(() => {
|
|
70
76
|
BackHandler.addEventListener('hardwareBackPress', _onBackPress);
|
|
71
|
-
const id = panelHeightValue.addListener(e => setCurrentHeight(e.value))
|
|
77
|
+
const id = panelHeightValue.addListener(e => setCurrentHeight(e.value));
|
|
72
78
|
|
|
73
79
|
return (() => {
|
|
74
80
|
BackHandler.removeEventListener('hardwareBackPress', _onBackPress);
|
|
75
|
-
panelHeightValue.removeListener(id)
|
|
76
|
-
})
|
|
77
|
-
}, [])
|
|
81
|
+
panelHeightValue.removeListener(id);
|
|
82
|
+
});
|
|
83
|
+
}, []);
|
|
78
84
|
|
|
79
85
|
const fadeIn = () => {
|
|
80
86
|
Animated.timing(fadeAnim, {
|
|
81
87
|
toValue: 0.3,
|
|
82
88
|
duration: 500,
|
|
83
89
|
useNativeDriver: false
|
|
84
|
-
}).start(() => { setIsPanelOpened(true) });
|
|
90
|
+
}).start(() => { setIsPanelOpened(true); });
|
|
85
91
|
};
|
|
86
92
|
|
|
87
93
|
const fadeOut = () => {
|
|
@@ -90,8 +96,8 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
90
96
|
duration: 500,
|
|
91
97
|
useNativeDriver: false
|
|
92
98
|
}).start(() => {
|
|
93
|
-
setIsPanelOpened(false)
|
|
94
|
-
props.onClose()
|
|
99
|
+
setIsPanelOpened(false);
|
|
100
|
+
props.onClose();
|
|
95
101
|
});
|
|
96
102
|
};
|
|
97
103
|
|
|
@@ -99,17 +105,17 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
99
105
|
Animated.timing(panelHeightValue, {
|
|
100
106
|
duration: props.animationDuration,
|
|
101
107
|
easing: Easing.quad,
|
|
102
|
-
toValue: sliderMaxHeight - contentHeight
|
|
108
|
+
toValue: sliderMaxHeight - contentHeight,
|
|
103
109
|
useNativeDriver: false,
|
|
104
|
-
}).start()
|
|
105
|
-
}
|
|
110
|
+
}).start();
|
|
111
|
+
};
|
|
106
112
|
|
|
107
113
|
const expand = () => {
|
|
108
114
|
const { animationDuration } = props;
|
|
109
115
|
|
|
110
|
-
if (currentHeight > (sliderMaxHeight - contentHeight
|
|
111
|
-
setToContentHeight(contentHeight
|
|
112
|
-
return
|
|
116
|
+
if (contentHeight && currentHeight > (sliderMaxHeight - contentHeight)) {
|
|
117
|
+
setToContentHeight(contentHeight);
|
|
118
|
+
return;
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
Animated.timing(panelHeightValue, {
|
|
@@ -117,32 +123,16 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
117
123
|
easing: Easing.quad,
|
|
118
124
|
toValue: 0,
|
|
119
125
|
useNativeDriver: false,
|
|
120
|
-
}).start()
|
|
121
|
-
}
|
|
126
|
+
}).start();
|
|
127
|
+
};
|
|
122
128
|
|
|
123
129
|
const collapse = () => {
|
|
124
|
-
if (currentHeight > (sliderMaxHeight - contentHeight
|
|
125
|
-
_dismiss()
|
|
126
|
-
return
|
|
130
|
+
if (contentHeight && currentHeight > (sliderMaxHeight - contentHeight)) {
|
|
131
|
+
_dismiss();
|
|
132
|
+
return;
|
|
127
133
|
}
|
|
128
134
|
|
|
129
|
-
setToContentHeight(contentHeight
|
|
130
|
-
|
|
131
|
-
// Animated.timing(panelHeightValue, {
|
|
132
|
-
// duration: animationDuration,
|
|
133
|
-
// easing: Easing.quad,
|
|
134
|
-
// toValue: sliderMaxHeight - contentHeight!,
|
|
135
|
-
// useNativeDriver: false,
|
|
136
|
-
// }).start(() => {
|
|
137
|
-
// const isPanelOpenedNewValue = !isPanelOpened
|
|
138
|
-
// setIsPanelOpened(isPanelOpenedNewValue)
|
|
139
|
-
// if (isPanelOpenedNewValue) {
|
|
140
|
-
// // onOpen();
|
|
141
|
-
// } else {
|
|
142
|
-
// // onClose();
|
|
143
|
-
// Keyboard.dismiss();
|
|
144
|
-
// }
|
|
145
|
-
// });
|
|
135
|
+
contentHeight && setToContentHeight(contentHeight);
|
|
146
136
|
};
|
|
147
137
|
|
|
148
138
|
const _onBackPress = () => {
|
|
@@ -151,24 +141,24 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
151
141
|
};
|
|
152
142
|
|
|
153
143
|
const _setSize = (e: LayoutChangeEvent) => {
|
|
154
|
-
|
|
155
|
-
if (newContentHeight !== 0) newContentHeight += 42;
|
|
144
|
+
const newContentHeight = e.nativeEvent.layout.height;
|
|
156
145
|
|
|
157
|
-
setContentHeight(newContentHeight)
|
|
158
|
-
setToContentHeight(newContentHeight)
|
|
146
|
+
setContentHeight(newContentHeight);
|
|
147
|
+
setToContentHeight(newContentHeight);
|
|
159
148
|
};
|
|
160
149
|
|
|
161
150
|
const _dismiss = () => {
|
|
162
|
-
const { animationDuration } = props
|
|
151
|
+
const { animationDuration } = props;
|
|
163
152
|
Animated.timing(panelHeightValue, {
|
|
164
153
|
duration: animationDuration,
|
|
165
154
|
easing: Easing.quad,
|
|
166
155
|
toValue: sliderMaxHeight,
|
|
167
156
|
useNativeDriver: false,
|
|
168
157
|
}).start(() => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
null;
|
|
159
|
+
});
|
|
160
|
+
fadeOut();
|
|
161
|
+
};
|
|
172
162
|
|
|
173
163
|
const {
|
|
174
164
|
sliderMaxHeight,
|
|
@@ -178,11 +168,11 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
178
168
|
return (
|
|
179
169
|
<>
|
|
180
170
|
<TouchableOpacity
|
|
181
|
-
style={
|
|
171
|
+
style={styles.outsideContainer} activeOpacity={1}
|
|
182
172
|
onPress={_dismiss}
|
|
183
173
|
>
|
|
184
174
|
<Animated.View
|
|
185
|
-
style={
|
|
175
|
+
style={styles.animation}
|
|
186
176
|
>
|
|
187
177
|
</Animated.View>
|
|
188
178
|
</TouchableOpacity>
|
|
@@ -199,22 +189,31 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
199
189
|
<View
|
|
200
190
|
style={styles.outerContent}
|
|
201
191
|
>
|
|
202
|
-
<TouchableOpacity
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
192
|
+
<TouchableOpacity
|
|
193
|
+
activeOpacity={1}
|
|
194
|
+
style={styles.closeButton}
|
|
195
|
+
onPress={_dismiss}
|
|
196
|
+
>
|
|
197
|
+
<Image source={CloseIcon} />
|
|
206
198
|
</TouchableOpacity>
|
|
199
|
+
|
|
207
200
|
<View
|
|
208
201
|
onLayout={_setSize}
|
|
209
202
|
style={[styles.innerContent]}
|
|
210
203
|
>
|
|
211
|
-
|
|
204
|
+
<KeyboardAvoidingView
|
|
205
|
+
behavior="padding"
|
|
206
|
+
style={{ height: props.height }}
|
|
207
|
+
keyboardVerticalOffset={props.height * (1 - BOTTOM_SHEET_MAX_PRECANTAGE_SIZE)}
|
|
208
|
+
>
|
|
209
|
+
{children}
|
|
210
|
+
</KeyboardAvoidingView>
|
|
212
211
|
</View>
|
|
213
212
|
</View>
|
|
214
213
|
</Animated.View>
|
|
215
214
|
</>
|
|
216
215
|
);
|
|
217
|
-
}
|
|
216
|
+
};
|
|
218
217
|
|
|
219
218
|
BottomSheet.propTypes = {
|
|
220
219
|
children: PropTypes.oneOfType([PropTypes.node]),
|
|
@@ -230,48 +229,11 @@ BottomSheet.propTypes = {
|
|
|
230
229
|
BottomSheet.defaultProps = {
|
|
231
230
|
children: <View />,
|
|
232
231
|
isOpen: true,
|
|
233
|
-
sliderMaxHeight: Dimensions.get('window').height *
|
|
232
|
+
sliderMaxHeight: Dimensions.get('window').height * BOTTOM_SHEET_MAX_PRECANTAGE_SIZE,
|
|
234
233
|
animationDuration: 200,
|
|
235
234
|
onOpen: () => null,
|
|
236
235
|
onClose: () => null,
|
|
237
236
|
expandToMaxHeightEnabled: false
|
|
238
237
|
};
|
|
239
238
|
|
|
240
|
-
const styles = StyleSheet.create({
|
|
241
|
-
container: {
|
|
242
|
-
flex: 1,
|
|
243
|
-
marginTop: 60,
|
|
244
|
-
paddingHorizontal: 12,
|
|
245
|
-
shadowColor: '#000000',
|
|
246
|
-
shadowOffset: {
|
|
247
|
-
width: 0,
|
|
248
|
-
height: 6,
|
|
249
|
-
},
|
|
250
|
-
shadowOpacity: 0.37,
|
|
251
|
-
shadowRadius: 7.49,
|
|
252
|
-
elevation: 12,
|
|
253
|
-
borderTopLeftRadius: 15,
|
|
254
|
-
borderTopRightRadius: 15,
|
|
255
|
-
backgroundColor: '#ffffff',
|
|
256
|
-
},
|
|
257
|
-
lineContainer: {
|
|
258
|
-
borderTopLeftRadius: 30,
|
|
259
|
-
borderTopRightRadius: 30,
|
|
260
|
-
alignItems: 'center'
|
|
261
|
-
},
|
|
262
|
-
line: {
|
|
263
|
-
width: 35,
|
|
264
|
-
height: 4,
|
|
265
|
-
borderRadius: 2,
|
|
266
|
-
marginTop: 18,
|
|
267
|
-
backgroundColor: '#D5DDE0',
|
|
268
|
-
},
|
|
269
|
-
outerContent: {
|
|
270
|
-
flex: -1,
|
|
271
|
-
},
|
|
272
|
-
innerContent: {
|
|
273
|
-
flex: -1,
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
|
|
277
239
|
export default BottomSheet;
|