Skip to content

Commit 8b4f0d7

Browse files
chrisbobbegnprice
authored andcommitted
ComposeMenu: Use modern Pressable API for buttons
With the `onPress` handler removed from the icon components themselves, we lose RN's default feedback for `Text` elements, which is to fade a tight rectangle around the text (at least on iOS). So implement touch feedback the way we've done with `Pressable` before, e.g., in StreamItem and UserStatusScreen.
1 parent 6f1df47 commit 8b4f0d7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/compose/ComposeMenu.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow strict-local */
22
import React, { useCallback, useContext, useMemo } from 'react';
33
import type { Node } from 'react';
4-
import { Platform, View, Alert, Linking } from 'react-native';
4+
import { Platform, View, Alert, Linking, Pressable } from 'react-native';
55
import type { DocumentPickerResponse } from 'react-native-document-picker';
66
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
77

@@ -10,7 +10,7 @@ import * as logging from '../utils/logging';
1010
import { TranslationContext } from '../boot/TranslationProvider';
1111
import type { Narrow } from '../types';
1212
import { showErrorAlert } from '../utils/info';
13-
import { BRAND_COLOR, createStyleSheet } from '../styles';
13+
import { BRAND_COLOR, HIGHLIGHT_COLOR, createStyleSheet } from '../styles';
1414
import {
1515
IconPlusCircle,
1616
IconLeft,
@@ -82,9 +82,13 @@ type MenuButtonProps = $ReadOnly<{|
8282

8383
function MenuButton(props: MenuButtonProps) {
8484
const { onPress, IconComponent } = props;
85-
const style = useMemo(() => ({ padding: 12, marginRight: -8, color: BRAND_COLOR }), []);
85+
const style = useMemo(() => ({ padding: 12, marginRight: -8 }), []);
8686

87-
return <IconComponent style={style} size={24} onPress={onPress} />;
87+
return (
88+
<Pressable style={style} onPress={onPress}>
89+
{({ pressed }) => <IconComponent color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR} size={24} />}
90+
</Pressable>
91+
);
8892
}
8993

9094
export default function ComposeMenu(props: Props): Node {
@@ -237,7 +241,6 @@ export default function ComposeMenu(props: Props): Node {
237241
},
238242
expandButton: {
239243
padding: 12,
240-
color: BRAND_COLOR,
241244
},
242245
}),
243246
[],
@@ -265,9 +268,17 @@ export default function ComposeMenu(props: Props): Node {
265268
</View>
266269
</AnimatedComponent>
267270
{!expanded && (
268-
<IconPlusCircle style={styles.expandButton} size={24} onPress={onExpandContract} />
271+
<Pressable style={styles.expandButton} onPress={onExpandContract}>
272+
{({ pressed }) => (
273+
<IconPlusCircle color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR} size={24} />
274+
)}
275+
</Pressable>
276+
)}
277+
{expanded && (
278+
<Pressable style={styles.expandButton} onPress={onExpandContract}>
279+
{({ pressed }) => <IconLeft color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR} size={24} />}
280+
</Pressable>
269281
)}
270-
{expanded && <IconLeft style={styles.expandButton} size={24} onPress={onExpandContract} />}
271282
</View>
272283
);
273284
}

0 commit comments

Comments
 (0)