-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShareExtension.tsx
More file actions
54 lines (48 loc) · 1.5 KB
/
Copy pathShareExtension.tsx
File metadata and controls
54 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { useEffect } from "react";
import { Text, View, ActivityIndicator, StyleSheet } from "react-native";
import { close, openHostApp, type InitialProps } from "expo-share-extension";
interface PreprocessingResults {
title?: string;
content?: string;
url?: string;
byline?: string;
excerpt?: string;
imageUrl?: string;
}
export default function ShareExtension({ preprocessingResults }: InitialProps) {
useEffect(() => {
const results = (preprocessingResults ?? {}) as PreprocessingResults;
const params = new URLSearchParams();
if (results.title) params.set("title", results.title);
if (results.url) params.set("url", results.url);
if (results.byline) params.set("byline", results.byline);
if (results.imageUrl) params.set("imageUrl", results.imageUrl);
if (results.content) {
// Truncate at 200KB to stay within URL scheme limits
const content =
results.content.length > 200_000 ? results.content.slice(0, 200_000) : results.content;
params.set("content", content);
}
openHostApp(`import-article?${params.toString()}`);
close();
}, []);
return (
<View style={styles.container}>
<ActivityIndicator size="large" color="#999" />
<Text style={styles.text}>Saving article...</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#1a1a2e",
},
text: {
marginTop: 16,
color: "#999",
fontSize: 16,
},
});