-
Notifications
You must be signed in to change notification settings - Fork 40
[MOB-12272] banner-component #750
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
Draft
lposen
wants to merge
4
commits into
loren/embedded/MOB-12271-notification-component
Choose a base branch
from
loren/embedded/MOB-12272-banner-component
base: loren/embedded/MOB-12271-notification-component
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3204df3
refactor: restructure IterableEmbeddedBanner component and update imp…
lposen b3aef75
feat: add message click handling to IterableEmbeddedBanner component
lposen b781e90
fix: update IMAGE_HEIGHT and IMAGE_WIDTH for platform-specific stylin…
lposen 1086555
refactor: remove unused session management and impression handling co…
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 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
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/embedded/components/IterableEmbeddedBanner/IterableEmbeddedBanner.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,88 @@ | ||
| import { StyleSheet, Platform } from 'react-native'; | ||
| import { | ||
| embeddedMediaImageBackgroundColors, | ||
| embeddedMediaImageBorderColors, | ||
| } from '../../constants/embeddedViewDefaults'; | ||
|
|
||
| // See https://support.iterable.com/hc/en-us/articles/23230946708244-Out-of-the-Box-Views-for-Embedded-Messages#banners | ||
| export const IMAGE_HEIGHT = Platform.OS === 'android' ? 80 : 100; | ||
| export const IMAGE_WIDTH = Platform.OS === 'android' ? 80 : 100; | ||
|
|
||
| export const styles = StyleSheet.create({ | ||
| body: { | ||
| alignSelf: 'stretch', | ||
| fontSize: 14, | ||
| fontWeight: '400', | ||
| lineHeight: 20, | ||
| }, | ||
| bodyContainer: { | ||
| alignItems: 'center', | ||
| alignSelf: 'stretch', | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| paddingTop: 4, | ||
| }, | ||
| button: { | ||
| borderRadius: 32, | ||
| gap: 8, | ||
| }, | ||
| buttonContainer: { | ||
| alignItems: 'flex-start', | ||
| alignSelf: 'stretch', | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| gap: 12, | ||
| width: '100%', | ||
| }, | ||
| buttonText: { | ||
| fontSize: 14, | ||
| fontWeight: '400', | ||
| lineHeight: 20, | ||
| paddingHorizontal: 12, | ||
| paddingVertical: 8, | ||
| }, | ||
| 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: 16, | ||
| justifyContent: 'center', | ||
| padding: 16, | ||
| width: '100%', | ||
| }, | ||
| mediaContainer: { | ||
| alignItems: 'flex-start', | ||
| alignSelf: 'stretch', | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| }, | ||
| mediaImage: { | ||
| backgroundColor: embeddedMediaImageBackgroundColors.banner, | ||
| borderColor: embeddedMediaImageBorderColors.banner, | ||
| borderRadius: 6, | ||
| borderStyle: 'solid', | ||
| borderWidth: 1, | ||
| height: IMAGE_HEIGHT, | ||
| paddingHorizontal: 0, | ||
| paddingVertical: 0, | ||
| width: IMAGE_WIDTH, | ||
| }, | ||
| textContainer: { | ||
| alignSelf: 'center', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| flexGrow: 1, | ||
| flexShrink: 1, | ||
| gap: 4, | ||
| width: '100%', | ||
| }, | ||
| title: { | ||
| fontSize: 16, | ||
| fontWeight: '700', | ||
| lineHeight: 16, | ||
| paddingBottom: 4, | ||
| }, | ||
| }); |
124 changes: 124 additions & 0 deletions
124
src/embedded/components/IterableEmbeddedBanner/IterableEmbeddedBanner.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,124 @@ | ||
| import { | ||
| Image, | ||
| Text, | ||
| TouchableOpacity, | ||
| View, | ||
| type TextStyle, | ||
| type ViewStyle, | ||
| PixelRatio, | ||
| Pressable, | ||
| } from 'react-native'; | ||
|
|
||
| import { IterableEmbeddedViewType } from '../../enums'; | ||
| import { useEmbeddedView } from '../../hooks/useEmbeddedView'; | ||
| import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps'; | ||
| import { | ||
| styles, | ||
| IMAGE_HEIGHT, | ||
| IMAGE_WIDTH, | ||
| } from './IterableEmbeddedBanner.styles'; | ||
|
|
||
| /** | ||
| * TODO: figure out how default action works. | ||
| */ | ||
|
|
||
| export const IterableEmbeddedBanner = ({ | ||
| config, | ||
| message, | ||
| onButtonClick = () => {}, | ||
| onMessageClick = () => {}, | ||
| }: IterableEmbeddedComponentProps) => { | ||
| const { parsedStyles, media, handleButtonClick, handleMessageClick } = | ||
| useEmbeddedView(IterableEmbeddedViewType.Banner, { | ||
| 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, | ||
| ]} | ||
| > | ||
| {} | ||
| <View | ||
| // eslint-disable-next-line react-native/no-inline-styles | ||
| style={[styles.bodyContainer, { gap: media.shouldShow ? 16 : 0 }]} | ||
| > | ||
| <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> | ||
| {media.shouldShow && ( | ||
| <View style={styles.mediaContainer}> | ||
| <Image | ||
| source={{ | ||
| uri: media.url as string, | ||
| width: PixelRatio.getPixelSizeForLayoutSize(IMAGE_WIDTH), | ||
| height: PixelRatio.getPixelSizeForLayoutSize(IMAGE_HEIGHT), | ||
| }} | ||
| style={styles.mediaImage} | ||
| alt={media.caption as string} | ||
| /> | ||
| </View> | ||
| )} | ||
| </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> | ||
|
Comment on lines
+90
to
+119
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. |
||
| )} | ||
| </View> | ||
| </Pressable> | ||
| ); | ||
|
Comment on lines
+25
to
+123
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 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 './IterableEmbeddedBanner'; |
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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export * from './IterableEmbeddedBanner'; | ||
| export * from './IterableEmbeddedBanner/IterableEmbeddedBanner'; | ||
| export * from './IterableEmbeddedCard'; | ||
| export * from './IterableEmbeddedNotification/IterableEmbeddedNotification'; | ||
| export * from './IterableEmbeddedView'; |
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.
Found 19 lines of similar code in 2 locations (mass = 65) [qlty:similar-code]