-
Notifications
You must be signed in to change notification settings - Fork 44
[SDK-248] notification-component #814
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
Merged
lposen
merged 16 commits into
emb-ootb/master
from
loren/embedded/SDK-248-notification-component
Mar 13, 2026
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
95e8d92
feat: add IterableEmbeddedNotification component for displaying notif…
lposen ef7cf1d
feat: add utility functions and styles for embedded views
lposen 980123d
feat: implement useEmbeddedView hook for managing embedded view lifec…
lposen 917835b
feat: enhance IterableEmbeddedNotification with styles and button fun…
lposen 4a47ef2
feat: add hooks for managing embedded view styles and media
lposen f0cdd24
Merge branch 'loren/embedded/SDK-367-parse-media-for-components' into…
lposen 8df3131
test: add unit tests for IterableEmbeddedNotification component
lposen 47a283d
refactor: remove media display logic
lposen 7278e0c
test: add unit tests for useEmbeddedView hook functionality
lposen 4b2dff4
Merge branch 'loren/embedded/SDK-367-parse-media-for-components' into…
lposen 4623abe
Merge branch 'emb-ootb/master' into loren/embedded/SDK-248-notificati…
lposen 82b2cda
feat: enhance IterableEmbeddedNotification styles with shadow propert…
lposen 7890401
Merge branch 'emb-ootb/master' into loren/embedded/SDK-248-notificati…
lposen 094fa0c
Merge branch 'emb-ootb/master' into loren/embedded/SDK-248-notificati…
lposen 028323f
refactor: update default props for onButtonClick and onMessageClick i…
lposen 9b76334
Apply suggestion from @joaodordio
lposen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/embedded/components/IterableEmbeddedNotification/IterableEmbeddedNotification.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { StyleSheet } from 'react-native'; | ||
|
|
||
| export const styles = StyleSheet.create({ | ||
| body: { | ||
| alignSelf: 'stretch', | ||
| fontSize: 14, | ||
| fontWeight: '400', | ||
| lineHeight: 20, | ||
| }, | ||
| bodyContainer: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| flexGrow: 1, | ||
| flexShrink: 1, | ||
| gap: 4, | ||
| width: '100%', | ||
| }, | ||
| button: { | ||
| borderRadius: 32, | ||
| gap: 8, | ||
| paddingHorizontal: 12, | ||
| paddingVertical: 8, | ||
| }, | ||
| buttonContainer: { | ||
| alignItems: 'flex-start', | ||
| alignSelf: 'stretch', | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| gap: 12, | ||
| width: '100%', | ||
| }, | ||
| buttonText: { | ||
| fontSize: 14, | ||
| fontWeight: '700', | ||
| lineHeight: 20, | ||
| }, | ||
| container: { | ||
| alignItems: 'flex-start', | ||
| borderStyle: 'solid', | ||
| boxShadow: | ||
| '0 1px 1px 0 rgba(0, 0, 0, 0.06), 0 0 2px 0 rgba(0, 0, 0, 0.06), 0 0 1px 0 rgba(0, 0, 0, 0.08)', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: 8, | ||
| justifyContent: 'center', | ||
| padding: 16, | ||
| width: '100%', | ||
| }, | ||
| title: { | ||
| fontSize: 16, | ||
| fontWeight: '700', | ||
| lineHeight: 24, | ||
| }, | ||
| }); | ||
96 changes: 96 additions & 0 deletions
96
src/embedded/components/IterableEmbeddedNotification/IterableEmbeddedNotification.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { | ||
| Text, | ||
| TouchableOpacity, | ||
| View, | ||
| type TextStyle, | ||
| type ViewStyle, | ||
| Pressable, | ||
| } from 'react-native'; | ||
|
|
||
| import { IterableEmbeddedViewType } from '../../enums/IterableEmbeddedViewType'; | ||
| import { useEmbeddedView } from '../../hooks/useEmbeddedView'; | ||
| import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps'; | ||
| import { styles } from './IterableEmbeddedNotification.styles'; | ||
|
|
||
| export const IterableEmbeddedNotification = ({ | ||
| config, | ||
| message, | ||
| onButtonClick = () => {}, | ||
| onMessageClick = () => {}, | ||
| }: IterableEmbeddedComponentProps) => { | ||
| const { parsedStyles, handleButtonClick, handleMessageClick } = | ||
| useEmbeddedView(IterableEmbeddedViewType.Notification, { | ||
| message, | ||
| config, | ||
| onButtonClick, | ||
| onMessageClick, | ||
| }); | ||
|
|
||
| const buttons = message.elements?.buttons ?? []; | ||
|
|
||
| return ( | ||
| <Pressable onPress={() => handleMessageClick()}> | ||
| <View | ||
| style={[ | ||
| styles.container, | ||
| { | ||
| backgroundColor: parsedStyles.backgroundColor, | ||
| borderColor: parsedStyles.borderColor, | ||
| borderRadius: parsedStyles.borderCornerRadius, | ||
| borderWidth: parsedStyles.borderWidth, | ||
| } as ViewStyle, | ||
| ]} | ||
| > | ||
| {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be removed |
||
| <View style={styles.bodyContainer}> | ||
| <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> | ||
| </Pressable> | ||
| ); | ||
|
qltysh[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }; | ||
2 changes: 2 additions & 0 deletions
2
src/embedded/components/IterableEmbeddedNotification/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './IterableEmbeddedNotification'; | ||
| export { IterableEmbeddedNotification as default } from './IterableEmbeddedNotification'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './useEmbeddedView'; |
85 changes: 85 additions & 0 deletions
85
src/embedded/hooks/useEmbeddedView/embeddedViewDefaults.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| export const embeddedBackgroundColors = { | ||
| notification: '#ffffff', | ||
| card: '#ffffff', | ||
| banner: '#ffffff', | ||
| }; | ||
|
|
||
| export const embeddedBorderColors = { | ||
| notification: '#E0DEDF', | ||
| card: '#E0DEDF', | ||
| banner: '#E0DEDF', | ||
| }; | ||
|
|
||
| export const embeddedPrimaryBtnBackgroundColors = { | ||
| notification: '#6A266D', | ||
| card: 'transparent', | ||
| banner: '#6A266D', | ||
| }; | ||
|
|
||
| export const embeddedPrimaryBtnTextColors = { | ||
| notification: '#ffffff', | ||
| card: '#79347F', | ||
| banner: '#ffffff', | ||
| }; | ||
|
|
||
| export const embeddedSecondaryBtnBackgroundColors = { | ||
| notification: 'transparent', | ||
| card: 'transparent', | ||
| banner: 'transparent', | ||
| }; | ||
|
|
||
| export const embeddedSecondaryBtnTextColors = { | ||
| notification: '#79347F', | ||
| card: '#79347F', | ||
| banner: '#79347F', | ||
| }; | ||
|
|
||
| export const embeddedTitleTextColors = { | ||
| notification: '#3D3A3B', | ||
| card: '#3D3A3B', | ||
| banner: '#3D3A3B', | ||
| }; | ||
|
|
||
| export const embeddedBodyTextColors = { | ||
| notification: '#787174', | ||
| card: '#787174', | ||
| banner: '#787174', | ||
| }; | ||
|
|
||
| export const embeddedBorderRadius = { | ||
| notification: 8, | ||
| card: 6, | ||
| banner: 8, | ||
| }; | ||
|
|
||
| export const embeddedBorderWidth = { | ||
| notification: 1, | ||
| card: 1, | ||
| banner: 1, | ||
| }; | ||
|
|
||
| export const embeddedMediaImageBorderColors = { | ||
| notification: '#E0DEDF', | ||
| card: '#E0DEDF', | ||
| banner: '#E0DEDF', | ||
| }; | ||
|
|
||
| export const embeddedMediaImageBackgroundColors = { | ||
| notification: '#F5F4F4', | ||
| card: '#F5F4F4', | ||
| banner: '#F5F4F4', | ||
| }; | ||
|
|
||
| export const embeddedStyles = { | ||
| backgroundColor: embeddedBackgroundColors, | ||
| bodyText: embeddedBodyTextColors, | ||
| borderColor: embeddedBorderColors, | ||
| borderCornerRadius: embeddedBorderRadius, | ||
| borderWidth: embeddedBorderWidth, | ||
| mediaImageBorder: embeddedMediaImageBorderColors, | ||
| primaryBtnBackgroundColor: embeddedPrimaryBtnBackgroundColors, | ||
| primaryBtnTextColor: embeddedPrimaryBtnTextColors, | ||
| secondaryBtnBackground: embeddedSecondaryBtnBackgroundColors, | ||
| secondaryBtnTextColor: embeddedSecondaryBtnTextColors, | ||
| titleText: embeddedTitleTextColors, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { IterableEmbeddedMessage } from '../../types/IterableEmbeddedMessage'; | ||
| import { IterableEmbeddedViewType } from '../../enums'; | ||
|
|
||
| /** | ||
| * This function is used to get the media to render for a given embedded view | ||
| * type and message. | ||
| * | ||
| * @param viewType - The type of view to render. | ||
| * @param message - The message to render. | ||
| * @returns The media to render. | ||
| * | ||
| * @example | ||
| * const media = getMedia(IterableEmbeddedViewType.Notification, message); | ||
| * console.log(media); | ||
| */ | ||
| export const getMedia = ( | ||
| /** The type of view to render. */ | ||
| viewType: IterableEmbeddedViewType, | ||
| /** The message to render. */ | ||
| message: IterableEmbeddedMessage | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
| ) => { | ||
| if (viewType === IterableEmbeddedViewType.Notification) { | ||
| return { url: null, caption: null, shouldShow: false }; | ||
| } | ||
| const url = message.elements?.mediaUrl ?? null; | ||
| const caption = message.elements?.mediaUrlCaption ?? null; | ||
| const shouldShow = !!url && url.length > 0; | ||
| return { url, caption, shouldShow }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import type { IterableEmbeddedViewConfig } from '../../types/IterableEmbeddedViewConfig'; | ||
| import { embeddedStyles } from './embeddedViewDefaults'; | ||
| import { IterableEmbeddedViewType } from '../../enums'; | ||
|
|
||
| /** | ||
| * Get the default style for the embedded view type. | ||
| * | ||
| * @param viewType - The type of view to render. | ||
| * @param colors - The colors to use for the default style. | ||
| * @returns The default style. | ||
| */ | ||
| const getDefaultStyle = ( | ||
| viewType: IterableEmbeddedViewType, | ||
| colors: { | ||
| banner: number | string; | ||
| card: number | string; | ||
| notification: number | string; | ||
| } | ||
| ) => { | ||
| switch (viewType) { | ||
| case IterableEmbeddedViewType.Notification: | ||
| return colors.notification; | ||
| case IterableEmbeddedViewType.Card: | ||
| return colors.card; | ||
| default: | ||
| return colors.banner; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Get the style for the embedded view type. | ||
| * | ||
| * If a style is provided in the config, it will take precedence over the default style. | ||
| * | ||
| * @param viewType - The type of view to render. | ||
| * @param c - The config to use for the styles. | ||
| * @returns The styles. | ||
| * | ||
| * @example | ||
| * const styles = getStyles(IterableEmbeddedViewType.Notification, { | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
| * backgroundColor: '#000000', | ||
| * borderColor: '#000000', | ||
| * borderWidth: 1, | ||
| * borderCornerRadius: 10, | ||
| * primaryBtnBackgroundColor: '#000000', | ||
| * primaryBtnTextColor: '#000000', | ||
| * }); | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
| */ | ||
| export const getStyles = ( | ||
| viewType: IterableEmbeddedViewType, | ||
| c?: IterableEmbeddedViewConfig | null | ||
| ) => { | ||
| return { | ||
| backgroundColor: | ||
| c?.backgroundColor ?? | ||
| getDefaultStyle(viewType, embeddedStyles.backgroundColor), | ||
| borderColor: | ||
| c?.borderColor ?? getDefaultStyle(viewType, embeddedStyles.borderColor), | ||
| borderWidth: | ||
| c?.borderWidth ?? getDefaultStyle(viewType, embeddedStyles.borderWidth), | ||
| borderCornerRadius: | ||
| c?.borderCornerRadius ?? | ||
| getDefaultStyle(viewType, embeddedStyles.borderCornerRadius), | ||
| primaryBtnBackgroundColor: | ||
| c?.primaryBtnBackgroundColor ?? | ||
| getDefaultStyle(viewType, embeddedStyles.primaryBtnBackgroundColor), | ||
| primaryBtnTextColor: | ||
| c?.primaryBtnTextColor ?? | ||
| getDefaultStyle(viewType, embeddedStyles.primaryBtnTextColor), | ||
| secondaryBtnBackgroundColor: | ||
| c?.secondaryBtnBackgroundColor ?? | ||
| getDefaultStyle(viewType, embeddedStyles.secondaryBtnBackground), | ||
| secondaryBtnTextColor: | ||
| c?.secondaryBtnTextColor ?? | ||
| getDefaultStyle(viewType, embeddedStyles.secondaryBtnTextColor), | ||
| titleTextColor: | ||
| c?.titleTextColor ?? getDefaultStyle(viewType, embeddedStyles.titleText), | ||
| bodyTextColor: | ||
| c?.bodyTextColor ?? getDefaultStyle(viewType, embeddedStyles.bodyText), | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './useEmbeddedView'; | ||
| export { useEmbeddedView as default } from './useEmbeddedView'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AI flagged this as boxShadow not working in earlier versions than RN 0.76.
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.
Good call! Updating