Share funktion
This commit is contained in:
@@ -4,7 +4,7 @@ import { useRouter } from 'expo-router';
|
||||
import { parseShareIntent, ShareIntentModule } from 'expo-share-intent';
|
||||
import * as ExpoLinking from 'expo-linking';
|
||||
import { SHARE_INTENT_KEY, storeSharedImageUri } from '../utils/shareHandoff';
|
||||
import { resolveSharedImageUri, summarizeShareIntent } from '../utils/shareIntent';
|
||||
import { isSharedImageResolutionFailure, resolveSharedImageUri, summarizeShareIntent } from '../utils/shareIntent';
|
||||
|
||||
const SHARE_INTENT_SCHEME = 'greenlens';
|
||||
const SHARE_INTENT_OPTIONS = {
|
||||
@@ -16,6 +16,8 @@ export default function ShareIntentCallbackScreen() {
|
||||
const router = useRouter();
|
||||
const [isWaiting, setIsWaiting] = React.useState(true);
|
||||
const [failureDetails, setFailureDetails] = React.useState<string | null>(null);
|
||||
const [failureTitle, setFailureTitle] = React.useState<string | null>(null);
|
||||
const [failureBody, setFailureBody] = React.useState<string | null>(null);
|
||||
const [previewUri, setPreviewUri] = React.useState<string | null>(null);
|
||||
const pendingKeyRef = React.useRef<string | null>(null);
|
||||
const getIntentCalledRef = React.useRef(false);
|
||||
@@ -33,11 +35,13 @@ export default function ShareIntentCallbackScreen() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const showFailure = (message: string) => {
|
||||
const showFailure = (message: string, title?: string, body?: string) => {
|
||||
settledRef.current = true;
|
||||
ShareIntentModule?.clearShareIntent(SHARE_INTENT_KEY);
|
||||
setPreviewUri(null);
|
||||
setIsWaiting(false);
|
||||
setFailureTitle(title ?? null);
|
||||
setFailureBody(body ?? null);
|
||||
setFailureDetails(message);
|
||||
};
|
||||
|
||||
@@ -45,13 +49,23 @@ export default function ShareIntentCallbackScreen() {
|
||||
try {
|
||||
setIsWaiting(true);
|
||||
setFailureDetails(null);
|
||||
setFailureTitle(null);
|
||||
setFailureBody(null);
|
||||
const shareIntent = parseShareIntent(event.value, SHARE_INTENT_OPTIONS);
|
||||
if (__DEV__) {
|
||||
console.debug('[ShareIntentCallback]', summarizeShareIntent(shareIntent));
|
||||
}
|
||||
const resolved = await resolveSharedImageUri(shareIntent);
|
||||
if (!resolved) {
|
||||
showFailure('Die Quelle hat keinen nutzbaren Bildanhang oder Bild-Link geliefert.');
|
||||
if (isSharedImageResolutionFailure(resolved)) {
|
||||
if (resolved.failureReason === 'login_wall') {
|
||||
showFailure(
|
||||
'Die geteilte Seite verlangt einen Login und hat das Bild nicht ausgeliefert.',
|
||||
'Instagram hat den Post nicht freigegeben',
|
||||
'Mach einen Screenshot vom Post und teile den Screenshot mit GreenLens — das funktioniert immer.',
|
||||
);
|
||||
} else {
|
||||
showFailure('Die Quelle hat keinen nutzbaren Bildanhang oder Bild-Link geliefert.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
settledRef.current = true;
|
||||
@@ -118,9 +132,10 @@ export default function ShareIntentCallbackScreen() {
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.messageBox}>
|
||||
<Text style={styles.title}>Bild konnte nicht geladen werden.</Text>
|
||||
<Text style={styles.title}>{failureTitle ?? 'Bild konnte nicht geladen werden.'}</Text>
|
||||
<Text style={styles.body}>
|
||||
Tippe und halte das Bild in Safari oder Instagram, wähle „Bild teilen" und teile es direkt mit GreenLens.
|
||||
{failureBody
|
||||
?? 'Tippe und halte das Bild in Safari oder Instagram, wähle „Bild teilen" und teile es direkt mit GreenLens.'}
|
||||
</Text>
|
||||
{failureDetails ? (
|
||||
<Text style={styles.detail}>{failureDetails}</Text>
|
||||
|
||||
Reference in New Issue
Block a user