mattermost-mobile/app/screens/post_options/options/copy_text_option.tsx
2023-05-19 13:48:00 +02:00

38 lines
1.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Clipboard from '@react-native-clipboard/clipboard';
import React, {useCallback} from 'react';
import {BaseOption} from '@components/common_post_options';
import {SNACK_BAR_TYPE} from '@constants/snack_bar';
import {t} from '@i18n';
import {dismissBottomSheet} from '@screens/navigation';
import {showSnackBar} from '@utils/snack_bar';
import type {AvailableScreens} from '@typings/screens/navigation';
type Props = {
bottomSheetId: AvailableScreens;
sourceScreen: AvailableScreens;
postMessage: string;
}
const CopyTextOption = ({bottomSheetId, postMessage, sourceScreen}: Props) => {
const handleCopyText = useCallback(async () => {
Clipboard.setString(postMessage);
await dismissBottomSheet(bottomSheetId);
showSnackBar({barType: SNACK_BAR_TYPE.MESSAGE_COPIED, sourceScreen});
}, [postMessage]);
return (
<BaseOption
i18nId={t('mobile.post_info.copy_text')}
defaultMessage='Copy Text'
iconName='content-copy'
onPress={handleCopyText}
testID='post_options.copy_text.option'
/>
);
};
export default CopyTextOption;