Monday, November 5, 2018

Share Text from your React Native App


import React, { Component } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Share } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons'

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      result: ''
    };
    this._shareMessage = this._shareMessage.bind(this)
    this._showResults = this._showResults.bind(this)
  }

  _shareMessage = () => {
    Share.share({ message: ' This is a simple shared message' }).then(this._showResults)
  }

  _showResults =(result) => {
    this.setState({ result })
  }

  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity onPress={() => this._shareMessage()}>
        <Icon name='md-share' size={45} type='ion-icon'/>
          <Text>{JSON.stringify(this.state.result)}</Text>
        </TouchableOpacity>

      </View>

    );
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  },

})








No comments:

Post a Comment