Skip to content

Commit a2581a8

Browse files
committed
feat: add sharing functionality
1 parent 8afffba commit a2581a8

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

sample-apps/react-native/ExpoTikTokApp/components/ActivityPager/PagerItem.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { ActivityResponse } from '@stream-io/feeds-react-native-sdk';
22
import { useFeedContext } from '@stream-io/feeds-react-native-sdk';
33
import React, { useMemo } from 'react';
44
import {
5-
Alert,
65
Dimensions,
76
StyleSheet,
87
Text,
@@ -18,6 +17,7 @@ import { Bookmark } from '@/components/Bookmark';
1817
import { useRouter } from 'expo-router';
1918
import { useSafeAreaInsets } from 'react-native-safe-area-context';
2019
import { LocationPreview } from '@/components/LocationPreview';
20+
import { ShareButton } from '@/components/Share';
2121

2222
const { height: SCREEN_HEIGHT } = Dimensions.get('window');
2323

@@ -95,16 +95,9 @@ const UnmemoizedPagerItem = ({
9595
<Text style={styles.iconLabel}>{activity.bookmark_count ?? 0}</Text>
9696
</TouchableOpacity>
9797

98-
<TouchableOpacity
99-
onPress={() =>
100-
Alert.alert(
101-
'Sharing was captured successfully, but is not implemented yet !',
102-
)
103-
}
104-
style={styles.iconContainer}
105-
>
106-
<Ionicons name="arrow-redo-outline" size={28} color="white" />
107-
</TouchableOpacity>
98+
<View style={styles.iconContainer}>
99+
<ShareButton attachment={videoAttachment} />
100+
</View>
108101
</View>
109102
</View>
110103
);

sample-apps/react-native/ExpoTikTokApp/components/LocationPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Place } from '@/components/PlaceSearchDropdown';
55
import { useRouter } from 'expo-router';
66

77
type LocationPreviewProps = {
8-
location: Omit<Place, 'id'>;
8+
location: Omit<Place, 'id' | 'address'>;
99
};
1010

1111
export const LocationPreview = ({ location }: LocationPreviewProps) => {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Ionicons } from '@expo/vector-icons';
2+
import { Share, TouchableOpacity } from 'react-native';
3+
import React from 'react';
4+
import {
5+
Attachment,
6+
isImageFile,
7+
isVideoFile,
8+
} from '@stream-io/feeds-react-native-sdk';
9+
import { useStableCallback } from '@/hooks/useStableCallback';
10+
11+
const pretext = 'Check out this cool';
12+
13+
export const ShareButton = ({ attachment }: { attachment: Attachment }) => {
14+
const shareText = attachment.image_url
15+
? `${pretext} image ! ${attachment.image_url}`
16+
: `${pretext} video ! ${attachment.asset_url}`;
17+
18+
const shareContent = useStableCallback(async () => {
19+
try {
20+
await Share.share({
21+
message: shareText,
22+
title: 'ExpoTikTokApp',
23+
});
24+
} catch (error) {
25+
console.error('Error sharing:', error);
26+
}
27+
});
28+
29+
return (
30+
<TouchableOpacity onPress={shareContent}>
31+
<Ionicons name="arrow-redo-outline" size={28} color="white" />
32+
</TouchableOpacity>
33+
);
34+
};

0 commit comments

Comments
 (0)