@@ -3,18 +3,28 @@ import React, { useContext, useMemo } from 'react';
3
3
import type { Node } from 'react' ;
4
4
import { View } from 'react-native' ;
5
5
6
- import type { LocalizableReactText } from '../types' ;
6
+ import type { EmojiType , LocalizableReactText } from '../types' ;
7
7
import ZulipTextIntl from './ZulipTextIntl' ;
8
8
import Touchable from './Touchable' ;
9
9
import { IconRight } from './Icons' ;
10
10
import type { SpecificIconType } from './Icons' ;
11
11
import globalStyles , { ThemeContext , createStyleSheet } from '../styles' ;
12
+ import Emoji from '../emoji/Emoji' ;
13
+ import { ensureUnreachable } from '../generics' ;
12
14
13
15
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
+ | } ,
18
28
19
29
title : LocalizableReactText ,
20
30
subtitle ? : LocalizableReactText ,
@@ -34,7 +44,7 @@ type Props = $ReadOnly<{|
34
44
* selectable option row instead, use `SelectableOptionRow`.
35
45
*/
36
46
export default function NestedNavRow ( props : Props ) : Node {
37
- const { title, subtitle, titleBoldUppercase, onPress, icon } = props ;
47
+ const { title, subtitle, titleBoldUppercase, onPress, leftElement } = props ;
38
48
39
49
const themeContext = useContext ( ThemeContext ) ;
40
50
@@ -51,10 +61,11 @@ export default function NestedNavRow(props: Props): Node {
51
61
// https://material.io/design/usability/accessibility.html#layout-and-typography
52
62
minHeight : 48 ,
53
63
} ,
64
+ leftElement : {
65
+ marginRight : 8 ,
66
+ } ,
54
67
iconFromProps : {
55
68
textAlign : 'center' ,
56
- marginRight : 8 ,
57
- color : icon ?. color ?? themeContext . color ,
58
69
} ,
59
70
textWrapper : {
60
71
flex : 1 ,
@@ -72,13 +83,35 @@ export default function NestedNavRow(props: Props): Node {
72
83
color : themeContext . color ,
73
84
} ,
74
85
} ) ,
75
- [ themeContext , icon , titleBoldUppercase ] ,
86
+ [ themeContext , titleBoldUppercase ] ,
76
87
) ;
77
88
78
89
return (
79
90
< Touchable onPress = { onPress } >
80
91
< 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
+
82
115
< View style = { styles . textWrapper } >
83
116
< ZulipTextIntl style = { styles . title } text = { title } />
84
117
{ subtitle !== undefined && < ZulipTextIntl style = { styles . subtitle } text = { subtitle } /> }
0 commit comments