import * as Sharing from 'expo-sharing'; import type { RefObject } from 'react'; import { Share, type View } from 'react-native'; import { captureRef } from 'react-native-view-shot'; import { track } from '@/lib/analytics'; /** 보이는 화면 조각을 PNG로 찍어 공유. 이미지 공유가 안 되는 곳(웹 등)이면 글로 보낸다 */ export async function shareView(ref: RefObject, { title, message }: { title: string; message: string }) { try { if (ref.current && (await Sharing.isAvailableAsync())) { const uri = await captureRef(ref, { format: 'png', quality: 1, result: 'tmpfile' }); await Sharing.shareAsync(uri, { mimeType: 'image/png', UTI: 'public.png', dialogTitle: title }); // 앱은 보이는 카드를 그대로 찍어 보내므로 비율은 'card' track('share', { content_type: 'image', item_id: title, method: 'share_sheet', ratio: 'card' }); return; } await Share.share({ message }); } catch (e) { console.warn('공유 실패', e); } }