Skip to content

Commit 2c9a954

Browse files
committed
refactor: create HeaderBackButton and replace back-arrow
1 parent 4308017 commit 2c9a954

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

src/inbox/components/HeaderBackButton.tsx

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,93 @@
11
import {
2+
Image,
3+
PixelRatio,
4+
Platform,
25
StyleSheet,
36
Text,
47
TouchableWithoutFeedback,
58
View,
9+
type ImageSourcePropType,
610
type TouchableWithoutFeedbackProps,
711
} from 'react-native';
8-
import { Icon } from 'react-native-vector-icons/Icon';
912
import { ITERABLE_INBOX_COLORS } from '../constants/colors';
1013

14+
// Base64 encoded back arrow icons
15+
// [Original image](https://github.com/react-navigation/react-navigation/blob/main/packages/elements/src/assets/back-icon%404x.ios.png)
16+
const backArrowLarge =
17+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAABUCAYAAADEZ7TLAAAC8ElEQVR42u2bWchOaxTH/xfnHMcZnHkwRobwJfdIkkSSkpKSEikREcla+81X5tR34c61O8kQIknmKUnGyCzzjczzz817Kfm+9dbasn/13P/X/1n72XuvZy2VGmeQnA1yrsh4LGe/DNda2qnUNPOdjBY572XwiXVeNZpUStbxvZyNMvjsci7Ud6Jk4o3NMvjCVStT2vwgY2srxCPnYHnEO9tl0Mr1WOmspZ2cHTJow7qY7fyPcnbJoI1rvdJoob2M3QHxr9RM/yznf5KxJyAeOQsyxe8NiS9YpRTW8LOMfUHnl2c5/4uMA0HnlymF1fwq53BIvLEky/kOco4G06ZQCqv4Tc7xoPOLs5z/XcaJoPhFSmElf8g5+XWe8yv4S86p4GkzLytt/pZzOuj8nCzn/5FzJuj8rCzn/5VzLiD+gwpmKoXl/CfjfEi8M0MpGB1lXAw6Py0rbTrJuBR4WN+rYGqW+C5yLofEG1OUgtNVzpVA2rxTjclZzneTcy0k3pmUJb67jOuBtHkrZ6JSKOgh42ZIfMGELPE95dwKpM0bFYzPEt9bxu2QeGdcVs73kXEnkDav5YzNEt9Xzt1Q0ckYkyW+v4z7QfGjlUKNJjkPAmnzUgUjs8QPkPEw4PwLFYzIEj9QzqOA889VMDwr5/8PiTeeqWCY0jDWB5x/KmeoMgkcl0/kDFGA/ABqDFadKoVCD7HxsFEPcXWMluVFVn1KtJmCfnLuBYMYpTrV53T2D012EL0a+UtZ/dSHyirOjUaVVarCVqi0aFxtVGmxKu4GgujcyPJ6dcGResVkTFed6pIvdM1qnM2+Zs2/6HZmK0h+q0HB3Owg/gw3ezjzVadqtylLw1Ney5lxLLgTlr0THWQcCe5ETUHibZfGoeDp1Kwg+Y2vzlIFyW89LlihIPnN385qpdJC+3D7vbFQQfIHIGo0lWEEZWdkBKUaAmrgGNa2+BhWfhBbWhnAgTLOUW4KfmLkT7K2Zhi0GsetBqK/dT4Csa/f2ZlrPiMAAAAASUVORK5CYII=';
18+
19+
export const ICON_SIZE = Platform.OS === 'ios' ? 21 : 24;
20+
export const ICON_MARGIN = Platform.OS === 'ios' ? 8 : 3;
21+
const ICON_COLOR = ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT;
22+
1123
const styles = StyleSheet.create({
24+
icon: {
25+
height: ICON_SIZE,
26+
margin: ICON_MARGIN,
27+
width: ICON_SIZE,
28+
},
1229

1330
returnButton: {
1431
alignItems: 'center',
32+
display: 'flex',
1533
flexDirection: 'row',
1634
},
1735

18-
returnButtonIcon: {
19-
color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT,
20-
fontSize: 40,
21-
paddingLeft: 0,
22-
},
23-
2436
returnButtonText: {
2537
color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT,
2638
fontSize: 20,
2739
},
2840
});
2941

30-
export const HeaderBackButton = (props: TouchableWithoutFeedbackProps) => {
42+
/**
43+
* Props for the HeaderBackButton component.
44+
*/
45+
export interface HeaderBackButtonProps extends TouchableWithoutFeedbackProps {
46+
/**
47+
* The text to display next to the back arrow.
48+
*/
49+
label?: string;
50+
/**
51+
* The URI of the image to display.
52+
*
53+
* This defaults to a base64 encoded version of [the back arrow used in react-navigation/elements](https://github.com/react-navigation/react-navigation/blob/main/packages/elements/src/assets/back-icon%404x.ios.png)
54+
*/
55+
imageUri?: string;
56+
/**
57+
* The source of the image to display.
58+
*/
59+
imageSource?: ImageSourcePropType;
60+
}
61+
62+
/**
63+
* A back arrow button used in a header
64+
*
65+
* @returns A button with a back arrow
66+
*/
67+
export const HeaderBackButton = ({
68+
label,
69+
imageUri = backArrowLarge,
70+
imageSource = {
71+
uri: imageUri,
72+
width: PixelRatio.getPixelSizeForLayoutSize(ICON_SIZE),
73+
height: PixelRatio.getPixelSizeForLayoutSize(ICON_SIZE),
74+
},
75+
...props
76+
}: HeaderBackButtonProps) => {
3177
return (
3278
<TouchableWithoutFeedback {...props}>
3379
<View style={styles.returnButton}>
34-
<Icon name="chevron-back-outline" style={styles.returnButtonIcon} />
35-
<Text style={styles.returnButtonText}>Inbox</Text>
80+
<Image
81+
source={imageSource}
82+
resizeMode="contain"
83+
fadeDuration={0}
84+
tintColor={ICON_COLOR}
85+
style={styles.icon}
86+
height={ICON_SIZE}
87+
width={ICON_SIZE}
88+
resizeMethod="scale"
89+
/>
90+
{label && <Text style={styles.returnButtonText}>{label}</Text>}
3691
</View>
3792
</TouchableWithoutFeedback>
3893
);

src/inbox/components/IterableInboxMessageDisplay.tsx

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useEffect, useState } from 'react';
22
import {
33
Linking,
4+
Platform,
45
ScrollView,
56
StyleSheet,
67
Text,
7-
TouchableWithoutFeedback,
88
View,
99
} from 'react-native';
10-
import Icon from 'react-native-vector-icons/Ionicons';
1110
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
1211

1312
import {
@@ -86,6 +85,7 @@ export const IterableInboxMessageDisplay = ({
8685

8786
header: {
8887
flexDirection: 'row',
88+
height: Platform.OS === 'ios' ? 44 : 56,
8989
justifyContent: 'center',
9090
width: '100%',
9191
},
@@ -119,11 +119,6 @@ export const IterableInboxMessageDisplay = ({
119119
fontWeight: 'bold',
120120
},
121121

122-
returnButton: {
123-
alignItems: 'center',
124-
flexDirection: 'row',
125-
},
126-
127122
returnButtonContainer: {
128123
alignItems: 'center',
129124
flexDirection: 'row',
@@ -133,17 +128,6 @@ export const IterableInboxMessageDisplay = ({
133128
width: '25%',
134129
...(isPortrait ? {} : { marginLeft: 80 }),
135130
},
136-
137-
returnButtonIcon: {
138-
color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT,
139-
fontSize: 40,
140-
paddingLeft: 0,
141-
},
142-
143-
returnButtonText: {
144-
color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT,
145-
fontSize: 20,
146-
},
147131
});
148132

149133
const JS = `
@@ -223,6 +207,7 @@ export const IterableInboxMessageDisplay = ({
223207
<View style={styles.header}>
224208
<View style={styles.returnButtonContainer}>
225209
<HeaderBackButton
210+
label="Inbox"
226211
onPress={() => {
227212
returnToInbox();
228213
Iterable.trackInAppClose(
@@ -232,24 +217,6 @@ export const IterableInboxMessageDisplay = ({
232217
);
233218
}}
234219
/>
235-
<TouchableWithoutFeedback
236-
onPress={() => {
237-
returnToInbox();
238-
Iterable.trackInAppClose(
239-
rowViewModel.inAppMessage,
240-
IterableInAppLocation.inbox,
241-
IterableInAppCloseSource.back
242-
);
243-
}}
244-
>
245-
<View style={styles.returnButton}>
246-
<Icon
247-
name="chevron-back-outline"
248-
style={styles.returnButtonIcon}
249-
/>
250-
<Text style={styles.returnButtonText}>Inbox</Text>
251-
</View>
252-
</TouchableWithoutFeedback>
253220
</View>
254221
<View style={styles.messageTitleContainer}>
255222
<View style={styles.messageTitle}>

0 commit comments

Comments
 (0)