-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathIterableEmbeddedView.tsx
More file actions
85 lines (79 loc) · 2.87 KB
/
Copy pathIterableEmbeddedView.tsx
File metadata and controls
85 lines (79 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useMemo } from 'react';
import { View, Text } from 'react-native';
import { IterableEmbeddedViewType } from '../enums/IterableEmbeddedViewType';
import { IterableEmbeddedBanner } from './IterableEmbeddedBanner';
import { IterableEmbeddedCard } from './IterableEmbeddedCard';
import { IterableEmbeddedNotification } from './IterableEmbeddedNotification';
import type { IterableEmbeddedComponentProps } from '../types/IterableEmbeddedComponentProps';
import { useEmbeddedView } from '../hooks/useEmbeddedView/useEmbeddedView';
/**
* The props for the IterableEmbeddedView component.
*/
interface IterableEmbeddedViewProps extends IterableEmbeddedComponentProps {
/** The type of view to render. */
viewType: IterableEmbeddedViewType;
}
/**
*
* @param viewType - The type of view to render.
* @param message - The message to render.
* @param config - The config for the IterableEmbeddedView component, most likely used to style the view.
* @param onButtonClick - The function to call when a button is clicked.
* @returns The IterableEmbeddedView component.
*
* This component is used to render pre-created, customizable message displays
* included with Iterables RN SDK: cards, banners, and notifications.
*/
export const IterableEmbeddedView = ({
viewType,
...props
}: IterableEmbeddedViewProps) => {
const Cmp = useMemo(() => {
switch (viewType) {
case IterableEmbeddedViewType.Card:
return IterableEmbeddedCard;
case IterableEmbeddedViewType.Notification:
return IterableEmbeddedNotification;
case IterableEmbeddedViewType.Banner:
return IterableEmbeddedBanner;
default:
return null;
}
}, [viewType]);
const { parsedStyles } = useEmbeddedView(viewType, props);
return Cmp ? (
<View>
<Text>
parsedStyles.backgroundColor: {String(parsedStyles.backgroundColor)}
</Text>
<Text>parsedStyles.borderColor: {String(parsedStyles.borderColor)}</Text>
<Text>parsedStyles.borderWidth: {parsedStyles.borderWidth}</Text>
<Text>
parsedStyles.borderCornerRadius: {parsedStyles.borderCornerRadius}
</Text>
<Text>
parsedStyles.primaryBtnBackgroundColor:{' '}
{String(parsedStyles.primaryBtnBackgroundColor)}
</Text>
<Text>
parsedStyles.primaryBtnTextColor:{' '}
{String(parsedStyles.primaryBtnTextColor)}
</Text>
<Text>
parsedStyles.secondaryBtnBackgroundColor:{' '}
{String(parsedStyles.secondaryBtnBackgroundColor)}
</Text>
<Text>
parsedStyles.secondaryBtnTextColor:{' '}
{String(parsedStyles.secondaryBtnTextColor)}
</Text>
<Text>
parsedStyles.titleTextColor: {String(parsedStyles.titleTextColor)}
</Text>
<Text>
parsedStyles.bodyTextColor: {String(parsedStyles.bodyTextColor)}
</Text>
<Cmp {...props} />
</View>
) : null;
};