React Native course · Module 13: Native APIs
expo-sharing & expo-linking - Sharing and links
In this lesson3
Share content and open external apps!
expo-sharing
npx expo install expo-sharingimport * as Sharing from 'expo-sharing';
// Check availability
const isAvailable = await Sharing.isAvailableAsync();
// Share a file
async function shareFile(uri: string) {
if (await Sharing.isAvailableAsync()) {
await Sharing.shareAsync(uri, {
mimeType: 'image/jpeg',
dialogTitle: 'Share a photo from Atlantis',
});
}
}expo-linking
npx expo install expo-linkingimport * as Linking from 'expo-linking';
// Open URL
await Linking.openURL('https://atlantis.app');
// Open app settings
await Linking.openSettings();
// Check if URL can be opened
const canOpen = await Linking.canOpenURL('mailto:');
// Deep linking - creating a link to the app
const appUrl = Linking.createURL('treasure', {
queryParams: { id: '123' },
});
// Result: myapp://treasure?id=123Handling deep links
import * as Linking from 'expo-linking';
function App() {
const url = Linking.useURL();
useEffect(() => {
if (url) {
const { path, queryParams } = Linking.parse(url);
// Navigate based on deep link
if (path === 'treasure' && queryParams?.id) {
navigation.navigate('TreasureDetail', { id: queryParams.id });
}
}
}, [url]);
return <AppNavigator />;
}Docs entries used in this lesson
Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. How do you share a file?
2. How do you open app settings?
These are 2 of 3 questions for this lesson. Solve the rest in the game.
Hands-on tasks in the game
- Horizontal ordering
Arrange opening a URL: