|
1 | 1 | import { |
| 2 | + Image, |
| 3 | + PixelRatio, |
| 4 | + Platform, |
2 | 5 | StyleSheet, |
3 | 6 | Text, |
4 | 7 | TouchableWithoutFeedback, |
5 | 8 | View, |
| 9 | + type ImageSourcePropType, |
6 | 10 | type TouchableWithoutFeedbackProps, |
7 | 11 | } from 'react-native'; |
8 | | -import { Icon } from 'react-native-vector-icons/Icon'; |
9 | 12 | import { ITERABLE_INBOX_COLORS } from '../constants/colors'; |
10 | 13 |
|
| 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 | + |
11 | 23 | const styles = StyleSheet.create({ |
| 24 | + icon: { |
| 25 | + height: ICON_SIZE, |
| 26 | + margin: ICON_MARGIN, |
| 27 | + width: ICON_SIZE, |
| 28 | + }, |
12 | 29 |
|
13 | 30 | returnButton: { |
14 | 31 | alignItems: 'center', |
| 32 | + display: 'flex', |
15 | 33 | flexDirection: 'row', |
16 | 34 | }, |
17 | 35 |
|
18 | | - returnButtonIcon: { |
19 | | - color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT, |
20 | | - fontSize: 40, |
21 | | - paddingLeft: 0, |
22 | | - }, |
23 | | - |
24 | 36 | returnButtonText: { |
25 | 37 | color: ITERABLE_INBOX_COLORS.BUTTON_PRIMARY_TEXT, |
26 | 38 | fontSize: 20, |
27 | 39 | }, |
28 | 40 | }); |
29 | 41 |
|
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) => { |
31 | 77 | return ( |
32 | 78 | <TouchableWithoutFeedback {...props}> |
33 | 79 | <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>} |
36 | 91 | </View> |
37 | 92 | </TouchableWithoutFeedback> |
38 | 93 | ); |
|
0 commit comments