@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,43 @@
|
|
|
1
|
+
import { getLineHeight } from '../utils';
|
|
2
|
+
// color
|
|
3
|
+
export const COLOR_BLACK = '#000';
|
|
4
|
+
export const COLOR_GREY = '#a1a1a1';
|
|
5
|
+
export const COLOR_LIGHT_GREY = '#e8e8e8';
|
|
6
|
+
export const COLOR_LIGHT_GREY_2 = '#d8d8d8';
|
|
7
|
+
export const COLOR_WHITE = '#fff';
|
|
8
|
+
// spacing
|
|
9
|
+
export const SPACING_SMALL = 4;
|
|
10
|
+
export const SPACING_MEDIUM = 8;
|
|
11
|
+
export const SPACING_LARGE = 12;
|
|
12
|
+
export const SPACING_EXTRA_LARGE = 16;
|
|
13
|
+
// border radius
|
|
14
|
+
export const BORDER_RADIUS_BASE = 4;
|
|
15
|
+
// font
|
|
16
|
+
export const FONT_SIZE_BASE = 16;
|
|
17
|
+
export const FONT_SIZE_LARGE = 18;
|
|
18
|
+
export const LINE_HEIGHT_BASE = getLineHeight(FONT_SIZE_BASE);
|
|
19
|
+
export const LINE_HEIGHT_LARGE = getLineHeight(FONT_SIZE_LARGE);
|
|
20
|
+
export const FONT_WEIGHT_BASE = '400';
|
|
21
|
+
// icon
|
|
22
|
+
export const ICON_BUTTON_SIZE = 20;
|
|
23
|
+
export const ICON_BUTTON_HIT_SLOP = 10;
|
|
24
|
+
// shadow properties
|
|
25
|
+
// iOS shadow values
|
|
26
|
+
export const MESSAGE_SHADOW_HEIGHT = 2;
|
|
27
|
+
export const MESSAGE_SHADOW_WIDTH = 2;
|
|
28
|
+
export const MESSAGE_SHADOW_OPACITY = 0.1;
|
|
29
|
+
export const MESSAGE_SHADOW_RADIUS = 2;
|
|
30
|
+
// android shadow values
|
|
31
|
+
export const MESSAGE_ELEVATION = 3;
|
|
32
|
+
// Message UI Buttons
|
|
33
|
+
// default value applied in React Native TouchableOpacity
|
|
34
|
+
export const BUTTON_PRESSED_OPACITY = 0.8;
|
|
35
|
+
// Message Component Test IDs
|
|
36
|
+
export const IN_APP_MESSAGING_TEST_ID = {
|
|
37
|
+
BODY: 'in-app-messaging--body',
|
|
38
|
+
CLOSE_BUTTON: 'in-app-messaging--close-button',
|
|
39
|
+
HEADER: 'in-app-messaging--header',
|
|
40
|
+
IMAGE: 'in-app-messaging--image',
|
|
41
|
+
PRIMARY_BUTTON: 'in-app-messaging--primary-button',
|
|
42
|
+
SECONDARY_BUTTON: 'in-app-messaging--secondary-button',
|
|
43
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const BANNER_IMAGE_SCREEN_MULTIPLIER = 0.2;
|
|
2
|
+
export declare const CAROUSEL_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
3
|
+
export declare const FULL_SCREEN_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
4
|
+
export declare const MODAL_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
5
|
+
export declare const BANNER_IMAGE_SCREEN_SIZE: number;
|
|
6
|
+
export declare const CAROUSEL_IMAGE_SCREEN_SIZE: number;
|
|
7
|
+
export declare const FULL_SCREEN_IMAGE_SCREEN_SIZE: number;
|
|
8
|
+
export declare const MODAL_IMAGE_SCREEN_SIZE: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native';
|
|
2
|
+
// as images are not expected to be responsive to orientation changes get screen dimensions at app start
|
|
3
|
+
const SCREEN_DIMENSIONS = Dimensions.get('screen');
|
|
4
|
+
// compare screen width and height and assign the lesser of the two as the base screen dimension
|
|
5
|
+
const BASE_SCREEN_DIMENSION = SCREEN_DIMENSIONS.width < SCREEN_DIMENSIONS.height
|
|
6
|
+
? SCREEN_DIMENSIONS.width
|
|
7
|
+
: SCREEN_DIMENSIONS.height;
|
|
8
|
+
// base size that message images should fill
|
|
9
|
+
// - all banner message images should fill 20 percent of the base screen dimension
|
|
10
|
+
// - all other components should fill 60 percent of the base screen dimension
|
|
11
|
+
export const BANNER_IMAGE_SCREEN_MULTIPLIER = 0.2;
|
|
12
|
+
export const CAROUSEL_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
13
|
+
export const FULL_SCREEN_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
14
|
+
export const MODAL_IMAGE_SCREEN_MULTIPLIER = 0.6;
|
|
15
|
+
export const BANNER_IMAGE_SCREEN_SIZE = BANNER_IMAGE_SCREEN_MULTIPLIER * BASE_SCREEN_DIMENSION;
|
|
16
|
+
export const CAROUSEL_IMAGE_SCREEN_SIZE = CAROUSEL_IMAGE_SCREEN_MULTIPLIER * BASE_SCREEN_DIMENSION;
|
|
17
|
+
export const FULL_SCREEN_IMAGE_SCREEN_SIZE = FULL_SCREEN_IMAGE_SCREEN_MULTIPLIER * BASE_SCREEN_DIMENSION;
|
|
18
|
+
export const MODAL_IMAGE_SCREEN_SIZE = MODAL_IMAGE_SCREEN_MULTIPLIER * BASE_SCREEN_DIMENSION;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useMessageImage } from './useMessageImage';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare type ImageDimensions = {
|
|
2
|
+
height: number | undefined;
|
|
3
|
+
width: number | undefined;
|
|
4
|
+
};
|
|
5
|
+
export declare type ImageLoadingState = 'loaded' | 'failed';
|
|
6
|
+
export declare enum ImagePrefetchStatus {
|
|
7
|
+
Failure = "FAILURE",
|
|
8
|
+
Fetching = "FETCHING",
|
|
9
|
+
Success = "SUCCESS"
|
|
10
|
+
}
|
|
11
|
+
export declare type UseMessageImage = {
|
|
12
|
+
hasRenderableImage: boolean;
|
|
13
|
+
imageDimensions: ImageDimensions;
|
|
14
|
+
isImageFetching: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MessageImage, MessageLayout } from '@aws-amplify/ui-react-core';
|
|
2
|
+
import { UseMessageImage } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Handles prefetching and dimension setting for message images
|
|
5
|
+
*
|
|
6
|
+
* @param image contains image source
|
|
7
|
+
* @param layout message layout
|
|
8
|
+
* @returns message image dimensions and rendering related booleans
|
|
9
|
+
*/
|
|
10
|
+
export default function useMessageImage(image: MessageImage | undefined, layout: MessageLayout): UseMessageImage;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Image } from 'react-native';
|
|
3
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
4
|
+
import { ImagePrefetchStatus } from './types';
|
|
5
|
+
import { getLayoutImageDimensions, prefetchNetworkImage } from './utils';
|
|
6
|
+
const logger = new Logger('Notifications.InAppMessaging');
|
|
7
|
+
/**
|
|
8
|
+
* Handles prefetching and dimension setting for message images
|
|
9
|
+
*
|
|
10
|
+
* @param image contains image source
|
|
11
|
+
* @param layout message layout
|
|
12
|
+
* @returns message image dimensions and rendering related booleans
|
|
13
|
+
*/
|
|
14
|
+
export default function useMessageImage(image, layout) {
|
|
15
|
+
const { src } = image ?? {};
|
|
16
|
+
const shouldPrefetch = !!src;
|
|
17
|
+
// set initial status to fetching if prefetch is required
|
|
18
|
+
const [prefetchStatus, setPrefetchStatus] = useState(shouldPrefetch ? ImagePrefetchStatus.Fetching : null);
|
|
19
|
+
const imageDimensions = useRef({
|
|
20
|
+
height: undefined,
|
|
21
|
+
width: undefined,
|
|
22
|
+
}).current;
|
|
23
|
+
const isImageFetching = prefetchStatus === ImagePrefetchStatus.Fetching;
|
|
24
|
+
const hasRenderableImage = prefetchStatus === ImagePrefetchStatus.Success;
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!shouldPrefetch) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
prefetchNetworkImage(src).then((prefetchResult) => {
|
|
30
|
+
if (prefetchResult === 'loaded') {
|
|
31
|
+
// get image size once loaded
|
|
32
|
+
Image.getSize(src, (imageWidth, imageHeight) => {
|
|
33
|
+
const { height, width } = getLayoutImageDimensions(imageHeight, imageWidth, layout);
|
|
34
|
+
imageDimensions.height = height;
|
|
35
|
+
imageDimensions.width = width;
|
|
36
|
+
setPrefetchStatus(ImagePrefetchStatus.Success);
|
|
37
|
+
}, (error) => {
|
|
38
|
+
// handle size retrieval error
|
|
39
|
+
logger.error(`Unable to retrieve size for image: ${error}`);
|
|
40
|
+
setPrefetchStatus(ImagePrefetchStatus.Failure);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// handle prefetch failure
|
|
45
|
+
setPrefetchStatus(ImagePrefetchStatus.Failure);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}, [imageDimensions, layout, shouldPrefetch, src]);
|
|
49
|
+
return { hasRenderableImage, imageDimensions, isImageFetching };
|
|
50
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MessageLayout } from '@aws-amplify/ui-react-core';
|
|
2
|
+
import { ImageDimensions, ImageLoadingState } from './types';
|
|
3
|
+
export declare const prefetchNetworkImage: (url: string) => Promise<ImageLoadingState>;
|
|
4
|
+
export declare const getLayoutImageDimensions: (imageHeight: number, imageWidth: number, layout: MessageLayout) => ImageDimensions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Image } from 'react-native';
|
|
2
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
3
|
+
import { BANNER_IMAGE_SCREEN_SIZE, CAROUSEL_IMAGE_SCREEN_SIZE, FULL_SCREEN_IMAGE_SCREEN_SIZE, MODAL_IMAGE_SCREEN_SIZE, } from './constants';
|
|
4
|
+
const logger = new Logger('Notifications.InAppMessaging');
|
|
5
|
+
const inAppMessageImageSizes = {
|
|
6
|
+
BOTTOM_BANNER: BANNER_IMAGE_SCREEN_SIZE,
|
|
7
|
+
MIDDLE_BANNER: BANNER_IMAGE_SCREEN_SIZE,
|
|
8
|
+
TOP_BANNER: BANNER_IMAGE_SCREEN_SIZE,
|
|
9
|
+
CAROUSEL: CAROUSEL_IMAGE_SCREEN_SIZE,
|
|
10
|
+
FULL_SCREEN: FULL_SCREEN_IMAGE_SCREEN_SIZE,
|
|
11
|
+
MODAL: MODAL_IMAGE_SCREEN_SIZE,
|
|
12
|
+
};
|
|
13
|
+
export const prefetchNetworkImage = async (url) => {
|
|
14
|
+
try {
|
|
15
|
+
const loaded = await Image.prefetch(url);
|
|
16
|
+
if (loaded) {
|
|
17
|
+
return 'loaded';
|
|
18
|
+
}
|
|
19
|
+
logger.error(`Image failed to load: ${url}`);
|
|
20
|
+
return 'failed';
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
logger.error(`Image.prefetch failed: ${e}`);
|
|
24
|
+
return 'failed';
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export const getLayoutImageDimensions = (imageHeight, imageWidth, layout) => {
|
|
28
|
+
// determine aspect ratio for scaling rendered image
|
|
29
|
+
const aspectRatio = imageWidth / imageHeight;
|
|
30
|
+
const isSquare = aspectRatio === 1;
|
|
31
|
+
const isPortrait = imageHeight > imageWidth;
|
|
32
|
+
const isLandscape = imageWidth > imageHeight;
|
|
33
|
+
// an image that has smaller dimensions than the max image dimension (e.g. 10px x 10px)
|
|
34
|
+
// will be scaled up in size to match the size the message component expects.
|
|
35
|
+
// While this could lead to pixelated images, it was ultimately a product decision,
|
|
36
|
+
// ideally the message creator would follow the image guidelines in the pinpoint console
|
|
37
|
+
const maxImageDimension = inAppMessageImageSizes[layout];
|
|
38
|
+
let height = undefined;
|
|
39
|
+
let width = undefined;
|
|
40
|
+
// set square image dimensions
|
|
41
|
+
if (isSquare) {
|
|
42
|
+
height = maxImageDimension;
|
|
43
|
+
width = maxImageDimension;
|
|
44
|
+
}
|
|
45
|
+
// set portrait image dimensions
|
|
46
|
+
if (isPortrait) {
|
|
47
|
+
height = maxImageDimension;
|
|
48
|
+
width = maxImageDimension * aspectRatio;
|
|
49
|
+
}
|
|
50
|
+
// set landscape image dimensions
|
|
51
|
+
if (isLandscape) {
|
|
52
|
+
height = maxImageDimension / aspectRatio;
|
|
53
|
+
width = maxImageDimension;
|
|
54
|
+
}
|
|
55
|
+
return { height, width };
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useMessageProps } from './useMessageProps';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ColorValue, ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
import { MessageLayout, MessagePayloadStyle } from '@aws-amplify/ui-react-core';
|
|
3
|
+
import { ButtonProps } from '../../../primitives';
|
|
4
|
+
import { ImageDimensions } from '../useMessageImage';
|
|
5
|
+
/**
|
|
6
|
+
* Resolved message types
|
|
7
|
+
*/
|
|
8
|
+
export interface MessageComponentStyles {
|
|
9
|
+
body: StyleProp<TextStyle>;
|
|
10
|
+
buttonsContainer: StyleProp<ViewStyle>;
|
|
11
|
+
container: StyleProp<ViewStyle>;
|
|
12
|
+
contentContainer: StyleProp<ViewStyle>;
|
|
13
|
+
header: StyleProp<TextStyle>;
|
|
14
|
+
iconButton: {
|
|
15
|
+
container: StyleProp<ViewStyle>;
|
|
16
|
+
iconColor?: ColorValue;
|
|
17
|
+
};
|
|
18
|
+
imageContainer: StyleProp<ViewStyle>;
|
|
19
|
+
image: StyleProp<ImageStyle>;
|
|
20
|
+
primaryButton: MessageButtonStyleProps;
|
|
21
|
+
secondaryButton: MessageButtonStyleProps;
|
|
22
|
+
textContainer: StyleProp<ViewStyle>;
|
|
23
|
+
wrapper: StyleProp<ViewStyle>;
|
|
24
|
+
}
|
|
25
|
+
export declare type GetDefaultStyle<AdditionalStyle = unknown> = (imageDimensions: ImageDimensions, additionalStyle?: AdditionalStyle) => MessageDefaultStyle;
|
|
26
|
+
export interface UseMessageProps {
|
|
27
|
+
hasButtons: boolean;
|
|
28
|
+
hasPrimaryButton: boolean;
|
|
29
|
+
hasRenderableImage: boolean;
|
|
30
|
+
hasSecondaryButton: boolean;
|
|
31
|
+
shouldRenderMessage: boolean;
|
|
32
|
+
styles: MessageComponentStyles | null;
|
|
33
|
+
}
|
|
34
|
+
export interface MessageStyleParams {
|
|
35
|
+
/**
|
|
36
|
+
* message specific layout
|
|
37
|
+
*/
|
|
38
|
+
layout: MessageLayout;
|
|
39
|
+
/**
|
|
40
|
+
* style params to derive resolved style from
|
|
41
|
+
*/
|
|
42
|
+
styleParams: StyleParams;
|
|
43
|
+
}
|
|
44
|
+
export interface StyleParams {
|
|
45
|
+
/**
|
|
46
|
+
* default component styles defined at the UI component level
|
|
47
|
+
*/
|
|
48
|
+
defaultStyle: MessageDefaultStyle;
|
|
49
|
+
/**
|
|
50
|
+
* message specific styles in the message payload
|
|
51
|
+
*/
|
|
52
|
+
payloadStyle: MessagePayloadStyle;
|
|
53
|
+
/**
|
|
54
|
+
* custom component style passed as style prop to message UI components
|
|
55
|
+
*/
|
|
56
|
+
overrideStyle: MessageOverrideStyle;
|
|
57
|
+
}
|
|
58
|
+
export interface MessageButtonStyleParams {
|
|
59
|
+
/**
|
|
60
|
+
* message button types
|
|
61
|
+
*/
|
|
62
|
+
buttonType: 'primaryButton' | 'secondaryButton';
|
|
63
|
+
/**
|
|
64
|
+
* style params to derive resolved style from
|
|
65
|
+
*/
|
|
66
|
+
styleParams: StyleParams;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Default Message UI component style props
|
|
70
|
+
*/
|
|
71
|
+
export interface MessageDefaultStyle {
|
|
72
|
+
body: TextStyle;
|
|
73
|
+
buttonContainer: ViewStyle;
|
|
74
|
+
buttonsContainer: ViewStyle;
|
|
75
|
+
buttonText: TextStyle;
|
|
76
|
+
container: ViewStyle;
|
|
77
|
+
contentContainer: ViewStyle;
|
|
78
|
+
header: TextStyle;
|
|
79
|
+
iconButton: ViewStyle;
|
|
80
|
+
image: ImageStyle;
|
|
81
|
+
imageContainer: ViewStyle;
|
|
82
|
+
textContainer: ViewStyle;
|
|
83
|
+
wrapper: ViewStyle;
|
|
84
|
+
}
|
|
85
|
+
export interface MessageButtonStyleProps {
|
|
86
|
+
container?: ButtonProps['style'];
|
|
87
|
+
text?: ButtonProps['textStyle'];
|
|
88
|
+
}
|
|
89
|
+
export interface MessageContainerAndWrapperStyle {
|
|
90
|
+
container: [
|
|
91
|
+
defaultStyle: StyleProp<ViewStyle>,
|
|
92
|
+
messageStyle: StyleProp<ViewStyle>,
|
|
93
|
+
overrideStyle: StyleProp<ViewStyle>
|
|
94
|
+
];
|
|
95
|
+
wrapper: StyleProp<ViewStyle>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Override style props
|
|
99
|
+
*/
|
|
100
|
+
export interface MessageOverrideStyle {
|
|
101
|
+
body?: StyleProp<TextStyle>;
|
|
102
|
+
closeIconButton?: StyleProp<ViewStyle>;
|
|
103
|
+
closeIconColor?: ColorValue;
|
|
104
|
+
container?: StyleProp<ViewStyle>;
|
|
105
|
+
header?: StyleProp<TextStyle>;
|
|
106
|
+
image?: StyleProp<ImageStyle>;
|
|
107
|
+
primaryButton?: MessageButtonStyleProps;
|
|
108
|
+
secondaryButton?: MessageButtonStyleProps;
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MessageComponentBaseProps } from '@aws-amplify/ui-react-core';
|
|
2
|
+
import { GetDefaultStyle, MessageOverrideStyle, UseMessageProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Handle common message UI component prop logic including setting of image dimensions,
|
|
5
|
+
* render booleans, and style resolving
|
|
6
|
+
*
|
|
7
|
+
* @param {MessageComponentBaseProps} props - message UI component props
|
|
8
|
+
* @param {GetDefaultStyle} getDefaultStyle - returns default UI component style
|
|
9
|
+
*
|
|
10
|
+
* @returns {UseMessageProps} message UI component render related booleans and styles
|
|
11
|
+
*/
|
|
12
|
+
export default function useMessageProps(props: MessageComponentBaseProps<MessageOverrideStyle>, getDefaultStyle: GetDefaultStyle): UseMessageProps;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import isEmpty from 'lodash/isEmpty';
|
|
3
|
+
import { useMessageImage } from '../useMessageImage';
|
|
4
|
+
import { getPayloadStyle, getMessageStyles } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* Handle common message UI component prop logic including setting of image dimensions,
|
|
7
|
+
* render booleans, and style resolving
|
|
8
|
+
*
|
|
9
|
+
* @param {MessageComponentBaseProps} props - message UI component props
|
|
10
|
+
* @param {GetDefaultStyle} getDefaultStyle - returns default UI component style
|
|
11
|
+
*
|
|
12
|
+
* @returns {UseMessageProps} message UI component render related booleans and styles
|
|
13
|
+
*/
|
|
14
|
+
export default function useMessageProps(props, getDefaultStyle) {
|
|
15
|
+
const { image, layout, onDisplay, primaryButton, secondaryButton } = props;
|
|
16
|
+
const hasDisplayed = useRef(false);
|
|
17
|
+
const { hasRenderableImage, imageDimensions, isImageFetching } = useMessageImage(image, layout);
|
|
18
|
+
const shouldRenderMessage = !isImageFetching;
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!hasDisplayed.current && shouldRenderMessage) {
|
|
21
|
+
onDisplay?.();
|
|
22
|
+
hasDisplayed.current = true;
|
|
23
|
+
}
|
|
24
|
+
}, [onDisplay, shouldRenderMessage]);
|
|
25
|
+
const hasPrimaryButton = !isEmpty(primaryButton);
|
|
26
|
+
const hasSecondaryButton = !isEmpty(secondaryButton);
|
|
27
|
+
const hasButtons = hasPrimaryButton || hasSecondaryButton;
|
|
28
|
+
const styles = useMemo(() => {
|
|
29
|
+
// prevent generating style if message rendering is delayed
|
|
30
|
+
if (!shouldRenderMessage) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const defaultStyle = getDefaultStyle(imageDimensions);
|
|
34
|
+
const payloadStyle = getPayloadStyle(props);
|
|
35
|
+
const overrideStyle = props.style;
|
|
36
|
+
return getMessageStyles({
|
|
37
|
+
styleParams: { defaultStyle, payloadStyle, overrideStyle },
|
|
38
|
+
layout,
|
|
39
|
+
});
|
|
40
|
+
}, [getDefaultStyle, layout, imageDimensions, props, shouldRenderMessage]);
|
|
41
|
+
return {
|
|
42
|
+
hasButtons,
|
|
43
|
+
hasPrimaryButton,
|
|
44
|
+
hasRenderableImage,
|
|
45
|
+
hasSecondaryButton,
|
|
46
|
+
shouldRenderMessage,
|
|
47
|
+
styles,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MessageComponentBaseProps, MessageLayout, MessagePayloadStyle } from '@aws-amplify/ui-react-core';
|
|
2
|
+
import { MessageButtonStyleParams, MessageButtonStyleProps, MessageComponentStyles, MessageContainerAndWrapperStyle, MessageStyleParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Parse and assign appropriate button container and text style from style objects params
|
|
5
|
+
*
|
|
6
|
+
* @param {MessageButtonStyleParams} params - message styleParams and button type
|
|
7
|
+
* @returns {MessageButtonStyleProps} resolved button container and text style arrays
|
|
8
|
+
*/
|
|
9
|
+
export declare const getComponentButtonStyle: ({ styleParams, buttonType, }: MessageButtonStyleParams) => MessageButtonStyleProps;
|
|
10
|
+
/**
|
|
11
|
+
* Utility for determining if the provided layout requires filling the entire device screen.
|
|
12
|
+
*
|
|
13
|
+
* @param {InAppMessageLayout} layout - message layout
|
|
14
|
+
* @returns {Boolean} boolean indicating whether entire screen should be filled
|
|
15
|
+
*/
|
|
16
|
+
export declare const shouldFillDeviceScreen: (layout: MessageLayout) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Parse and assign appropriate message container and wrapper style from style params
|
|
19
|
+
*
|
|
20
|
+
* @param {MessageStyleParams} params - message styleParams, layout, and device orientation
|
|
21
|
+
* @returns {ContainerAndWrapperStyle} resolved containerStyle and wrapperStyle
|
|
22
|
+
*/
|
|
23
|
+
export declare const getContainerAndWrapperStyle: ({ styleParams, layout, }: MessageStyleParams) => MessageContainerAndWrapperStyle;
|
|
24
|
+
/**
|
|
25
|
+
* Utility for extracting message payload style
|
|
26
|
+
*
|
|
27
|
+
* @param {MessageComponentBaseProps} props - message props
|
|
28
|
+
* @returns {Object} message payload specific style
|
|
29
|
+
*/
|
|
30
|
+
export declare const getPayloadStyle: ({ body, container, header, primaryButton, secondaryButton, }: MessageComponentBaseProps) => MessagePayloadStyle;
|
|
31
|
+
/**
|
|
32
|
+
* Receives message styling and returns style property values for use with in-app message
|
|
33
|
+
* UI components. Handles resolvement style precedence between default, payload, and custom style
|
|
34
|
+
*
|
|
35
|
+
* Style param resolve precedence from lowest to highest:
|
|
36
|
+
* 1. defaultStyle
|
|
37
|
+
* 2. messageStyle
|
|
38
|
+
* 3. overrideStyle
|
|
39
|
+
*
|
|
40
|
+
* @param {MessageStyleParams} params - message style params, layout, and device orientation
|
|
41
|
+
* @returns {MessageStyles} message style props
|
|
42
|
+
*/
|
|
43
|
+
export declare function getMessageStyles({ styleParams, layout, }: MessageStyleParams): MessageComponentStyles;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { DEFAULT_CAROUSEL_INDICATOR_SIZE } from '../../../primitives';
|
|
3
|
+
import { BUTTON_PRESSED_OPACITY, SPACING_EXTRA_LARGE } from '../../constants';
|
|
4
|
+
// Carousel page indicator size + margins
|
|
5
|
+
const DEFAULT_CAROUSEL_INDICATOR_PADDING = (DEFAULT_CAROUSEL_INDICATOR_SIZE * 5) / 3;
|
|
6
|
+
/**
|
|
7
|
+
* Parse and assign appropriate button container and text style from style objects params
|
|
8
|
+
*
|
|
9
|
+
* @param {MessageButtonStyleParams} params - message styleParams and button type
|
|
10
|
+
* @returns {MessageButtonStyleProps} resolved button container and text style arrays
|
|
11
|
+
*/
|
|
12
|
+
export const getComponentButtonStyle = ({ styleParams, buttonType, }) => {
|
|
13
|
+
const { defaultStyle, payloadStyle, overrideStyle } = styleParams;
|
|
14
|
+
// default component styles defined at the UI component level
|
|
15
|
+
const { buttonContainer: containerDefaultStyle = {}, buttonText: textDefaultStyle = {}, } = defaultStyle ?? {};
|
|
16
|
+
// message specific styles in the in-app message payload, overrides default component styles
|
|
17
|
+
const { backgroundColor, borderRadius, color } = payloadStyle?.[buttonType] ?? {};
|
|
18
|
+
const containePayloadStyle = {
|
|
19
|
+
...(backgroundColor ? { backgroundColor } : null),
|
|
20
|
+
...(borderRadius ? { borderRadius } : null),
|
|
21
|
+
};
|
|
22
|
+
const textMessageStyle = { ...(color ? { color } : null) };
|
|
23
|
+
// custom component override styles passed as style prop, overrides all previous styles
|
|
24
|
+
const { container: containerOverrideStyle = {}, text: textOverrideStyle = {}, } = overrideStyle?.[buttonType] ?? {};
|
|
25
|
+
return {
|
|
26
|
+
// the style prop of the React Native Pressable component used in the message UI accepts either a ViewStyle array
|
|
27
|
+
// or a function receiving a boolean reflecting whether the component is currently pressed, returning a ViewStyle
|
|
28
|
+
// array. Utilizing the latter, we add an opacity value to the UI message button style during press events
|
|
29
|
+
container: ({ pressed } = { pressed: false }) => {
|
|
30
|
+
// default button press interaction opacity
|
|
31
|
+
const pressedOpacity = pressed ? { opacity: BUTTON_PRESSED_OPACITY } : {};
|
|
32
|
+
// pass `pressed` to containerOverrideStyle and evaluate if the consumer passed a function for custom
|
|
33
|
+
// button style
|
|
34
|
+
const containerOverrideFinalStyle = typeof containerOverrideStyle === 'function'
|
|
35
|
+
? containerOverrideStyle({ pressed })
|
|
36
|
+
: containerOverrideStyle;
|
|
37
|
+
return [
|
|
38
|
+
pressedOpacity,
|
|
39
|
+
containerDefaultStyle,
|
|
40
|
+
containePayloadStyle,
|
|
41
|
+
containerOverrideFinalStyle,
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
text: [textDefaultStyle, textMessageStyle, textOverrideStyle],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Utility for determining if the provided layout requires filling the entire device screen.
|
|
49
|
+
*
|
|
50
|
+
* @param {InAppMessageLayout} layout - message layout
|
|
51
|
+
* @returns {Boolean} boolean indicating whether entire screen should be filled
|
|
52
|
+
*/
|
|
53
|
+
export const shouldFillDeviceScreen = (layout) => {
|
|
54
|
+
switch (layout) {
|
|
55
|
+
case 'CAROUSEL':
|
|
56
|
+
case 'FULL_SCREEN': {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
case 'MODAL':
|
|
60
|
+
case 'TOP_BANNER':
|
|
61
|
+
case 'MIDDLE_BANNER':
|
|
62
|
+
case 'BOTTOM_BANNER':
|
|
63
|
+
default: {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Parse and assign appropriate message container and wrapper style from style params
|
|
70
|
+
*
|
|
71
|
+
* @param {MessageStyleParams} params - message styleParams, layout, and device orientation
|
|
72
|
+
* @returns {ContainerAndWrapperStyle} resolved containerStyle and wrapperStyle
|
|
73
|
+
*/
|
|
74
|
+
export const getContainerAndWrapperStyle = ({ styleParams, layout, }) => {
|
|
75
|
+
const { defaultStyle, payloadStyle, overrideStyle } = styleParams;
|
|
76
|
+
const containerDefaultStyle = defaultStyle?.container ?? {};
|
|
77
|
+
const containerPayloadStyle = payloadStyle?.container ?? {};
|
|
78
|
+
const containerOverrideStyle = overrideStyle?.container ?? {};
|
|
79
|
+
const wrapperDefaultStyle = defaultStyle?.wrapper ?? {};
|
|
80
|
+
if (!shouldFillDeviceScreen(layout)) {
|
|
81
|
+
return {
|
|
82
|
+
wrapper: wrapperDefaultStyle,
|
|
83
|
+
container: [
|
|
84
|
+
containerDefaultStyle,
|
|
85
|
+
containerPayloadStyle,
|
|
86
|
+
containerOverrideStyle,
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// in non-banner and landscape modal layouts container backgroundColor values should be applied as
|
|
91
|
+
// wrapper style to ensure that the backgroundColor is applied to the entire screen
|
|
92
|
+
const { backgroundColor: defaultBackgroundColor, ...restContainerDefaultStyle } = containerDefaultStyle;
|
|
93
|
+
const { backgroundColor: messageBackgroundColor, ...restContainerPayloadStyle } = containerPayloadStyle;
|
|
94
|
+
// flatten overrideStyle to access override backgroundColor
|
|
95
|
+
const { backgroundColor: overrideBackgroundColor, ...restContainerOverrideStyle } = StyleSheet.flatten(containerOverrideStyle);
|
|
96
|
+
// all non-backgroundColor container override style are applied to the container View
|
|
97
|
+
const container = [
|
|
98
|
+
restContainerDefaultStyle,
|
|
99
|
+
restContainerPayloadStyle,
|
|
100
|
+
restContainerOverrideStyle,
|
|
101
|
+
];
|
|
102
|
+
// use ternaries to prevent passing backgroundColor object with undefined or null value
|
|
103
|
+
const wrapper = [
|
|
104
|
+
wrapperDefaultStyle,
|
|
105
|
+
defaultBackgroundColor ? { backgroundColor: defaultBackgroundColor } : {},
|
|
106
|
+
messageBackgroundColor ? { backgroundColor: messageBackgroundColor } : {},
|
|
107
|
+
overrideBackgroundColor ? { backgroundColor: overrideBackgroundColor } : {},
|
|
108
|
+
];
|
|
109
|
+
return { wrapper, container };
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Utility for extracting message payload style
|
|
113
|
+
*
|
|
114
|
+
* @param {MessageComponentBaseProps} props - message props
|
|
115
|
+
* @returns {Object} message payload specific style
|
|
116
|
+
*/
|
|
117
|
+
export const getPayloadStyle = ({ body, container, header, primaryButton, secondaryButton, }) => ({
|
|
118
|
+
body: body?.style ?? {},
|
|
119
|
+
container: container?.style ?? {},
|
|
120
|
+
header: header?.style ?? {},
|
|
121
|
+
primaryButton: primaryButton?.style ?? {},
|
|
122
|
+
secondaryButton: secondaryButton?.style ?? {},
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Receives message styling and returns style property values for use with in-app message
|
|
126
|
+
* UI components. Handles resolvement style precedence between default, payload, and custom style
|
|
127
|
+
*
|
|
128
|
+
* Style param resolve precedence from lowest to highest:
|
|
129
|
+
* 1. defaultStyle
|
|
130
|
+
* 2. messageStyle
|
|
131
|
+
* 3. overrideStyle
|
|
132
|
+
*
|
|
133
|
+
* @param {MessageStyleParams} params - message style params, layout, and device orientation
|
|
134
|
+
* @returns {MessageStyles} message style props
|
|
135
|
+
*/
|
|
136
|
+
export function getMessageStyles({ styleParams, layout, }) {
|
|
137
|
+
// view style applied to the wrapper and primary container views
|
|
138
|
+
const { wrapper, container } = getContainerAndWrapperStyle({
|
|
139
|
+
styleParams,
|
|
140
|
+
layout,
|
|
141
|
+
});
|
|
142
|
+
// primary and secondary button container and text style
|
|
143
|
+
const primaryButton = getComponentButtonStyle({
|
|
144
|
+
styleParams,
|
|
145
|
+
buttonType: 'primaryButton',
|
|
146
|
+
});
|
|
147
|
+
const secondaryButton = getComponentButtonStyle({
|
|
148
|
+
styleParams,
|
|
149
|
+
buttonType: 'secondaryButton',
|
|
150
|
+
});
|
|
151
|
+
const { defaultStyle, payloadStyle, overrideStyle } = styleParams;
|
|
152
|
+
// image style composed of default and override style
|
|
153
|
+
const image = [defaultStyle?.image, overrideStyle?.image];
|
|
154
|
+
const iconButton = {
|
|
155
|
+
// view style applied to icon button
|
|
156
|
+
container: [defaultStyle?.iconButton, overrideStyle?.closeIconButton],
|
|
157
|
+
// close icon color, only specified as an overrideStyle
|
|
158
|
+
iconColor: overrideStyle?.closeIconColor,
|
|
159
|
+
};
|
|
160
|
+
// text style applied to message body and header respectively
|
|
161
|
+
const body = [defaultStyle?.body, payloadStyle?.body, overrideStyle?.body];
|
|
162
|
+
const header = [
|
|
163
|
+
defaultStyle?.header,
|
|
164
|
+
payloadStyle?.header,
|
|
165
|
+
overrideStyle?.header,
|
|
166
|
+
];
|
|
167
|
+
const { buttonsContainer, contentContainer, imageContainer, textContainer } = defaultStyle ?? {};
|
|
168
|
+
const styleProps = {
|
|
169
|
+
body,
|
|
170
|
+
buttonsContainer,
|
|
171
|
+
wrapper,
|
|
172
|
+
contentContainer,
|
|
173
|
+
container,
|
|
174
|
+
header,
|
|
175
|
+
iconButton,
|
|
176
|
+
image,
|
|
177
|
+
imageContainer,
|
|
178
|
+
primaryButton,
|
|
179
|
+
secondaryButton,
|
|
180
|
+
textContainer,
|
|
181
|
+
};
|
|
182
|
+
if (layout === 'CAROUSEL') {
|
|
183
|
+
styleProps.container = [
|
|
184
|
+
styleProps.container,
|
|
185
|
+
// Add bottom padding for carousel page indicators
|
|
186
|
+
{
|
|
187
|
+
paddingBottom: SPACING_EXTRA_LARGE + DEFAULT_CAROUSEL_INDICATOR_PADDING,
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
return styleProps;
|
|
192
|
+
}
|