Skip to content

Commit 96901e3

Browse files
committed
Emoji [nfc]: Allow setting size
1 parent 7a8208b commit 96901e3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/emoji/Emoji.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @flow strict-local */
2-
import React from 'react';
2+
import React, { useMemo } from 'react';
33
import type { Node } from 'react';
44
import { Image } from 'react-native';
55
import { createIconSet } from 'react-native-vector-icons';
@@ -18,19 +18,20 @@ const UnicodeEmoji = createIconSet(codeToEmojiMap);
1818
type Props = $ReadOnly<{|
1919
type: EmojiType,
2020
code: string,
21+
size?: number,
2122
|}>;
2223

23-
const componentStyles = createStyleSheet({
24-
image: { width: 20, height: 20 },
25-
});
26-
2724
export default function Emoji(props: Props): Node {
28-
const { code } = props;
25+
const { code, size = 20 } = props;
2926
const imageEmoji = useSelector(state =>
3027
props.type === 'image' ? getAllImageEmojiByCode(state)[props.code] : undefined,
3128
);
29+
const componentStyles = useMemo(
30+
() => createStyleSheet({ image: { width: size, height: size } }),
31+
[size],
32+
);
3233
if (imageEmoji) {
3334
return <Image style={componentStyles.image} source={{ uri: imageEmoji.source_url }} />;
3435
}
35-
return <UnicodeEmoji name={code} size={20} />;
36+
return <UnicodeEmoji name={code} size={size} />;
3637
}

0 commit comments

Comments
 (0)