GithubHelp home page GithubHelp logo

kanerogers / react-native-communications Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davebeehively/react-native-communications

0.0 2.0 0.0 138 KB

Easily call, email, text or iMessage someone in React Native

License: MIT License

JavaScript 100.00%

react-native-communications's Introduction

react-native-communications

Easily call, email, text or iMessage someone in React Native

Installation

npm install react-native-communications

Methods

phonecall(phoneNumber, prompt)

phoneNumber - String
prompt - Boolean

Both arguments are required and need to be of the correct type.

If prompt is true it uses the undocumented telprompt: url scheme. This triggers an alert asking user to confirm if they want to dial the number. There are conflicting reports around the internet about whether Apple will allow apps using this scheme to be submitted to the App store (some have had success and others have had rejections).

If you face any problems having apps approved because of this raise an issue in this repo and I will look at removing it.


email(to, cc, bcc, subject, body)

to - String Array
cc - String Array
bcc - String Array
subject - String
body - String

You must supply either 0 arguments or the full set (5).

If 0 arguments are supplied the new email view will be launched with no prefilled details.

If 5 are supplied they will be checked against their expected type and ignored if the type is incorrect.

If there are any arguments you don't want to provide a value for set them as null or undefined.

e.g.

email(['emailAddress'], null, null, null, 'my body text') would open the new email view with a recipient and body text prefilled.

email(null, ['emailAddress1', 'emailAddress2'], null, 'my subject', null) would open the new email view with two recipients in the cc field and a subject prefilled.

email([123, 'emailAddress'], null, null, 789, ['my body text']) would open the new email view with one recipient prefilled and no other values.


text(phoneNumber)

phoneNumber - String

phoneNumber is an optional argument. If it is not provided then the new message view will be launched with no recipient specified.

If it is provided but is the wrong type then again the new message view will be launched with no recipient specified.

Usage

Note: This will only work when run on an actual device. The iOS simulator does not have the required device components installed.

Assuming you have npm install -g react-native-cli, first generate an app:

react-native init RNCommunications
cd RNCommunications
npm install react-native-communications --save

Then paste the following into RNCommunications/index.ios.js:

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} = React;

var Communications = require('react-native-communications');

var RNCommunications = React.createClass({

  render: function() {
    return (
      <View style={styles.container}>
      <TouchableOpacity onPress={() => Communications.phonecall('0123456789', true)}>
        <View style={styles.phone}>
          <Text style={styles.text}>Make phonecall</Text>
        </View>
      </TouchableOpacity>
      <TouchableOpacity onPress={() => Communications.email(['emailAddress1', 'emailAddress2'],null,null,'My Subject','My body text')}>
        <View style={styles.email}>
          <Text style={styles.text}>Send an email</Text>
        </View>
      </TouchableOpacity>
      <TouchableOpacity onPress={() => Communications.text('0123456789')}>
        <View style={styles.sms}>
          <Text style={styles.text}>Send a text/iMessage</Text>
        </View>
      </TouchableOpacity>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    backgroundColor: 'rgb(253,253,253)',
  },
  phone: {
    flex: 33,
    justifyContent: 'center',
  },
  email: {
    flex: 33,
    justifyContent: 'center',
  },
  sms: {
    flex: 33,
    justifyContent: 'center',
  },
  text: {
    fontSize: 32,
  },
});

AppRegistry.registerComponent('RNCommunications', () => RNCommunications);

react-native-communications's People

Watchers

James Cloos avatar Kane Rogers-Wong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.