react-native-communications
Advanced tools
Comparing version 1.0.1 to 2.0.0
'use strict'; | ||
var React = require('react-native'); | ||
var { | ||
import { | ||
Linking, | ||
Platform, | ||
} = React; | ||
} from 'react-native'; | ||
var communication = { | ||
phonecall: function(phoneNumber, prompt) { | ||
const communication = { | ||
phonecall(phoneNumber, prompt) { | ||
if(arguments.length !== 2) { | ||
@@ -26,3 +25,3 @@ console.log('you must supply exactly 2 arguments'); | ||
var url; | ||
let url; | ||
@@ -41,5 +40,5 @@ if(Platform.OS !== 'android') { | ||
email: function(to, cc, bcc, subject, body){ | ||
var url = 'mailto:'; | ||
var argLength = arguments.length; | ||
email(to, cc, bcc, subject, body){ | ||
let url = 'mailto:'; | ||
let argLength = arguments.length; | ||
@@ -59,7 +58,7 @@ switch(argLength) { | ||
// it helps us know when we need to add & to separate parameters | ||
var valueAdded = false; | ||
let valueAdded = false; | ||
if(isCorrectType('Array', arguments[0])) { | ||
var validAddresses = getValidArgumentsFromArray(arguments[0], 'String'); | ||
let validAddresses = getValidArgumentsFromArray(arguments[0], 'String'); | ||
if(validAddresses.length > 0) { | ||
@@ -73,3 +72,3 @@ url += validAddresses.join(','); | ||
if(isCorrectType('Array', arguments[1])) { | ||
var validAddresses = getValidArgumentsFromArray(arguments[1], 'String'); | ||
let validAddresses = getValidArgumentsFromArray(arguments[1], 'String'); | ||
@@ -87,4 +86,4 @@ if(validAddresses.length > 0) { | ||
var validAddresses = getValidArgumentsFromArray(arguments[2], 'String'); | ||
let validAddresses = getValidArgumentsFromArray(arguments[2], 'String'); | ||
if(validAddresses.length > 0) { | ||
@@ -118,3 +117,3 @@ valueAdded = true; | ||
text: function(phoneNumber) { | ||
text(phoneNumber) { | ||
if(arguments.length > 1) { | ||
@@ -125,3 +124,3 @@ console.log('you supplied too many arguments. You can either supply 0 or 1'); | ||
var url = 'sms:'; | ||
let url = 'sms:'; | ||
@@ -132,4 +131,4 @@ if(arguments.length !== 0) { | ||
} else { | ||
console.log('the phone number should be provided as a string. It was provided as ' | ||
+ Object.prototype.toString.call(phoneNumber).slice(8, -1) | ||
console.log('the phone number should be provided as a string. It was provided as ' | ||
+ Object.prototype.toString.call(phoneNumber).slice(8, -1) | ||
+ ',ignoring the value provided'); | ||
@@ -141,17 +140,18 @@ } | ||
}, | ||
web: function(address) { | ||
if(!address) { | ||
console.log('Missing address argument'); | ||
return; | ||
} | ||
if(!isCorrectType('String', address)) { | ||
console.log('address was not provided as a string, it was provided as ' | ||
+ Object.prototype.toString.call(address).slice(8, -1)); | ||
return; | ||
} | ||
LaunchURL(address); | ||
web(address) { | ||
if(!address) { | ||
console.log('Missing address argument'); | ||
return; | ||
} | ||
if(!isCorrectType('String', address)) { | ||
console.log('address was not provided as a string, it was provided as ' | ||
+ Object.prototype.toString.call(address).slice(8, -1)); | ||
return; | ||
} | ||
LaunchURL(address); | ||
} | ||
}; | ||
var LaunchURL = function(url) { | ||
const LaunchURL = (url) => { | ||
Linking.canOpenURL(url).then(supported => { | ||
@@ -166,3 +166,3 @@ if(!supported) { | ||
var getValidArgumentsFromArray = function(array, type) { | ||
const getValidArgumentsFromArray = (array, type) => { | ||
var validValues = []; | ||
@@ -178,6 +178,6 @@ array.forEach(function(value) { | ||
var isCorrectType = function(expected, actual) { | ||
const isCorrectType = (expected, actual) => { | ||
return Object.prototype.toString.call(actual).slice(8, -1) === expected; | ||
}; | ||
module.exports = communication; | ||
export default communication; |
{ | ||
"name": "react-native-communications", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Open a web address or call, email, text or iMessage (iOS only) someone in React Native", | ||
@@ -5,0 +5,0 @@ "main": "AKCommunications.js", |
@@ -9,3 +9,3 @@ # react-native-communications | ||
If you are on **React Native >= 0.20** just | ||
**React Native >= 0.25** | ||
@@ -16,2 +16,10 @@ ```bash | ||
--- | ||
**React Native >=0.20 < 0.25** | ||
```bash | ||
npm install react-native-communications@1.0.1 | ||
``` | ||
**Note:** Do not use version 1.0.0 of this module as it contained a bug with the phonecall method. | ||
@@ -21,3 +29,3 @@ | ||
**Versions 0.15 through to and including 0.19 of React Native** are also supported by running the following installation command | ||
**React Native >=0.15 <=0.19** | ||
@@ -28,2 +36,4 @@ ```bash | ||
--- | ||
## Methods | ||
@@ -115,41 +125,44 @@ | ||
**Note:** The following sample code has been updated to use es6 syntax and imports supported from React Native 0.25 onwards | ||
```js | ||
'use strict'; | ||
var React = require('react-native'); | ||
var { | ||
import React from 'react'; | ||
import { | ||
AppRegistry, | ||
StyleSheet, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
} = React; | ||
TouchableOpacity | ||
} from 'react-native'; | ||
var Communications = require('react-native-communications'); | ||
import Communications from 'react-native-communications'; | ||
var RNCommunications = React.createClass({ | ||
const RNCommunications = React.createClass({ | ||
render: function() { | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<TouchableOpacity onPress={() => Communications.phonecall('0123456789', true)}> | ||
<View style={styles.holder}> | ||
<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.holder}> | ||
<Text style={styles.text}>Send an email</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => Communications.text('0123456789')}> | ||
<View style={styles.holder}> | ||
<Text style={styles.text}>Send a text/iMessage</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => Communications.web('https://github.com/facebook/react-native')}> | ||
<View style={styles.holder}> | ||
<Text style={styles.text}>Open react-native repo on Github</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => Communications.phonecall('0123456789', true)}> | ||
<View style={styles.holder}> | ||
<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.holder}> | ||
<Text style={styles.text}>Send an email</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => Communications.text('0123456789')}> | ||
<View style={styles.holder}> | ||
<Text style={styles.text}>Send a text/iMessage</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => Communications.web('https://github.com/facebook/react-native')}> | ||
<View style={styles.holder}> | ||
<Text style={styles.text}>Open react-native repo on Github</Text> | ||
</View> | ||
</TouchableOpacity> | ||
</View> | ||
@@ -156,0 +169,0 @@ ); |
10961
188
136