App.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, {Component} from 'react';
  9. import {
  10. AppRegistry,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Platform
  15. } from 'react-native';
  16. import ContactPickerBridge from 'react-native-contacts-picker';
  17. import checkContactsPermission from './requestPermission';
  18. import kiperContacts from 'react-native-kiper-contacts';
  19. if(Platform.OS==='android'){
  20. checkContactsPermission()
  21. }
  22. export default class ContactPicker extends Component {
  23. render() {
  24. return (
  25. <View style={styles.container}>
  26. <Text style={styles.welcome} onPress={this.openContactPicker}>打开通讯录选择器</Text>
  27. <Text style={styles.welcome} onPress={this.getAllContact}>获取全部通讯录</Text>
  28. <Text style={styles.welcome} onPress={this.checkContactPermissions}>是否有通讯录权限</Text>
  29. </View>
  30. );
  31. }
  32. openContactPicker = () => {
  33. ContactPickerBridge.openContactPicker((result) => {
  34. console.log('openContactPicker ---->', JSON.stringify(result));
  35. });
  36. };
  37. getAllContact = () => {
  38. ContactPickerBridge
  39. .getAllContact((result) => {
  40. console.log('getAllContact ---->', JSON.stringify(result));
  41. });
  42. };
  43. checkContactPermissions = () => {
  44. ContactPickerBridge
  45. .checkContactPermissions((result) => {
  46. console.log('getAllContact ---->', JSON.stringify(result));
  47. });
  48. };
  49. }
  50. const styles = StyleSheet.create({
  51. container: {
  52. flex: 1,
  53. justifyContent: 'center',
  54. alignItems: 'center',
  55. backgroundColor: '#F5FCFF',
  56. },
  57. welcome: {
  58. fontSize: 20,
  59. textAlign: 'center',
  60. margin: 10,
  61. },
  62. instructions: {
  63. textAlign: 'center',
  64. color: '#333333',
  65. marginBottom: 5,
  66. },
  67. });