App.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { Component } from 'react';
  2. import ContactsWrapper from 'react-native-contacts-wrapper';
  3. import {
  4. StyleSheet,
  5. Text,
  6. View,
  7. TouchableOpacity
  8. } from 'react-native';
  9. export default class App extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.onButtonPressed = this.onButtonPressed.bind(this);
  13. }
  14. onButtonPressed() {
  15. ContactsWrapper.getContact()
  16. .then((contact) => {
  17. // Replace this code
  18. console.log(contact);
  19. })
  20. .catch((error) => {
  21. console.log("ERROR CODE: ", error.code);
  22. console.log("ERROR MESSAGE: ", error.message);
  23. });
  24. }
  25. render() {
  26. return (
  27. <View style = {styles.container}>
  28. <TouchableOpacity onPress = {this.onButtonPressed}>
  29. <View style = {styles.buttonWrapper}>
  30. <Text style = {styles.buttonText}>Open Contact</Text>
  31. </View>
  32. </TouchableOpacity>
  33. </View>
  34. );
  35. }
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. flex: 1,
  40. justifyContent: 'center',
  41. alignItems: 'center',
  42. backgroundColor: '#999999',
  43. },
  44. buttonWrapper: {
  45. marginTop: 70,
  46. marginLeft: 20,
  47. marginRight:20,
  48. flexDirection: 'column',
  49. backgroundColor: '#00CCFF',
  50. borderRadius: 4
  51. },
  52. buttonText: {
  53. justifyContent: 'center',
  54. alignSelf: 'center',
  55. marginTop: 10,
  56. marginBottom: 10,
  57. marginHorizontal: 20,
  58. elevation: 1,
  59. color: '#FFFFFF'
  60. }
  61. });