Page MenuHomePhabricator

D7507.id25315.diff
No OneTemporary

D7507.id25315.diff

diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js
--- a/native/avatars/avatar-hooks.js
+++ b/native/avatars/avatar-hooks.js
@@ -3,6 +3,7 @@
import { useActionSheet } from '@expo/react-native-action-sheet';
import * as ImagePicker from 'expo-image-picker';
import * as React from 'react';
+import { Platform } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { uploadMultimedia } from 'lib/actions/upload-actions.js';
@@ -17,10 +18,12 @@
} from 'lib/types/media-types.js';
import { useServerCall } from 'lib/utils/action-utils.js';
+import SWMansionIcon from '../components/swmansion-icon.react.js';
import { getCompatibleMediaURI } from '../media/identifier-utils.js';
import type { MediaResult } from '../media/media-utils.js';
import { processMedia } from '../media/media-utils.js';
import { useSelector } from '../redux/redux-utils.js';
+import { useStyles } from '../themes/colors.js';
import { useStaffCanSee } from '../utils/staff-utils.js';
function useUploadProcessedMedia(): MediaResult => Promise<UploadMultimediaResult> {
@@ -117,30 +120,56 @@
}
type ShowAvatarActionSheetOptions = {
- +id: string,
- +text: string,
+ +id: 'emoji' | 'image' | 'cancel',
+onPress?: () => mixed,
- +icon?: React.Node,
- +isCancel?: boolean,
};
function useShowAvatarActionSheet(
- options: $ReadOnlyArray<ShowAvatarActionSheetOptions>,
+ options: ShowAvatarActionSheetOptions[],
): () => void {
+ options = Platform.OS === 'ios' ? [...options, { id: 'cancel' }] : options;
+
const insets = useSafeAreaInsets();
const { showActionSheetWithOptions } = useActionSheet();
+ const styles = useStyles(unboundStyles);
const showAvatarActionSheet = React.useCallback(() => {
- const texts = options.map(
- (option: ShowAvatarActionSheetOptions) => option.text,
- );
+ const texts = options.map((option: ShowAvatarActionSheetOptions) => {
+ if (option.id === 'emoji') {
+ return 'Use Emoji';
+ } else if (option.id === 'image') {
+ return 'Select image';
+ } else {
+ return 'Cancel';
+ }
+ });
- const cancelButtonIndex = options.findIndex(option => option.isCancel);
+ const cancelButtonIndex = options.findIndex(
+ option => option.id === 'cancel',
+ );
const containerStyle = {
paddingBotton: insets.bottom,
};
- const icons = options.map(option => option.icon);
+ const icons = options.map(option => {
+ if (option.id === 'emoji') {
+ return (
+ <SWMansionIcon
+ name="emote-smile"
+ size={22}
+ style={styles.bottomSheetIcon}
+ />
+ );
+ } else if (option.id === 'image') {
+ return (
+ <SWMansionIcon
+ name="image-1"
+ size={22}
+ style={styles.bottomSheetIcon}
+ />
+ );
+ }
+ });
const onPressAction = (selectedIndex: ?number) => {
if (
@@ -165,11 +194,22 @@
},
onPressAction,
);
- }, [insets.bottom, options, showActionSheetWithOptions]);
+ }, [
+ insets.bottom,
+ options,
+ showActionSheetWithOptions,
+ styles.bottomSheetIcon,
+ ]);
return showAvatarActionSheet;
}
+const unboundStyles = {
+ bottomSheetIcon: {
+ color: '#000000',
+ },
+};
+
export {
useUploadProcessedMedia,
useProcessSelectedMedia,
diff --git a/native/avatars/edit-thread-avatar.react.js b/native/avatars/edit-thread-avatar.react.js
--- a/native/avatars/edit-thread-avatar.react.js
+++ b/native/avatars/edit-thread-avatar.react.js
@@ -1,15 +1,13 @@
// @flow
import * as React from 'react';
-import { TouchableOpacity, Platform } from 'react-native';
+import { TouchableOpacity } from 'react-native';
import {
useSelectAndUploadFromGallery,
useShowAvatarActionSheet,
} from './avatar-hooks.js';
import EditAvatarBadge from './edit-avatar-badge.react.js';
-import SWMansionIcon from '../components/swmansion-icon.react.js';
-import { useStyles } from '../themes/colors.js';
type Props = {
+children: React.Node,
@@ -19,71 +17,24 @@
function EditThreadAvatar(props: Props): React.Node {
const { onPressEmojiAvatarFlow, children, disabled } = props;
- const styles = useStyles(unboundStyles);
-
const selectAndUploadFromGallery = useSelectAndUploadFromGallery();
- const editAvatarOptions = React.useMemo(() => {
- const options = [
- {
- id: 'emoji',
- text: 'Use Emoji',
- onPress: onPressEmojiAvatarFlow,
- icon: (
- <SWMansionIcon
- name="emote-smile"
- size={22}
- style={styles.bottomSheetIcon}
- />
- ),
- },
- {
- id: 'image',
- text: 'Select image',
- onPress: selectAndUploadFromGallery,
- icon: (
- <SWMansionIcon
- name="image-1"
- size={22}
- style={styles.bottomSheetIcon}
- />
- ),
- },
- ];
-
- if (Platform.OS === 'ios') {
- options.push({
- id: 'cancel',
- text: 'Cancel',
- isCancel: true,
- });
- }
- return options;
- }, [
- onPressEmojiAvatarFlow,
- selectAndUploadFromGallery,
- styles.bottomSheetIcon,
- ]);
-
- const showAvatarActionSheet = useShowAvatarActionSheet(editAvatarOptions);
+ const actionSheetConfig = React.useMemo(
+ () => [
+ { id: 'emoji', onPress: onPressEmojiAvatarFlow },
+ { id: 'image', onPress: selectAndUploadFromGallery },
+ ],
+ [onPressEmojiAvatarFlow, selectAndUploadFromGallery],
+ );
- let editBadge;
- if (!disabled) {
- editBadge = <EditAvatarBadge />;
- }
+ const showAvatarActionSheet = useShowAvatarActionSheet(actionSheetConfig);
return (
<TouchableOpacity onPress={showAvatarActionSheet} disabled={disabled}>
{children}
- {editBadge}
+ {!disabled ? <EditAvatarBadge /> : null}
</TouchableOpacity>
);
}
-const unboundStyles = {
- bottomSheetIcon: {
- color: '#000000',
- },
-};
-
export default EditThreadAvatar;
diff --git a/native/avatars/edit-user-avatar.react.js b/native/avatars/edit-user-avatar.react.js
--- a/native/avatars/edit-user-avatar.react.js
+++ b/native/avatars/edit-user-avatar.react.js
@@ -1,15 +1,13 @@
// @flow
import * as React from 'react';
-import { TouchableOpacity, Platform } from 'react-native';
+import { TouchableOpacity } from 'react-native';
import {
useSelectAndUploadFromGallery,
useShowAvatarActionSheet,
} from './avatar-hooks.js';
import EditAvatarBadge from './edit-avatar-badge.react.js';
-import SWMansionIcon from '../components/swmansion-icon.react.js';
-import { useStyles } from '../themes/colors.js';
type Props = {
+children: React.Node,
@@ -19,71 +17,24 @@
function EditUserAvatar(props: Props): React.Node {
const { onPressEmojiAvatarFlow, children, disabled } = props;
- const styles = useStyles(unboundStyles);
-
const selectAndUploadFromGallery = useSelectAndUploadFromGallery();
- const editAvatarOptions = React.useMemo(() => {
- const options = [
- {
- id: 'emoji',
- text: 'Use Emoji',
- onPress: onPressEmojiAvatarFlow,
- icon: (
- <SWMansionIcon
- name="emote-smile"
- size={22}
- style={styles.bottomSheetIcon}
- />
- ),
- },
- {
- id: 'image',
- text: 'Select image',
- onPress: selectAndUploadFromGallery,
- icon: (
- <SWMansionIcon
- name="image-1"
- size={22}
- style={styles.bottomSheetIcon}
- />
- ),
- },
- ];
-
- if (Platform.OS === 'ios') {
- options.push({
- id: 'cancel',
- text: 'Cancel',
- isCancel: true,
- });
- }
- return options;
- }, [
- onPressEmojiAvatarFlow,
- selectAndUploadFromGallery,
- styles.bottomSheetIcon,
- ]);
-
- const showAvatarActionSheet = useShowAvatarActionSheet(editAvatarOptions);
+ const actionSheetConfig = React.useMemo(
+ () => [
+ { id: 'emoji', onPress: onPressEmojiAvatarFlow },
+ { id: 'image', onPress: selectAndUploadFromGallery },
+ ],
+ [onPressEmojiAvatarFlow, selectAndUploadFromGallery],
+ );
- let editBadge;
- if (!disabled) {
- editBadge = <EditAvatarBadge />;
- }
+ const showAvatarActionSheet = useShowAvatarActionSheet(actionSheetConfig);
return (
<TouchableOpacity onPress={showAvatarActionSheet} disabled={disabled}>
{children}
- {editBadge}
+ {!disabled ? <EditAvatarBadge /> : null}
</TouchableOpacity>
);
}
-const unboundStyles = {
- bottomSheetIcon: {
- color: '#000000',
- },
-};
-
export default EditUserAvatar;

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 7, 6:16 PM (21 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2255731
Default Alt Text
D7507.id25315.diff (8 KB)

Event Timeline