This is my code given below where I want to share this quotes on social media I try with react-native share but it only sharing hard-coded message I want to share particular post when user click on share button.
Here below I import all required library:
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
FlatList,
TouchableOpacity, Share
} from 'react-native';
import Icon from 'react-native-vector-icons';
Here below I put Share method for share content on other App:
const onShare = async () => {
try {
const result = await Share.share({
message:
'React Native | A framework for building native apps using React',
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
alert(error.message);
}
};
Here I put Quotes on Flatlist and also display it:
const sad =({navigation})=>{
return(
<View style={styles.container}>
<View>
<FlatList
data={[
{key: 'A rose by any other name would smell as sweet.'},
{key: 'All that glitters is not gold.'},
{key: 'A rose by any other name would smell as sweet.'},
{key: 'A rose by any other name would smell as sweet.'},
{key: 'A rose by any other name would smell as sweet.'},
{key: 'A rose by any other name would smell as sweet.'} ,
]}
renderItem={({item}) =>
<Text style={styles.item}>
{item.key}
<TouchableOpacity onPress={onShare} style={styles.sharebtn}>
<Text style={styles.btntext}>
Share
</Text>
</TouchableOpacity>
</Text>} />
</View>
</View>
);
};
And this is Style portion:
const styles = StyleSheet.create({
container:{
flex:1,
alignItems:'center'
},
item:{
margin:20,
fontSize: 18,
backgroundColor:'#DAD5D2',
textAlign:'center',
borderRadius:10
},
sharebtn:{
width:60,
height:30,
padding:5,
backgroundColor:'#2BDB25',
borderRadius:10
},
btntext:{
textAlign:'center'
}
});
export default sad;
question from:
https://stackoverflow.com/questions/65672171/im-creating-a-quotes-sharing-app-and-i-want-to-share-quotes-on-social-media-ho 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…