66 type TextStyle ,
77 type ViewStyle ,
88 PixelRatio ,
9+ Pressable ,
910} from 'react-native' ;
1011
1112import { IterableEmbeddedViewType } from '../../enums' ;
@@ -25,87 +26,99 @@ export const IterableEmbeddedBanner = ({
2526 config,
2627 message,
2728 onButtonClick = ( ) => { } ,
29+ onMessageClick = ( ) => { } ,
2830} : IterableEmbeddedComponentProps ) => {
29- const { parsedStyles, media, handleButtonClick } = useEmbeddedView (
30- IterableEmbeddedViewType . Banner ,
31- { message, config, onButtonClick }
32- ) ;
31+ const { parsedStyles, media, handleButtonClick, handleMessageClick } =
32+ useEmbeddedView ( IterableEmbeddedViewType . Banner , {
33+ message,
34+ config,
35+ onButtonClick,
36+ onMessageClick,
37+ } ) ;
3338
3439 const buttons = message . elements ?. buttons ?? [ ] ;
3540
3641 return (
37- < View
38- style = { [
39- styles . container ,
40- {
41- backgroundColor : parsedStyles . backgroundColor ,
42- borderColor : parsedStyles . borderColor ,
43- borderRadius : parsedStyles . borderCornerRadius ,
44- borderWidth : parsedStyles . borderWidth ,
45- } as ViewStyle ,
46- ] }
47- >
48- { /* eslint-disable-next-line react-native/no-inline-styles */ }
49- < View style = { [ styles . bodyContainer , { gap : media . shouldShow ? 16 : 0 } ] } >
50- < View style = { styles . textContainer } >
51- < Text
52- style = { [
53- styles . title ,
54- { color : parsedStyles . titleTextColor } as TextStyle ,
55- ] }
56- >
57- { message . elements ?. title }
58- </ Text >
59- < Text
60- style = { [
61- styles . body ,
62- { color : parsedStyles . bodyTextColor } as TextStyle ,
63- ] }
64- >
65- { message . elements ?. body }
66- </ Text >
42+ < Pressable onPress = { ( ) => handleMessageClick ( ) } >
43+ < View
44+ style = { [
45+ styles . container ,
46+ {
47+ backgroundColor : parsedStyles . backgroundColor ,
48+ borderColor : parsedStyles . borderColor ,
49+ borderRadius : parsedStyles . borderCornerRadius ,
50+ borderWidth : parsedStyles . borderWidth ,
51+ } as ViewStyle ,
52+ ] }
53+ >
54+ { }
55+ < View
56+ // eslint-disable-next-line react-native/no-inline-styles
57+ style = { [ styles . bodyContainer , { gap : media . shouldShow ? 16 : 0 } ] }
58+ >
59+ < View style = { styles . textContainer } >
60+ < Text
61+ style = { [
62+ styles . title ,
63+ { color : parsedStyles . titleTextColor } as TextStyle ,
64+ ] }
65+ >
66+ { message . elements ?. title }
67+ </ Text >
68+ < Text
69+ style = { [
70+ styles . body ,
71+ { color : parsedStyles . bodyTextColor } as TextStyle ,
72+ ] }
73+ >
74+ { message . elements ?. body }
75+ </ Text >
76+ </ View >
77+ { media . shouldShow && (
78+ < View style = { styles . mediaContainer } >
79+ < Image
80+ source = { {
81+ uri : media . url as string ,
82+ width : PixelRatio . getPixelSizeForLayoutSize ( IMAGE_WIDTH ) ,
83+ height : PixelRatio . getPixelSizeForLayoutSize ( IMAGE_HEIGHT ) ,
84+ } }
85+ style = { styles . mediaImage }
86+ alt = { media . caption as string }
87+ />
88+ </ View >
89+ ) }
6790 </ View >
68- { media . shouldShow && (
69- < View style = { styles . mediaContainer } >
70- < Image
71- source = { {
72- uri : media . url as string ,
73- width : PixelRatio . getPixelSizeForLayoutSize ( IMAGE_WIDTH ) ,
74- height : PixelRatio . getPixelSizeForLayoutSize ( IMAGE_HEIGHT ) ,
75- } }
76- style = { styles . mediaImage }
77- alt = { media . caption as string }
78- />
91+ { buttons . length > 0 && (
92+ < View style = { styles . buttonContainer } >
93+ { buttons . map ( ( button , index ) => {
94+ const backgroundColor =
95+ index === 0
96+ ? parsedStyles . primaryBtnBackgroundColor
97+ : parsedStyles . secondaryBtnBackgroundColor ;
98+ const textColor =
99+ index === 0
100+ ? parsedStyles . primaryBtnTextColor
101+ : parsedStyles . secondaryBtnTextColor ;
102+ return (
103+ < TouchableOpacity
104+ style = { [ styles . button , { backgroundColor } as ViewStyle ] }
105+ onPress = { ( ) => handleButtonClick ( button ) }
106+ key = { button . id }
107+ >
108+ < Text
109+ style = { [
110+ styles . buttonText ,
111+ { color : textColor } as TextStyle ,
112+ ] }
113+ >
114+ { button . title }
115+ </ Text >
116+ </ TouchableOpacity >
117+ ) ;
118+ } ) }
79119 </ View >
80120 ) }
81121 </ View >
82- { buttons . length > 0 && (
83- < View style = { styles . buttonContainer } >
84- { buttons . map ( ( button , index ) => {
85- const backgroundColor =
86- index === 0
87- ? parsedStyles . primaryBtnBackgroundColor
88- : parsedStyles . secondaryBtnBackgroundColor ;
89- const textColor =
90- index === 0
91- ? parsedStyles . primaryBtnTextColor
92- : parsedStyles . secondaryBtnTextColor ;
93- return (
94- < TouchableOpacity
95- style = { [ styles . button , { backgroundColor } as ViewStyle ] }
96- onPress = { ( ) => handleButtonClick ( button ) }
97- key = { button . id }
98- >
99- < Text
100- style = { [ styles . buttonText , { color : textColor } as TextStyle ] }
101- >
102- { button . title }
103- </ Text >
104- </ TouchableOpacity >
105- ) ;
106- } ) }
107- </ View >
108- ) }
109- </ View >
122+ </ Pressable >
110123 ) ;
111124} ;
0 commit comments