Skip to content

Commit 47fedd4

Browse files
chrisbobbegnprice
authored andcommitted
ComposeMenu [nfc]: Factor out MenuButton component
1 parent 73354dd commit 47fedd4

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/compose/ComposeMenu.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import AnimatedComponent from '../animation/AnimatedComponent';
2323
import { uploadFile } from '../actions';
2424
import { androidEnsureStoragePermission } from '../lightbox/download';
25+
import type { SpecificIconType } from '../common/Icons';
2526

2627
type Props = $ReadOnly<{|
2728
expanded: boolean,
@@ -74,6 +75,18 @@ export const chooseUploadImageFilename = (uri: string, fileName: string): string
7475
return nameWithoutPrefix;
7576
};
7677

78+
type MenuButtonProps = $ReadOnly<{|
79+
onPress: () => void | Promise<void>,
80+
IconComponent: SpecificIconType,
81+
|}>;
82+
83+
function MenuButton(props: MenuButtonProps) {
84+
const { onPress, IconComponent } = props;
85+
const style = useMemo(() => ({ padding: 12, marginRight: -8, color: BRAND_COLOR }), []);
86+
87+
return <IconComponent style={style} size={24} onPress={onPress} />;
88+
}
89+
7790
export default function ComposeMenu(props: Props): Node {
7891
const { destinationNarrow, insertAttachment, expanded, insertVideoCallLink, onExpandContract } =
7992
props;
@@ -220,11 +233,6 @@ export default function ComposeMenu(props: Props): Node {
220233
padding: 12,
221234
color: BRAND_COLOR,
222235
},
223-
composeMenuButton: {
224-
padding: 12,
225-
marginRight: -8,
226-
color: BRAND_COLOR,
227-
},
228236
}),
229237
[],
230238
);
@@ -241,12 +249,12 @@ export default function ComposeMenu(props: Props): Node {
241249
>
242250
<View style={styles.composeMenu}>
243251
{Platform.OS === 'android' && (
244-
<IconAttach style={styles.composeMenuButton} size={24} onPress={handleFilesPicker} />
252+
<MenuButton onPress={handleFilesPicker} IconComponent={IconAttach} />
245253
)}
246-
<IconImage style={styles.composeMenuButton} size={24} onPress={handleImagePicker} />
247-
<IconCamera style={styles.composeMenuButton} size={24} onPress={handleCameraCapture} />
254+
<MenuButton onPress={handleImagePicker} IconComponent={IconImage} />
255+
<MenuButton onPress={handleCameraCapture} IconComponent={IconCamera} />
248256
{insertVideoCallLink !== null ? (
249-
<IconVideo style={styles.composeMenuButton} size={24} onPress={insertVideoCallLink} />
257+
<MenuButton onPress={insertVideoCallLink} IconComponent={IconVideo} />
250258
) : null}
251259
</View>
252260
</AnimatedComponent>

0 commit comments

Comments
 (0)