Skip to content

Commit 37e437d

Browse files
chrisbobbegnprice
authored andcommitted
NestedNavRow [nfc]: Grow option to show emoji instead of icon at left
1 parent 9a84562 commit 37e437d

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

src/common/NestedNavRow.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import React, { useContext, useMemo } from 'react';
33
import type { Node } from 'react';
44
import { View } from 'react-native';
55

6-
import type { LocalizableReactText } from '../types';
6+
import type { EmojiType, LocalizableReactText } from '../types';
77
import ZulipTextIntl from './ZulipTextIntl';
88
import Touchable from './Touchable';
99
import { IconRight } from './Icons';
1010
import type { SpecificIconType } from './Icons';
1111
import globalStyles, { ThemeContext, createStyleSheet } from '../styles';
12+
import Emoji from '../emoji/Emoji';
13+
import { ensureUnreachable } from '../generics';
1214

1315
type Props = $ReadOnly<{|
14-
icon?: {|
15-
+Component: SpecificIconType,
16-
+color?: string,
17-
|},
16+
/** An icon or emoji displayed at the left of the row. */
17+
leftElement?:
18+
| {|
19+
+type: 'icon',
20+
+Component: SpecificIconType,
21+
+color?: string,
22+
|}
23+
| {|
24+
+type: 'emoji',
25+
+emojiCode: string,
26+
+emojiType: EmojiType,
27+
|},
1828

1929
title: LocalizableReactText,
2030
subtitle?: LocalizableReactText,
@@ -34,7 +44,7 @@ type Props = $ReadOnly<{|
3444
* selectable option row instead, use `SelectableOptionRow`.
3545
*/
3646
export default function NestedNavRow(props: Props): Node {
37-
const { title, subtitle, titleBoldUppercase, onPress, icon } = props;
47+
const { title, subtitle, titleBoldUppercase, onPress, leftElement } = props;
3848

3949
const themeContext = useContext(ThemeContext);
4050

@@ -51,10 +61,11 @@ export default function NestedNavRow(props: Props): Node {
5161
// https://material.io/design/usability/accessibility.html#layout-and-typography
5262
minHeight: 48,
5363
},
64+
leftElement: {
65+
marginRight: 8,
66+
},
5467
iconFromProps: {
5568
textAlign: 'center',
56-
marginRight: 8,
57-
color: icon?.color ?? themeContext.color,
5869
},
5970
textWrapper: {
6071
flex: 1,
@@ -72,13 +83,35 @@ export default function NestedNavRow(props: Props): Node {
7283
color: themeContext.color,
7384
},
7485
}),
75-
[themeContext, icon, titleBoldUppercase],
86+
[themeContext, titleBoldUppercase],
7687
);
7788

7889
return (
7990
<Touchable onPress={onPress}>
8091
<View style={styles.container}>
81-
{!!icon && <icon.Component size={24} style={styles.iconFromProps} />}
92+
{leftElement && (
93+
<View style={styles.leftElement}>
94+
{(() => {
95+
switch (leftElement.type) {
96+
case 'icon':
97+
return (
98+
<leftElement.Component
99+
size={24}
100+
style={styles.iconFromProps}
101+
color={leftElement.color ?? themeContext.color}
102+
/>
103+
);
104+
case 'emoji':
105+
return (
106+
<Emoji size={24} code={leftElement.emojiCode} type={leftElement.emojiType} />
107+
);
108+
default:
109+
ensureUnreachable(leftElement.type);
110+
}
111+
})()}
112+
</View>
113+
)}
114+
82115
<View style={styles.textWrapper}>
83116
<ZulipTextIntl style={styles.title} text={title} />
84117
{subtitle !== undefined && <ZulipTextIntl style={styles.subtitle} text={subtitle} />}

src/settings/NotificationsScreen.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ export default function NotificationsScreen(props: Props): Node {
140140
<Screen title="Notifications">
141141
<ServerPushSetupBanner isDismissable={false} />
142142
<NestedNavRow
143-
icon={
143+
leftElement={
144144
systemSettingsWarnings.length > 0
145145
? {
146+
type: 'icon',
146147
Component: IconAlertTriangle,
147148
color: kWarningColor,
148149
}
@@ -191,7 +192,11 @@ export default function NotificationsScreen(props: Props): Node {
191192
<NestedNavRow
192193
{...(() =>
193194
notificationReport.problems.length > 0 && {
194-
icon: { Component: IconAlertTriangle, color: kWarningColor },
195+
leftElement: {
196+
type: 'icon',
197+
Component: IconAlertTriangle,
198+
color: kWarningColor,
199+
},
195200
subtitle: 'Notifications for this account may not arrive.',
196201
})()}
197202
title="Troubleshooting"
@@ -213,7 +218,11 @@ export default function NotificationsScreen(props: Props): Node {
213218
}).length;
214219
return problemAccountsCount > 0
215220
? {
216-
icon: { Component: IconAlertTriangle, color: kWarningColor },
221+
leftElement: {
222+
type: 'icon',
223+
Component: IconAlertTriangle,
224+
color: kWarningColor,
225+
},
217226
subtitle: {
218227
text: `\
219228
{problemAccountsCount, plural,

src/settings/SettingsScreen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ export default function SettingsScreen(props: Props): Node {
9090
}}
9191
/>
9292
<NestedNavRow
93-
icon={{ Component: IconNotifications }}
93+
leftElement={{ type: 'icon', Component: IconNotifications }}
9494
title="Notifications"
9595
{...(() =>
9696
notificationReport.problems.length > 0 && {
97-
icon: { Component: IconAlertTriangle, color: kWarningColor },
97+
leftElement: { type: 'icon', Component: IconAlertTriangle, color: kWarningColor },
9898
subtitle: 'Notifications for this account may not arrive.',
9999
})()}
100100
onPress={() => {
@@ -117,7 +117,7 @@ export default function SettingsScreen(props: Props): Node {
117117
search
118118
/>
119119
<NestedNavRow
120-
icon={{ Component: IconMoreHorizontal }}
120+
leftElement={{ type: 'icon', Component: IconMoreHorizontal }}
121121
title="Legal"
122122
onPress={() => {
123123
navigation.push('legal');

0 commit comments

Comments
 (0)