diff --git a/native/avatars/edit-avatar-badge.react.js b/native/avatars/edit-avatar-badge.react.js new file mode 100644 index 000000000..0eb5fefdd --- /dev/null +++ b/native/avatars/edit-avatar-badge.react.js @@ -0,0 +1,43 @@ +// @flow + +import * as React from 'react'; +import { View } from 'react-native'; + +import SWMansionIcon from '../components/swmansion-icon.react.js'; +import { useColors, useStyles } from '../themes/colors.js'; + +function EditAvatarBadge(): React.Node { + const colors = useColors(); + const styles = useStyles(unboundStyles); + + return ( + + + + ); +} + +const unboundStyles = { + editAvatarIconContainer: { + position: 'absolute', + bottom: 0, + right: 0, + borderWidth: 2, + borderColor: 'panelForeground', + borderRadius: 18, + width: 36, + height: 36, + backgroundColor: 'purpleButton', + justifyContent: 'center', + }, + editAvatarIcon: { + textAlign: 'center', + }, +}; + +export default EditAvatarBadge; diff --git a/native/avatars/edit-thread-avatar.react.js b/native/avatars/edit-thread-avatar.react.js index 92b3a73e8..0429f138c 100644 --- a/native/avatars/edit-thread-avatar.react.js +++ b/native/avatars/edit-thread-avatar.react.js @@ -1,159 +1,127 @@ // @flow import { useActionSheet } from '@expo/react-native-action-sheet'; import * as React from 'react'; -import { View, TouchableOpacity, Platform } from 'react-native'; +import { TouchableOpacity, Platform } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useSelectAndUploadFromGallery } from './avatar-hooks.js'; +import EditAvatarBadge from './edit-avatar-badge.react.js'; import SWMansionIcon from '../components/swmansion-icon.react.js'; -import { useColors, useStyles } from '../themes/colors.js'; +import { useStyles } from '../themes/colors.js'; type Props = { +children: React.Node, +onPressEmojiAvatarFlow: () => mixed, +disabled?: boolean, }; function EditThreadAvatar(props: Props): React.Node { const { onPressEmojiAvatarFlow, children, disabled } = props; const { showActionSheetWithOptions } = useActionSheet(); - const colors = useColors(); const styles = useStyles(unboundStyles); const selectAndUploadFromGallery = useSelectAndUploadFromGallery(); const editAvatarOptions = React.useMemo(() => { const options = [ { id: 'emoji', text: 'Use Emoji', onPress: onPressEmojiAvatarFlow, icon: ( ), }, { id: 'image', text: 'Select image', onPress: selectAndUploadFromGallery, icon: ( ), }, ]; if (Platform.OS === 'ios') { options.push({ id: 'cancel', text: 'Cancel', isCancel: true, }); } return options; }, [ onPressEmojiAvatarFlow, selectAndUploadFromGallery, styles.bottomSheetIcon, ]); const insets = useSafeAreaInsets(); const onPressEditAvatar = React.useCallback(() => { const texts = editAvatarOptions.map(option => option.text); const cancelButtonIndex = editAvatarOptions.findIndex( option => option.isCancel, ); const containerStyle = { paddingBottom: insets.bottom, }; const icons = editAvatarOptions.map(option => option.icon); const onPressAction = (selectedIndex: ?number) => { if ( selectedIndex === null || selectedIndex === undefined || selectedIndex < 0 ) { return; } const option = editAvatarOptions[selectedIndex]; if (option.onPress) { option.onPress(); } }; showActionSheetWithOptions( { options: texts, cancelButtonIndex, containerStyle, icons, }, onPressAction, ); }, [editAvatarOptions, insets.bottom, showActionSheetWithOptions]); - const editBadge = React.useMemo(() => { - if (disabled) { - return null; - } - - return ( - - - - ); - }, [ - colors.floatingButtonLabel, - disabled, - styles.editAvatarIcon, - styles.editAvatarIconContainer, - ]); + let editBadge; + if (!disabled) { + editBadge = ; + } return ( {children} {editBadge} ); } const unboundStyles = { - editAvatarIconContainer: { - position: 'absolute', - bottom: 0, - right: 0, - borderWidth: 2, - borderColor: 'panelForeground', - borderRadius: 18, - width: 36, - height: 36, - backgroundColor: 'purpleButton', - justifyContent: 'center', - }, - editAvatarIcon: { - textAlign: 'center', - }, bottomSheetIcon: { color: '#000000', }, }; export default EditThreadAvatar; diff --git a/native/avatars/edit-user-avatar.react.js b/native/avatars/edit-user-avatar.react.js index 67742f280..f84d2000d 100644 --- a/native/avatars/edit-user-avatar.react.js +++ b/native/avatars/edit-user-avatar.react.js @@ -1,159 +1,127 @@ // @flow import { useActionSheet } from '@expo/react-native-action-sheet'; import * as React from 'react'; -import { View, TouchableOpacity, Platform } from 'react-native'; +import { TouchableOpacity, Platform } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useSelectAndUploadFromGallery } from './avatar-hooks.js'; +import EditAvatarBadge from './edit-avatar-badge.react.js'; import SWMansionIcon from '../components/swmansion-icon.react.js'; -import { useColors, useStyles } from '../themes/colors.js'; +import { useStyles } from '../themes/colors.js'; type Props = { +children: React.Node, +onPressEmojiAvatarFlow: () => mixed, +disabled?: boolean, }; function EditUserAvatar(props: Props): React.Node { const { onPressEmojiAvatarFlow, children, disabled } = props; const { showActionSheetWithOptions } = useActionSheet(); - const colors = useColors(); const styles = useStyles(unboundStyles); const selectAndUploadFromGallery = useSelectAndUploadFromGallery(); const editAvatarOptions = React.useMemo(() => { const options = [ { id: 'emoji', text: 'Use Emoji', onPress: onPressEmojiAvatarFlow, icon: ( ), }, { id: 'image', text: 'Select image', onPress: selectAndUploadFromGallery, icon: ( ), }, ]; if (Platform.OS === 'ios') { options.push({ id: 'cancel', text: 'Cancel', isCancel: true, }); } return options; }, [ onPressEmojiAvatarFlow, selectAndUploadFromGallery, styles.bottomSheetIcon, ]); const insets = useSafeAreaInsets(); const onPressEditAvatar = React.useCallback(() => { const texts = editAvatarOptions.map(option => option.text); const cancelButtonIndex = editAvatarOptions.findIndex( option => option.isCancel, ); const containerStyle = { paddingBottom: insets.bottom, }; const icons = editAvatarOptions.map(option => option.icon); const onPressAction = (selectedIndex: ?number) => { if ( selectedIndex === null || selectedIndex === undefined || selectedIndex < 0 ) { return; } const option = editAvatarOptions[selectedIndex]; if (option.onPress) { option.onPress(); } }; showActionSheetWithOptions( { options: texts, cancelButtonIndex, containerStyle, icons, }, onPressAction, ); }, [editAvatarOptions, insets.bottom, showActionSheetWithOptions]); - const editBadge = React.useMemo(() => { - if (disabled) { - return null; - } - - return ( - - - - ); - }, [ - colors.floatingButtonLabel, - disabled, - styles.editAvatarIcon, - styles.editAvatarIconContainer, - ]); + let editBadge; + if (!disabled) { + editBadge = ; + } return ( {children} {editBadge} ); } const unboundStyles = { - editAvatarIconContainer: { - position: 'absolute', - bottom: 0, - right: 0, - borderWidth: 2, - borderColor: 'panelForeground', - borderRadius: 18, - width: 36, - height: 36, - backgroundColor: 'purpleButton', - justifyContent: 'center', - }, - editAvatarIcon: { - textAlign: 'center', - }, bottomSheetIcon: { color: '#000000', }, }; export default EditUserAvatar;