@aws-amplify/ui-react-native 0.0.0-in-app-messaging-20220826014803
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/.eslintrc.js +100 -0
- package/.lintstagedrc.js +6 -0
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +201 -0
- package/README.md +25 -0
- package/babel.config.js +3 -0
- package/dist/InAppMessaging/components/BannerMessage/BannerMessage.d.ts +3 -0
- package/dist/InAppMessaging/components/BannerMessage/BannerMessage.js +16 -0
- package/dist/InAppMessaging/components/BannerMessage/index.d.ts +2 -0
- package/dist/InAppMessaging/components/BannerMessage/index.js +1 -0
- package/dist/InAppMessaging/components/BannerMessage/styles.d.ts +7 -0
- package/dist/InAppMessaging/components/BannerMessage/styles.js +77 -0
- package/dist/InAppMessaging/components/BannerMessage/types.d.ts +12 -0
- package/dist/InAppMessaging/components/BannerMessage/types.js +1 -0
- package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.d.ts +3 -0
- package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.js +20 -0
- package/dist/InAppMessaging/components/CarouselMessage/CarouselMessageItem.d.ts +3 -0
- package/dist/InAppMessaging/components/CarouselMessage/CarouselMessageItem.js +18 -0
- package/dist/InAppMessaging/components/CarouselMessage/index.d.ts +2 -0
- package/dist/InAppMessaging/components/CarouselMessage/index.js +1 -0
- package/dist/InAppMessaging/components/CarouselMessage/styles.d.ts +5 -0
- package/dist/InAppMessaging/components/CarouselMessage/styles.js +98 -0
- package/dist/InAppMessaging/components/CarouselMessage/types.d.ts +18 -0
- package/dist/InAppMessaging/components/CarouselMessage/types.js +1 -0
- package/dist/InAppMessaging/components/FullScreenMessage/FullScreenMessage.d.ts +3 -0
- package/dist/InAppMessaging/components/FullScreenMessage/FullScreenMessage.js +18 -0
- package/dist/InAppMessaging/components/FullScreenMessage/index.d.ts +2 -0
- package/dist/InAppMessaging/components/FullScreenMessage/index.js +1 -0
- package/dist/InAppMessaging/components/FullScreenMessage/styles.d.ts +3 -0
- package/dist/InAppMessaging/components/FullScreenMessage/styles.js +86 -0
- package/dist/InAppMessaging/components/FullScreenMessage/types.d.ts +6 -0
- package/dist/InAppMessaging/components/FullScreenMessage/types.js +1 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.d.ts +10 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.js +29 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.d.ts +3 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.js +24 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/index.d.ts +2 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/index.js +1 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/types.d.ts +24 -0
- package/dist/InAppMessaging/components/InAppMessageDisplay/types.js +1 -0
- package/dist/InAppMessaging/components/MessageLayout/MessageLayout.d.ts +3 -0
- package/dist/InAppMessaging/components/MessageLayout/MessageLayout.js +34 -0
- package/dist/InAppMessaging/components/MessageLayout/index.d.ts +1 -0
- package/dist/InAppMessaging/components/MessageLayout/index.js +1 -0
- package/dist/InAppMessaging/components/MessageLayout/types.d.ts +7 -0
- package/dist/InAppMessaging/components/MessageLayout/types.js +1 -0
- package/dist/InAppMessaging/components/MessageWrapper/MessageWrapper.d.ts +3 -0
- package/dist/InAppMessaging/components/MessageWrapper/MessageWrapper.js +20 -0
- package/dist/InAppMessaging/components/MessageWrapper/index.d.ts +2 -0
- package/dist/InAppMessaging/components/MessageWrapper/index.js +1 -0
- package/dist/InAppMessaging/components/MessageWrapper/styles.d.ts +2 -0
- package/dist/InAppMessaging/components/MessageWrapper/styles.js +5 -0
- package/dist/InAppMessaging/components/MessageWrapper/types.d.ts +10 -0
- package/dist/InAppMessaging/components/MessageWrapper/types.js +1 -0
- package/dist/InAppMessaging/components/ModalMessage/ModalMessage.d.ts +3 -0
- package/dist/InAppMessaging/components/ModalMessage/ModalMessage.js +18 -0
- package/dist/InAppMessaging/components/ModalMessage/index.d.ts +2 -0
- package/dist/InAppMessaging/components/ModalMessage/index.js +1 -0
- package/dist/InAppMessaging/components/ModalMessage/styles.d.ts +4 -0
- package/dist/InAppMessaging/components/ModalMessage/styles.js +99 -0
- package/dist/InAppMessaging/components/ModalMessage/types.d.ts +6 -0
- package/dist/InAppMessaging/components/ModalMessage/types.js +1 -0
- package/dist/InAppMessaging/components/index.d.ts +6 -0
- package/dist/InAppMessaging/components/index.js +2 -0
- package/dist/InAppMessaging/components/withInAppMessaging/index.d.ts +1 -0
- package/dist/InAppMessaging/components/withInAppMessaging/index.js +1 -0
- package/dist/InAppMessaging/components/withInAppMessaging/withInAppMessaging.d.ts +5 -0
- package/dist/InAppMessaging/components/withInAppMessaging/withInAppMessaging.js +11 -0
- package/dist/InAppMessaging/constants.d.ts +31 -0
- package/dist/InAppMessaging/constants.js +43 -0
- package/dist/InAppMessaging/hooks/index.d.ts +2 -0
- package/dist/InAppMessaging/hooks/index.js +2 -0
- package/dist/InAppMessaging/hooks/useMessageImage/constants.d.ts +8 -0
- package/dist/InAppMessaging/hooks/useMessageImage/constants.js +18 -0
- package/dist/InAppMessaging/hooks/useMessageImage/index.d.ts +2 -0
- package/dist/InAppMessaging/hooks/useMessageImage/index.js +1 -0
- package/dist/InAppMessaging/hooks/useMessageImage/types.d.ts +15 -0
- package/dist/InAppMessaging/hooks/useMessageImage/types.js +6 -0
- package/dist/InAppMessaging/hooks/useMessageImage/useMessageImage.d.ts +10 -0
- package/dist/InAppMessaging/hooks/useMessageImage/useMessageImage.js +50 -0
- package/dist/InAppMessaging/hooks/useMessageImage/utils.d.ts +4 -0
- package/dist/InAppMessaging/hooks/useMessageImage/utils.js +56 -0
- package/dist/InAppMessaging/hooks/useMessageProps/index.d.ts +2 -0
- package/dist/InAppMessaging/hooks/useMessageProps/index.js +1 -0
- package/dist/InAppMessaging/hooks/useMessageProps/types.d.ts +109 -0
- package/dist/InAppMessaging/hooks/useMessageProps/types.js +1 -0
- package/dist/InAppMessaging/hooks/useMessageProps/useMessageProps.d.ts +12 -0
- package/dist/InAppMessaging/hooks/useMessageProps/useMessageProps.js +49 -0
- package/dist/InAppMessaging/hooks/useMessageProps/utils.d.ts +43 -0
- package/dist/InAppMessaging/hooks/useMessageProps/utils.js +192 -0
- package/dist/InAppMessaging/index.d.ts +2 -0
- package/dist/InAppMessaging/index.js +2 -0
- package/dist/__mocks__/react-native-safe-area-context.d.ts +3 -0
- package/dist/__mocks__/react-native-safe-area-context.js +4 -0
- package/dist/assets/close.png +0 -0
- package/dist/assets/index.d.ts +5 -0
- package/dist/assets/index.js +4 -0
- package/dist/assets/index.ts +7 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useDeviceOrientation/index.d.ts +1 -0
- package/dist/hooks/useDeviceOrientation/index.js +1 -0
- package/dist/hooks/useDeviceOrientation/useDeviceOrientation.d.ts +6 -0
- package/dist/hooks/useDeviceOrientation/useDeviceOrientation.js +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/primitives/Button/Button.d.ts +3 -0
- package/dist/primitives/Button/Button.js +8 -0
- package/dist/primitives/Button/index.d.ts +2 -0
- package/dist/primitives/Button/index.js +1 -0
- package/dist/primitives/Button/styles.d.ts +2 -0
- package/dist/primitives/Button/styles.js +4 -0
- package/dist/primitives/Button/types.d.ts +7 -0
- package/dist/primitives/Button/types.js +1 -0
- package/dist/primitives/Carousel/Carousel.d.ts +3 -0
- package/dist/primitives/Carousel/Carousel.js +58 -0
- package/dist/primitives/Carousel/CarouselPageIndicator.d.ts +3 -0
- package/dist/primitives/Carousel/CarouselPageIndicator.js +10 -0
- package/dist/primitives/Carousel/constants.d.ts +9 -0
- package/dist/primitives/Carousel/constants.js +18 -0
- package/dist/primitives/Carousel/index.d.ts +3 -0
- package/dist/primitives/Carousel/index.js +2 -0
- package/dist/primitives/Carousel/styles.d.ts +2 -0
- package/dist/primitives/Carousel/styles.js +11 -0
- package/dist/primitives/Carousel/types.d.ts +19 -0
- package/dist/primitives/Carousel/types.js +1 -0
- package/dist/primitives/IconButton/IconButton.d.ts +3 -0
- package/dist/primitives/IconButton/IconButton.js +9 -0
- package/dist/primitives/IconButton/index.d.ts +2 -0
- package/dist/primitives/IconButton/index.js +1 -0
- package/dist/primitives/IconButton/styles.d.ts +2 -0
- package/dist/primitives/IconButton/styles.js +9 -0
- package/dist/primitives/IconButton/types.d.ts +18 -0
- package/dist/primitives/IconButton/types.js +1 -0
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.js +3 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +4 -0
- package/jest.config.js +20 -0
- package/package.json +55 -0
- package/src/InAppMessaging/components/BannerMessage/BannerMessage.tsx +37 -0
- package/src/InAppMessaging/components/BannerMessage/__tests__/BannerMessage.spec.tsx +138 -0
- package/src/InAppMessaging/components/BannerMessage/__tests__/__snapshots__/BannerMessage.spec.tsx.snap +224 -0
- package/src/InAppMessaging/components/BannerMessage/index.ts +2 -0
- package/src/InAppMessaging/components/BannerMessage/styles.ts +105 -0
- package/src/InAppMessaging/components/BannerMessage/types.ts +15 -0
- package/src/InAppMessaging/components/CarouselMessage/CarouselMessage.tsx +42 -0
- package/src/InAppMessaging/components/CarouselMessage/CarouselMessageItem.tsx +37 -0
- package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessage.spec.tsx +55 -0
- package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessageItem.spec.tsx +56 -0
- package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessage.spec.tsx.snap +86 -0
- package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessageItem.spec.tsx.snap +248 -0
- package/src/InAppMessaging/components/CarouselMessage/index.ts +2 -0
- package/src/InAppMessaging/components/CarouselMessage/styles.ts +125 -0
- package/src/InAppMessaging/components/CarouselMessage/types.ts +28 -0
- package/src/InAppMessaging/components/FullScreenMessage/FullScreenMessage.tsx +38 -0
- package/src/InAppMessaging/components/FullScreenMessage/__tests__/FullScreenMessage.spec.tsx +53 -0
- package/src/InAppMessaging/components/FullScreenMessage/__tests__/__snapshots__/FullScreenMessage.spec.tsx.snap +236 -0
- package/src/InAppMessaging/components/FullScreenMessage/index.ts +2 -0
- package/src/InAppMessaging/components/FullScreenMessage/styles.ts +106 -0
- package/src/InAppMessaging/components/FullScreenMessage/types.ts +7 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.tsx +48 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/InAppMessageDisplay.spec.tsx +33 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/__snapshots__/InAppMessageDisplay.spec.tsx.snap +9 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/handleMessageLinkAction.spec.ts +51 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.ts +30 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/index.ts +2 -0
- package/src/InAppMessaging/components/InAppMessageDisplay/types.ts +32 -0
- package/src/InAppMessaging/components/MessageLayout/MessageLayout.tsx +102 -0
- package/src/InAppMessaging/components/MessageLayout/index.ts +1 -0
- package/src/InAppMessaging/components/MessageLayout/types.ts +15 -0
- package/src/InAppMessaging/components/MessageWrapper/MessageWrapper.tsx +34 -0
- package/src/InAppMessaging/components/MessageWrapper/__tests__/MessageWrapper.spec.tsx +19 -0
- package/src/InAppMessaging/components/MessageWrapper/__tests__/__snapshots__/MessageWrapper.spec.tsx.snap +35 -0
- package/src/InAppMessaging/components/MessageWrapper/index.ts +2 -0
- package/src/InAppMessaging/components/MessageWrapper/styles.ts +7 -0
- package/src/InAppMessaging/components/MessageWrapper/types.ts +12 -0
- package/src/InAppMessaging/components/ModalMessage/ModalMessage.tsx +37 -0
- package/src/InAppMessaging/components/ModalMessage/__tests__/ModalMessage.spec.tsx +155 -0
- package/src/InAppMessaging/components/ModalMessage/__tests__/__snapshots__/ModalMessage.spec.tsx.snap +323 -0
- package/src/InAppMessaging/components/ModalMessage/index.ts +2 -0
- package/src/InAppMessaging/components/ModalMessage/styles.ts +132 -0
- package/src/InAppMessaging/components/ModalMessage/types.ts +8 -0
- package/src/InAppMessaging/components/index.ts +6 -0
- package/src/InAppMessaging/components/withInAppMessaging/__tests__/__snapshots__/withInAppMessaging.spec.tsx.snap +3 -0
- package/src/InAppMessaging/components/withInAppMessaging/__tests__/withInAppMessaging.spec.tsx +15 -0
- package/src/InAppMessaging/components/withInAppMessaging/index.ts +1 -0
- package/src/InAppMessaging/components/withInAppMessaging/withInAppMessaging.tsx +18 -0
- package/src/InAppMessaging/constants.ts +56 -0
- package/src/InAppMessaging/hooks/index.ts +9 -0
- package/src/InAppMessaging/hooks/useMessageImage/__tests__/useMessageImage.spec.ts +141 -0
- package/src/InAppMessaging/hooks/useMessageImage/__tests__/utils.spec.ts +107 -0
- package/src/InAppMessaging/hooks/useMessageImage/constants.ts +27 -0
- package/src/InAppMessaging/hooks/useMessageImage/index.ts +2 -0
- package/src/InAppMessaging/hooks/useMessageImage/types.ts +18 -0
- package/src/InAppMessaging/hooks/useMessageImage/useMessageImage.ts +74 -0
- package/src/InAppMessaging/hooks/useMessageImage/utils.ts +80 -0
- package/src/InAppMessaging/hooks/useMessageProps/__tests__/__snapshots__/utils.spec.ts.snap +223 -0
- package/src/InAppMessaging/hooks/useMessageProps/__tests__/useMessageProps.spec.ts +162 -0
- package/src/InAppMessaging/hooks/useMessageProps/__tests__/utils.spec.ts +354 -0
- package/src/InAppMessaging/hooks/useMessageProps/index.ts +8 -0
- package/src/InAppMessaging/hooks/useMessageProps/types.ts +131 -0
- package/src/InAppMessaging/hooks/useMessageProps/useMessageProps.ts +70 -0
- package/src/InAppMessaging/hooks/useMessageProps/utils.ts +274 -0
- package/src/InAppMessaging/index.ts +14 -0
- package/src/__mocks__/react-native-safe-area-context.ts +6 -0
- package/src/__tests__/__snapshots__/index.spec.ts.snap +15 -0
- package/src/__tests__/index.spec.ts +8 -0
- package/src/assets/close.png +0 -0
- package/src/assets/index.ts +7 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useDeviceOrientation/__tests__/useDeviceOrientation.spec.ts +87 -0
- package/src/hooks/useDeviceOrientation/index.ts +4 -0
- package/src/hooks/useDeviceOrientation/useDeviceOrientation.ts +47 -0
- package/src/index.ts +1 -0
- package/src/primitives/Button/Button.tsx +21 -0
- package/src/primitives/Button/__tests__/Button.spec.tsx +24 -0
- package/src/primitives/Button/__tests__/__snapshots__/Button.spec.tsx.snap +52 -0
- package/src/primitives/Button/index.ts +2 -0
- package/src/primitives/Button/styles.ts +6 -0
- package/src/primitives/Button/types.ts +9 -0
- package/src/primitives/Carousel/Carousel.tsx +115 -0
- package/src/primitives/Carousel/CarouselPageIndicator.tsx +39 -0
- package/src/primitives/Carousel/__tests__/Carousel.spec.tsx +185 -0
- package/src/primitives/Carousel/__tests__/CarouselPageIndicator.spec.tsx +71 -0
- package/src/primitives/Carousel/__tests__/__snapshots__/Carousel.spec.tsx.snap +216 -0
- package/src/primitives/Carousel/__tests__/__snapshots__/CarouselPageIndicator.spec.tsx.snap +191 -0
- package/src/primitives/Carousel/constants.ts +25 -0
- package/src/primitives/Carousel/index.ts +3 -0
- package/src/primitives/Carousel/styles.ts +14 -0
- package/src/primitives/Carousel/types.ts +22 -0
- package/src/primitives/IconButton/IconButton.tsx +20 -0
- package/src/primitives/IconButton/__tests__/IconButton.spec.tsx +13 -0
- package/src/primitives/IconButton/__tests__/__snapshots__/IconButton.spec.tsx.snap +34 -0
- package/src/primitives/IconButton/index.ts +2 -0
- package/src/primitives/IconButton/styles.ts +16 -0
- package/src/primitives/IconButton/types.ts +27 -0
- package/src/primitives/index.ts +3 -0
- package/src/utils/index.ts +6 -0
- package/tsconfig.dist.json +4 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal, ModalPropsIOS } from 'react-native';
|
|
3
|
+
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
|
4
|
+
|
|
5
|
+
import { styles } from './styles';
|
|
6
|
+
import { MessageWrapperProps } from './types';
|
|
7
|
+
|
|
8
|
+
const SUPPORTED_ORIENTATIONS: ModalPropsIOS['supportedOrientations'] = [
|
|
9
|
+
'portrait',
|
|
10
|
+
'portrait-upside-down',
|
|
11
|
+
'landscape',
|
|
12
|
+
'landscape-left',
|
|
13
|
+
'landscape-right',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default function MessageWrapper({
|
|
17
|
+
children,
|
|
18
|
+
disableSafeAreaView,
|
|
19
|
+
style,
|
|
20
|
+
}: MessageWrapperProps): JSX.Element {
|
|
21
|
+
return (
|
|
22
|
+
<Modal transparent visible supportedOrientations={SUPPORTED_ORIENTATIONS}>
|
|
23
|
+
<SafeAreaProvider>
|
|
24
|
+
{disableSafeAreaView ? (
|
|
25
|
+
children
|
|
26
|
+
) : (
|
|
27
|
+
<SafeAreaView style={[styles.messageWrapper, style]}>
|
|
28
|
+
{children}
|
|
29
|
+
</SafeAreaView>
|
|
30
|
+
)}
|
|
31
|
+
</SafeAreaProvider>
|
|
32
|
+
</Modal>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import TestRenderer from 'react-test-renderer';
|
|
3
|
+
import { Text } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import MessageWrapper from '../MessageWrapper';
|
|
6
|
+
|
|
7
|
+
const Children = () => <Text>Children</Text>;
|
|
8
|
+
|
|
9
|
+
describe('MessageWrapper', () => {
|
|
10
|
+
it('renders as expected', () => {
|
|
11
|
+
const renderer = TestRenderer.create(
|
|
12
|
+
<MessageWrapper>
|
|
13
|
+
<Children />
|
|
14
|
+
</MessageWrapper>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(renderer.toJSON()).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`MessageWrapper renders as expected 1`] = `
|
|
4
|
+
<Modal
|
|
5
|
+
hardwareAccelerated={false}
|
|
6
|
+
supportedOrientations={
|
|
7
|
+
Array [
|
|
8
|
+
"portrait",
|
|
9
|
+
"portrait-upside-down",
|
|
10
|
+
"landscape",
|
|
11
|
+
"landscape-left",
|
|
12
|
+
"landscape-right",
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
transparent={true}
|
|
16
|
+
visible={true}
|
|
17
|
+
>
|
|
18
|
+
<SafeAreaProvider>
|
|
19
|
+
<SafeAreaView
|
|
20
|
+
style={
|
|
21
|
+
Array [
|
|
22
|
+
Object {
|
|
23
|
+
"flex": 1,
|
|
24
|
+
},
|
|
25
|
+
undefined,
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
<Text>
|
|
30
|
+
Children
|
|
31
|
+
</Text>
|
|
32
|
+
</SafeAreaView>
|
|
33
|
+
</SafeAreaProvider>
|
|
34
|
+
</Modal>
|
|
35
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface MessageWrapperProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
disableSafeAreaView?: boolean;
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MessageWrapperStyle {
|
|
11
|
+
messageWrapper: ViewStyle;
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useDeviceOrientation } from '../../../hooks';
|
|
4
|
+
import { useMessageProps } from '../../hooks';
|
|
5
|
+
import { MessageLayout } from '../MessageLayout';
|
|
6
|
+
import { MessageWrapper } from '../MessageWrapper';
|
|
7
|
+
|
|
8
|
+
import { getLandscapeStyles, getPortraitStyles } from './styles';
|
|
9
|
+
import { ModalMessageProps } from './types';
|
|
10
|
+
|
|
11
|
+
export default function ModalMessage(
|
|
12
|
+
props: ModalMessageProps
|
|
13
|
+
): JSX.Element | null {
|
|
14
|
+
const { deviceOrientation, isPortraitMode } = useDeviceOrientation();
|
|
15
|
+
const messageProps = useMessageProps(
|
|
16
|
+
props,
|
|
17
|
+
isPortraitMode ? getPortraitStyles : getLandscapeStyles
|
|
18
|
+
);
|
|
19
|
+
const { shouldRenderMessage, styles } = messageProps;
|
|
20
|
+
|
|
21
|
+
if (!shouldRenderMessage) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { wrapper, ...messageStyles } = styles!;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<MessageWrapper style={wrapper}>
|
|
29
|
+
<MessageLayout
|
|
30
|
+
{...props}
|
|
31
|
+
{...messageProps}
|
|
32
|
+
orientation={deviceOrientation}
|
|
33
|
+
styles={messageStyles}
|
|
34
|
+
/>
|
|
35
|
+
</MessageWrapper>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import TestRenderer from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import { IN_APP_MESSAGING_TEST_ID } from '../../../constants';
|
|
5
|
+
import { useDeviceOrientation } from '../../../../hooks';
|
|
6
|
+
import { useMessageImage } from '../../../hooks';
|
|
7
|
+
|
|
8
|
+
import ModalMessage from '../ModalMessage';
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../../hooks');
|
|
11
|
+
jest.mock('../../../hooks/useMessageImage');
|
|
12
|
+
jest.mock('../../MessageWrapper', () => ({ MessageWrapper: 'MessageWrapper' }));
|
|
13
|
+
|
|
14
|
+
const mockUseMessageImage = useMessageImage as jest.Mock;
|
|
15
|
+
const onAction = jest.fn();
|
|
16
|
+
const onClose = jest.fn();
|
|
17
|
+
|
|
18
|
+
const baseProps = { layout: 'MODAL' as const, onClose };
|
|
19
|
+
|
|
20
|
+
describe('ModalMessage', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it.each([
|
|
26
|
+
['landscape', false],
|
|
27
|
+
['portrait', true],
|
|
28
|
+
])('renders as expected in %s mode', (deviceOrientation, isPortraitMode) => {
|
|
29
|
+
(useDeviceOrientation as jest.Mock).mockReturnValue({
|
|
30
|
+
deviceOrientation,
|
|
31
|
+
isPortraitMode,
|
|
32
|
+
});
|
|
33
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
34
|
+
hasRenderableImage: false,
|
|
35
|
+
imageDimensions: { height: null, width: null },
|
|
36
|
+
isImageFetching: false,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const renderer = TestRenderer.create(<ModalMessage {...baseProps} />);
|
|
40
|
+
|
|
41
|
+
expect(renderer.toJSON()).toMatchSnapshot();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders a message as expected with an image', () => {
|
|
45
|
+
(useDeviceOrientation as jest.Mock).mockReturnValue({
|
|
46
|
+
deviceOrientation: 'portrait',
|
|
47
|
+
isPortraitMode: true,
|
|
48
|
+
});
|
|
49
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
50
|
+
hasRenderableImage: true,
|
|
51
|
+
imageDimensions: { height: 100, width: 100 },
|
|
52
|
+
isImageFetching: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const src = 'asset.png';
|
|
56
|
+
const props = { ...baseProps, image: { src } };
|
|
57
|
+
|
|
58
|
+
const renderer = TestRenderer.create(<ModalMessage {...props} />);
|
|
59
|
+
|
|
60
|
+
const image = renderer.root.findByProps({
|
|
61
|
+
testID: IN_APP_MESSAGING_TEST_ID.IMAGE,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(image.props).toEqual(
|
|
65
|
+
expect.objectContaining({ source: { uri: src } })
|
|
66
|
+
);
|
|
67
|
+
expect(renderer.toJSON()).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('returns null while an image is fetching', () => {
|
|
71
|
+
(useDeviceOrientation as jest.Mock).mockReturnValue({
|
|
72
|
+
deviceOrientation: 'portrait',
|
|
73
|
+
isPortraitMode: true,
|
|
74
|
+
});
|
|
75
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
76
|
+
hasRenderableImage: false,
|
|
77
|
+
imageDimensions: { height: null, width: null },
|
|
78
|
+
isImageFetching: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const renderer = TestRenderer.create(<ModalMessage {...baseProps} />);
|
|
82
|
+
|
|
83
|
+
expect(renderer.toJSON()).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each([
|
|
87
|
+
[
|
|
88
|
+
'header',
|
|
89
|
+
IN_APP_MESSAGING_TEST_ID.HEADER,
|
|
90
|
+
{
|
|
91
|
+
testProps: { content: 'header content' },
|
|
92
|
+
expectedProps: { children: 'header content' },
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'body',
|
|
97
|
+
IN_APP_MESSAGING_TEST_ID.BODY,
|
|
98
|
+
{
|
|
99
|
+
testProps: { content: 'body content' },
|
|
100
|
+
expectedProps: { children: 'body content' },
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
'primaryButton',
|
|
105
|
+
IN_APP_MESSAGING_TEST_ID.PRIMARY_BUTTON,
|
|
106
|
+
{
|
|
107
|
+
testProps: { onAction, title: 'primary button' },
|
|
108
|
+
expectedProps: { children: 'primary button', onPress: onAction },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'secondaryButton',
|
|
113
|
+
IN_APP_MESSAGING_TEST_ID.SECONDARY_BUTTON,
|
|
114
|
+
{
|
|
115
|
+
testProps: { onAction, title: 'secondary button' },
|
|
116
|
+
expectedProps: { children: 'secondary button', onPress: onAction },
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
])(
|
|
120
|
+
'correctly handles a %s prop',
|
|
121
|
+
(key, testID, { testProps, expectedProps }) => {
|
|
122
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
123
|
+
hasRenderableImage: false,
|
|
124
|
+
imageDimensions: { height: null, width: null },
|
|
125
|
+
isImageFetching: false,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const props = { ...baseProps, [key]: testProps };
|
|
129
|
+
|
|
130
|
+
const renderer = TestRenderer.create(<ModalMessage {...props} />);
|
|
131
|
+
const testElement = renderer.root.findByProps({ testID });
|
|
132
|
+
|
|
133
|
+
expect(testElement.props).toEqual(expect.objectContaining(expectedProps));
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
it('calls onClose when the close button is pressed', () => {
|
|
138
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
139
|
+
hasRenderableImage: false,
|
|
140
|
+
imageDimensions: { height: null, width: null },
|
|
141
|
+
isImageFetching: false,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const renderer = TestRenderer.create(<ModalMessage {...baseProps} />);
|
|
145
|
+
const closeButton = renderer.root.findByProps({
|
|
146
|
+
testID: IN_APP_MESSAGING_TEST_ID.CLOSE_BUTTON,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
TestRenderer.act(() => {
|
|
150
|
+
(closeButton.props as { onPress: () => void }).onPress();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ModalMessage renders a message as expected with an image 1`] = `
|
|
4
|
+
<MessageWrapper
|
|
5
|
+
style={
|
|
6
|
+
Object {
|
|
7
|
+
"flex": 1,
|
|
8
|
+
"justifyContent": "center",
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
>
|
|
12
|
+
<View
|
|
13
|
+
style={
|
|
14
|
+
Array [
|
|
15
|
+
Object {
|
|
16
|
+
"backgroundColor": "#fff",
|
|
17
|
+
"elevation": 3,
|
|
18
|
+
"margin": 16,
|
|
19
|
+
"minHeight": "40%",
|
|
20
|
+
"shadowColor": "#000",
|
|
21
|
+
"shadowOffset": Object {
|
|
22
|
+
"height": 2,
|
|
23
|
+
"width": 2,
|
|
24
|
+
},
|
|
25
|
+
"shadowOpacity": 0.1,
|
|
26
|
+
"shadowRadius": 2,
|
|
27
|
+
},
|
|
28
|
+
Object {},
|
|
29
|
+
Object {},
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<View
|
|
34
|
+
style={
|
|
35
|
+
Object {
|
|
36
|
+
"padding": 12,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
<View
|
|
41
|
+
accessible={true}
|
|
42
|
+
collapsable={false}
|
|
43
|
+
focusable={true}
|
|
44
|
+
hitSlop={
|
|
45
|
+
Object {
|
|
46
|
+
"bottom": 10,
|
|
47
|
+
"left": 10,
|
|
48
|
+
"right": 10,
|
|
49
|
+
"top": 10,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
onBlur={[Function]}
|
|
53
|
+
onClick={[Function]}
|
|
54
|
+
onFocus={[Function]}
|
|
55
|
+
onResponderGrant={[Function]}
|
|
56
|
+
onResponderMove={[Function]}
|
|
57
|
+
onResponderRelease={[Function]}
|
|
58
|
+
onResponderTerminate={[Function]}
|
|
59
|
+
onResponderTerminationRequest={[Function]}
|
|
60
|
+
onStartShouldSetResponder={[Function]}
|
|
61
|
+
style={
|
|
62
|
+
Array [
|
|
63
|
+
Object {
|
|
64
|
+
"alignSelf": "flex-start",
|
|
65
|
+
"marginLeft": "auto",
|
|
66
|
+
},
|
|
67
|
+
undefined,
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
testID="in-app-messaging--close-button"
|
|
71
|
+
>
|
|
72
|
+
<Image
|
|
73
|
+
source={
|
|
74
|
+
Object {
|
|
75
|
+
"testUri": "../../../src/assets/close.png",
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
style={
|
|
79
|
+
Object {
|
|
80
|
+
"height": 20,
|
|
81
|
+
"resizeMode": "contain",
|
|
82
|
+
"tintColor": undefined,
|
|
83
|
+
"width": 20,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
</View>
|
|
88
|
+
<View
|
|
89
|
+
style={
|
|
90
|
+
Object {
|
|
91
|
+
"alignItems": "center",
|
|
92
|
+
"margin": 12,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
>
|
|
96
|
+
<Image
|
|
97
|
+
source={
|
|
98
|
+
Object {
|
|
99
|
+
"uri": "asset.png",
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
style={
|
|
103
|
+
Array [
|
|
104
|
+
Object {
|
|
105
|
+
"height": 100,
|
|
106
|
+
"width": 100,
|
|
107
|
+
},
|
|
108
|
+
undefined,
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
testID="in-app-messaging--image"
|
|
112
|
+
/>
|
|
113
|
+
</View>
|
|
114
|
+
<View
|
|
115
|
+
style={
|
|
116
|
+
Object {
|
|
117
|
+
"marginTop": 12,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
</View>
|
|
123
|
+
</MessageWrapper>
|
|
124
|
+
`;
|
|
125
|
+
|
|
126
|
+
exports[`ModalMessage renders as expected in landscape mode 1`] = `
|
|
127
|
+
<MessageWrapper
|
|
128
|
+
style={
|
|
129
|
+
Object {
|
|
130
|
+
"flex": 1,
|
|
131
|
+
"justifyContent": "center",
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
>
|
|
135
|
+
<View
|
|
136
|
+
style={
|
|
137
|
+
Array [
|
|
138
|
+
Object {
|
|
139
|
+
"backgroundColor": "#fff",
|
|
140
|
+
"elevation": 3,
|
|
141
|
+
"flex": 1,
|
|
142
|
+
"margin": 16,
|
|
143
|
+
"padding": 16,
|
|
144
|
+
"shadowColor": "#000",
|
|
145
|
+
"shadowOffset": Object {
|
|
146
|
+
"height": 2,
|
|
147
|
+
"width": 2,
|
|
148
|
+
},
|
|
149
|
+
"shadowOpacity": 0.1,
|
|
150
|
+
"shadowRadius": 2,
|
|
151
|
+
},
|
|
152
|
+
Object {},
|
|
153
|
+
Object {},
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
<View
|
|
158
|
+
style={
|
|
159
|
+
Object {
|
|
160
|
+
"flex": 1,
|
|
161
|
+
"flexDirection": "row",
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
>
|
|
165
|
+
<View
|
|
166
|
+
style={
|
|
167
|
+
Object {
|
|
168
|
+
"flex": 1,
|
|
169
|
+
"justifyContent": "center",
|
|
170
|
+
"paddingHorizontal": 8,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/>
|
|
174
|
+
<View
|
|
175
|
+
accessible={true}
|
|
176
|
+
collapsable={false}
|
|
177
|
+
focusable={true}
|
|
178
|
+
hitSlop={
|
|
179
|
+
Object {
|
|
180
|
+
"bottom": 10,
|
|
181
|
+
"left": 10,
|
|
182
|
+
"right": 10,
|
|
183
|
+
"top": 10,
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
onBlur={[Function]}
|
|
187
|
+
onClick={[Function]}
|
|
188
|
+
onFocus={[Function]}
|
|
189
|
+
onResponderGrant={[Function]}
|
|
190
|
+
onResponderMove={[Function]}
|
|
191
|
+
onResponderRelease={[Function]}
|
|
192
|
+
onResponderTerminate={[Function]}
|
|
193
|
+
onResponderTerminationRequest={[Function]}
|
|
194
|
+
onStartShouldSetResponder={[Function]}
|
|
195
|
+
style={
|
|
196
|
+
Array [
|
|
197
|
+
Object {
|
|
198
|
+
"alignSelf": "flex-start",
|
|
199
|
+
"marginLeft": "auto",
|
|
200
|
+
"marginRight": 8,
|
|
201
|
+
},
|
|
202
|
+
undefined,
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
testID="in-app-messaging--close-button"
|
|
206
|
+
>
|
|
207
|
+
<Image
|
|
208
|
+
source={
|
|
209
|
+
Object {
|
|
210
|
+
"testUri": "../../../src/assets/close.png",
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
style={
|
|
214
|
+
Object {
|
|
215
|
+
"height": 20,
|
|
216
|
+
"resizeMode": "contain",
|
|
217
|
+
"tintColor": undefined,
|
|
218
|
+
"width": 20,
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/>
|
|
222
|
+
</View>
|
|
223
|
+
</View>
|
|
224
|
+
</View>
|
|
225
|
+
</MessageWrapper>
|
|
226
|
+
`;
|
|
227
|
+
|
|
228
|
+
exports[`ModalMessage renders as expected in portrait mode 1`] = `
|
|
229
|
+
<MessageWrapper
|
|
230
|
+
style={
|
|
231
|
+
Object {
|
|
232
|
+
"flex": 1,
|
|
233
|
+
"justifyContent": "center",
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
>
|
|
237
|
+
<View
|
|
238
|
+
style={
|
|
239
|
+
Array [
|
|
240
|
+
Object {
|
|
241
|
+
"backgroundColor": "#fff",
|
|
242
|
+
"elevation": 3,
|
|
243
|
+
"margin": 16,
|
|
244
|
+
"minHeight": "40%",
|
|
245
|
+
"shadowColor": "#000",
|
|
246
|
+
"shadowOffset": Object {
|
|
247
|
+
"height": 2,
|
|
248
|
+
"width": 2,
|
|
249
|
+
},
|
|
250
|
+
"shadowOpacity": 0.1,
|
|
251
|
+
"shadowRadius": 2,
|
|
252
|
+
},
|
|
253
|
+
Object {},
|
|
254
|
+
Object {},
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
>
|
|
258
|
+
<View
|
|
259
|
+
style={
|
|
260
|
+
Object {
|
|
261
|
+
"padding": 12,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
>
|
|
265
|
+
<View
|
|
266
|
+
accessible={true}
|
|
267
|
+
collapsable={false}
|
|
268
|
+
focusable={true}
|
|
269
|
+
hitSlop={
|
|
270
|
+
Object {
|
|
271
|
+
"bottom": 10,
|
|
272
|
+
"left": 10,
|
|
273
|
+
"right": 10,
|
|
274
|
+
"top": 10,
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
onBlur={[Function]}
|
|
278
|
+
onClick={[Function]}
|
|
279
|
+
onFocus={[Function]}
|
|
280
|
+
onResponderGrant={[Function]}
|
|
281
|
+
onResponderMove={[Function]}
|
|
282
|
+
onResponderRelease={[Function]}
|
|
283
|
+
onResponderTerminate={[Function]}
|
|
284
|
+
onResponderTerminationRequest={[Function]}
|
|
285
|
+
onStartShouldSetResponder={[Function]}
|
|
286
|
+
style={
|
|
287
|
+
Array [
|
|
288
|
+
Object {
|
|
289
|
+
"alignSelf": "flex-start",
|
|
290
|
+
"marginLeft": "auto",
|
|
291
|
+
},
|
|
292
|
+
undefined,
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
testID="in-app-messaging--close-button"
|
|
296
|
+
>
|
|
297
|
+
<Image
|
|
298
|
+
source={
|
|
299
|
+
Object {
|
|
300
|
+
"testUri": "../../../src/assets/close.png",
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
style={
|
|
304
|
+
Object {
|
|
305
|
+
"height": 20,
|
|
306
|
+
"resizeMode": "contain",
|
|
307
|
+
"tintColor": undefined,
|
|
308
|
+
"width": 20,
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/>
|
|
312
|
+
</View>
|
|
313
|
+
<View
|
|
314
|
+
style={
|
|
315
|
+
Object {
|
|
316
|
+
"marginTop": 12,
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/>
|
|
320
|
+
</View>
|
|
321
|
+
</View>
|
|
322
|
+
</MessageWrapper>
|
|
323
|
+
`;
|