1
1
/* @flow strict-local */
2
2
3
- import React , { useState , useCallback , useContext } from 'react' ;
3
+ import React , { useState , useCallback } from 'react' ;
4
4
import type { Node } from 'react' ;
5
- import { FlatList } from 'react-native' ;
5
+ import { FlatList , LogBox } from 'react-native' ;
6
6
7
- import { TranslationContext } from '../boot/TranslationProvider' ;
8
7
import type { RouteProp } from '../react-navigation' ;
9
8
import type { AppNavigationProp } from '../nav/AppNavigator' ;
10
- import * as api from '../api' ;
11
9
import Screen from '../common/Screen' ;
12
10
import EmojiRow from './EmojiRow' ;
13
- import { getFilteredEmojis , reactionTypeFromEmojiType } from './data' ;
11
+ import { getFilteredEmojis } from './data' ;
12
+ import { getActiveImageEmojiByName } from '../selectors' ;
13
+ import type { EmojiType } from '../types' ;
14
14
import { useSelector } from '../react-redux' ;
15
- import { getAuth , getActiveImageEmojiByName } from '../selectors' ;
16
- import * as logging from '../utils/logging' ;
17
- import { showToast } from '../utils/info' ;
18
15
19
16
type Props = $ReadOnly < { |
20
17
navigation : AppNavigationProp < 'emoji-picker' > ,
21
- route : RouteProp < 'emoji-picker' , { | messageId : number | } > ,
18
+ route : RouteProp <
19
+ 'emoji-picker' ,
20
+ { |
21
+ // This param is a function, so React Nav is right to point out that
22
+ // it isn't serializable. But this is fine as long as we don't try to
23
+ // persist navigation state for this screen or set up deep linking to
24
+ // it, hence the LogBox suppression below.
25
+ //
26
+ // React Navigation doesn't offer a more sensible way to do have us
27
+ // pass the emoji data to the calling screen. …We could store the
28
+ // emoji data as a route param on the calling screen, or in Redux. But
29
+ // from this screen's perspective, that's basically just setting a
30
+ // global variable. Better to offer this explicit, side-effect-free
31
+ // way for the data to flow where it should, when it should.
32
+ onPressEmoji : ( { | + type : EmojiType , + code : string , + name : string | } ) => void ,
33
+ | } ,
34
+ > ,
22
35
| } > ;
23
36
37
+ // React Navigation would give us a console warning about non-serializable
38
+ // route params. For more about the warning, see
39
+ // https://reactnavigation.org/docs/5.x/troubleshooting/#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state
40
+ // See comment on this param, above.
41
+ LogBox . ignoreLogs ( [ / e m o j i - p i c k e r > p a r a m s \. o n P r e s s E m o j i \( F u n c t i o n \) / ] ) ;
42
+
24
43
export default function EmojiPickerScreen ( props : Props ) : Node {
25
44
const { navigation, route } = props ;
26
- const { messageId } = route . params ;
27
-
28
- const _ = useContext ( TranslationContext ) ;
45
+ const { onPressEmoji } = route . params ;
29
46
30
47
const activeImageEmojiByName = useSelector ( getActiveImageEmojiByName ) ;
31
- const auth = useSelector ( getAuth ) ;
32
48
33
49
const [ filter , setFilter ] = useState < string > ( '' ) ;
34
50
35
51
const handleInputChange = useCallback ( ( text : string ) => {
36
52
setFilter ( text . toLowerCase ( ) ) ;
37
53
} , [ ] ) ;
38
54
39
- const addReaction = useCallback (
40
- ( { type, code, name } ) => {
41
- api
42
- . emojiReactionAdd ( auth , messageId , reactionTypeFromEmojiType ( type , name ) , code , name )
43
- . catch ( err => {
44
- logging . error ( 'Error adding reaction emoji' , err ) ;
45
- showToast ( _ ( 'Failed to add reaction' ) ) ;
46
- } ) ;
55
+ const handlePressEmoji = useCallback (
56
+ ( ...args ) => {
57
+ onPressEmoji ( ...args ) ;
47
58
navigation . goBack ( ) ;
48
59
} ,
49
- [ auth , messageId , _ , navigation ] ,
60
+ [ onPressEmoji , navigation ] ,
50
61
) ;
51
62
52
63
const emojiNames = getFilteredEmojis ( filter , activeImageEmojiByName ) ;
@@ -63,7 +74,7 @@ export default function EmojiPickerScreen(props: Props): Node {
63
74
type = { item . emoji_type }
64
75
code = { item . code }
65
76
name = { item . name }
66
- onPress = { addReaction }
77
+ onPress = { handlePressEmoji }
67
78
/>
68
79
) }
69
80
/>
0 commit comments