diff --git a/native/avatars/edit-thread-avatar.react.js b/native/avatars/edit-thread-avatar.react.js
index f661c97a9..0dc423968 100644
--- a/native/avatars/edit-thread-avatar.react.js
+++ b/native/avatars/edit-thread-avatar.react.js
@@ -1,83 +1,96 @@
// @flow
+import { useNavigation } from '@react-navigation/native';
import invariant from 'invariant';
import * as React from 'react';
import { ActivityIndicator, TouchableOpacity, View } from 'react-native';
import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js';
import { useShowAvatarActionSheet } from './avatar-hooks.js';
import EditAvatarBadge from './edit-avatar-badge.react.js';
import { EditThreadAvatarContext } from './edit-thread-avatar-provider.react.js';
import ThreadAvatar from './thread-avatar.react.js';
+import { EmojiThreadAvatarCreationRouteName } from '../navigation/route-names.js';
import { useStyles } from '../themes/colors.js';
type Props = {
+threadInfo: RawThreadInfo | ThreadInfo,
- +onPressEmojiAvatarFlow: () => mixed,
+disabled?: boolean,
};
function EditThreadAvatar(props: Props): React.Node {
const styles = useStyles(unboundStyles);
- const { threadInfo, onPressEmojiAvatarFlow, disabled } = props;
+ const { threadInfo, disabled } = props;
const editThreadAvatarContext = React.useContext(EditThreadAvatarContext);
invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set');
const {
threadAvatarSaveInProgress,
selectFromGalleryAndUpdateThreadAvatar,
removeThreadAvatar,
} = editThreadAvatarContext;
+ const { navigate } = useNavigation();
+
+ const navigateToThreadEmojiAvatarCreation = React.useCallback(() => {
+ navigate<'EmojiThreadAvatarCreation'>({
+ name: EmojiThreadAvatarCreationRouteName,
+ params: {
+ threadID: threadInfo.id,
+ containingThreadID: threadInfo.containingThreadID,
+ },
+ });
+ }, [navigate, threadInfo.containingThreadID, threadInfo.id]);
+
const selectFromGallery = React.useCallback(
() => selectFromGalleryAndUpdateThreadAvatar(threadInfo.id),
[selectFromGalleryAndUpdateThreadAvatar, threadInfo.id],
);
const removeAvatar = React.useCallback(
() => removeThreadAvatar(threadInfo.id),
[removeThreadAvatar, threadInfo.id],
);
const actionSheetConfig = React.useMemo(
() => [
- { id: 'emoji', onPress: onPressEmojiAvatarFlow },
+ { id: 'emoji', onPress: navigateToThreadEmojiAvatarCreation },
{ id: 'image', onPress: selectFromGallery },
{ id: 'remove', onPress: removeAvatar },
],
- [onPressEmojiAvatarFlow, removeAvatar, selectFromGallery],
+ [navigateToThreadEmojiAvatarCreation, removeAvatar, selectFromGallery],
);
const showAvatarActionSheet = useShowAvatarActionSheet(actionSheetConfig);
let spinner;
if (threadAvatarSaveInProgress) {
spinner = (
);
}
return (
{spinner}
{!disabled ? : null}
);
}
const unboundStyles = {
spinnerContainer: {
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
};
export default EditThreadAvatar;
diff --git a/native/chat/settings/thread-settings-avatar.react.js b/native/chat/settings/thread-settings-avatar.react.js
index fbcfc85c9..14bb6c8c8 100644
--- a/native/chat/settings/thread-settings-avatar.react.js
+++ b/native/chat/settings/thread-settings-avatar.react.js
@@ -1,57 +1,39 @@
// @flow
-import { useNavigation } from '@react-navigation/native';
import * as React from 'react';
import { View } from 'react-native';
import { type ResolvedThreadInfo } from 'lib/types/thread-types.js';
import EditThreadAvatar from '../../avatars/edit-thread-avatar.react.js';
-import { EmojiThreadAvatarCreationRouteName } from '../../navigation/route-names.js';
import { useStyles } from '../../themes/colors.js';
type Props = {
+threadInfo: ResolvedThreadInfo,
+canChangeSettings: boolean,
};
function ThreadSettingsAvatar(props: Props): React.Node {
const { threadInfo, canChangeSettings } = props;
- const { navigate } = useNavigation();
-
const styles = useStyles(unboundStyles);
- const onPressEmojiAvatarFlow = React.useCallback(() => {
- navigate<'EmojiThreadAvatarCreation'>({
- name: EmojiThreadAvatarCreationRouteName,
- params: {
- threadID: threadInfo.id,
- containingThreadID: threadInfo.containingThreadID,
- },
- });
- }, [navigate, threadInfo.containingThreadID, threadInfo.id]);
-
return (
-
+
);
}
const unboundStyles = {
container: {
alignItems: 'center',
backgroundColor: 'panelForeground',
flex: 1,
paddingVertical: 16,
},
};
const MemoizedThreadSettingsAvatar: React.ComponentType =
React.memo(ThreadSettingsAvatar);
export default MemoizedThreadSettingsAvatar;