Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

react native - I'm creating a quotes sharing App and I want to share quotes on social media. How to share particular quotes?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...