-
Notifications
You must be signed in to change notification settings - Fork 39
[MOB-12273] add IterableEmbeddedCard #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: loren/embedded/MOB-12272-banner-component
Are you sure you want to change the base?
[MOB-12273] add IterableEmbeddedCard #752
Conversation
…ionality for embedded messaging
Diff Coverage: The code coverage on the diff in this pull request is 35.7%. Total Coverage: This PR will increase coverage by 0.08%. File Coverage Changes
🛟 Help
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more. |
3 new issues
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more. |
export const IterableEmbeddedCard = ({ | ||
config, | ||
message, | ||
onButtonClick = () => {}, | ||
onMessageClick = () => {}, | ||
}: IterableEmbeddedComponentProps) => { | ||
const { | ||
componentRef, | ||
handleButtonClick, | ||
handleLayout, | ||
handleMessageClick, | ||
media, | ||
parsedStyles, | ||
} = useEmbeddedView(IterableEmbeddedViewType.Card, { | ||
message, | ||
config, | ||
onButtonClick, | ||
onMessageClick, | ||
}); | ||
const buttons = message?.elements?.buttons ?? []; | ||
|
||
return ( | ||
<Pressable onPress={() => handleMessageClick()}> | ||
<View | ||
ref={componentRef} | ||
focusable={true} | ||
removeClippedSubviews={true} | ||
onLayout={handleLayout} | ||
style={[ | ||
styles.container, | ||
{ | ||
backgroundColor: parsedStyles.backgroundColor, | ||
borderColor: parsedStyles.borderColor, | ||
borderRadius: parsedStyles.borderCornerRadius, | ||
borderWidth: parsedStyles.borderWidth, | ||
} as ViewStyle, | ||
]} | ||
> | ||
<View | ||
style={[ | ||
styles.mediaContainer, | ||
media.shouldShow ? {} : styles.mediaContainerNoImage, | ||
]} | ||
> | ||
<Image | ||
source={ | ||
media.shouldShow | ||
? { | ||
uri: media.url as string, | ||
height: PixelRatio.getPixelSizeForLayoutSize(IMAGE_HEIGHT), | ||
} | ||
: // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
require('../../../core/images/logo-grey.png') | ||
} | ||
style={ | ||
media.shouldShow | ||
? styles.mediaImage | ||
: styles.mediaImagePlaceholder | ||
} | ||
alt={media.caption as string} | ||
/> | ||
</View> | ||
<View style={styles.bodyContainer}> | ||
<View style={styles.textContainer}> | ||
<Text | ||
style={[ | ||
styles.title, | ||
{ color: parsedStyles.titleTextColor } as TextStyle, | ||
]} | ||
> | ||
{message.elements?.title} | ||
</Text> | ||
<Text | ||
style={[ | ||
styles.body, | ||
{ color: parsedStyles.bodyTextColor } as TextStyle, | ||
]} | ||
> | ||
{message.elements?.body} | ||
</Text> | ||
</View> | ||
{buttons.length > 0 && ( | ||
<View style={styles.buttonContainer}> | ||
{buttons.map((button, index) => { | ||
const backgroundColor = | ||
index === 0 | ||
? parsedStyles.primaryBtnBackgroundColor | ||
: parsedStyles.secondaryBtnBackgroundColor; | ||
const textColor = | ||
index === 0 | ||
? parsedStyles.primaryBtnTextColor | ||
: parsedStyles.secondaryBtnTextColor; | ||
return ( | ||
<TouchableOpacity | ||
style={[styles.button, { backgroundColor } as ViewStyle]} | ||
onPress={() => handleButtonClick(button)} | ||
key={button.id} | ||
> | ||
<Text | ||
style={[ | ||
styles.buttonText, | ||
{ color: textColor } as TextStyle, | ||
]} | ||
> | ||
{button.title} | ||
</Text> | ||
</TouchableOpacity> | ||
); | ||
})} | ||
</View> | ||
)} | ||
</View> | ||
</View> | ||
</Pressable> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<View style={styles.bodyContainer}> | ||
<View style={styles.textContainer}> | ||
<Text | ||
style={[ | ||
styles.title, | ||
{ color: parsedStyles.titleTextColor } as TextStyle, | ||
]} | ||
> | ||
{message.elements?.title} | ||
</Text> | ||
<Text | ||
style={[ | ||
styles.body, | ||
{ color: parsedStyles.bodyTextColor } as TextStyle, | ||
]} | ||
> | ||
{message.elements?.body} | ||
</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</View> | ||
{buttons.length > 0 && ( | ||
<View style={styles.buttonContainer}> | ||
{buttons.map((button, index) => { | ||
const backgroundColor = | ||
index === 0 | ||
? parsedStyles.primaryBtnBackgroundColor | ||
: parsedStyles.secondaryBtnBackgroundColor; | ||
const textColor = | ||
index === 0 | ||
? parsedStyles.primaryBtnTextColor | ||
: parsedStyles.secondaryBtnTextColor; | ||
return ( | ||
<TouchableOpacity | ||
style={[styles.button, { backgroundColor } as ViewStyle]} | ||
onPress={() => handleButtonClick(button)} | ||
key={button.id} | ||
> | ||
<Text | ||
style={[ | ||
styles.buttonText, | ||
{ color: textColor } as TextStyle, | ||
]} | ||
> | ||
{button.title} | ||
</Text> | ||
</TouchableOpacity> | ||
); | ||
})} | ||
</View> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔹 JIRA Ticket(s) if any
✏️ Description
Created IterableEmbeddedCard component