index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. Platform,
  7. ScrollView,
  8. DeviceEventEmitter
  9. } from 'react-native';
  10. import ContactPickerBridge from 'react-native-contacts-picker';
  11. import ContactsWrapper from 'react-native-contacts-wrapper';
  12. import checkContactsPermission from '../../tool/requestPermission';
  13. import { connect } from 'react-redux';
  14. import ContactList from './components/ContactList'
  15. import searchBar from './components/searchBar'
  16. import Search from './Search'
  17. import NewFriend from './NewFriend'
  18. import FriendsValidation from './FriendsValidation'
  19. import DetailedInfo from './DetailedInfo'
  20. import AddFriend from './AddFriend'
  21. import BottomTabNavigator from '../../navigators/BottomTabNavigator'
  22. if(Platform.OS==='android'){
  23. checkContactsPermission()
  24. }
  25. class ContactPicker extends Component {
  26. constructor(props){
  27. super(props)
  28. }
  29. componentDidMount(){
  30. const {navigation } =this.props
  31. this.subscription = DeviceEventEmitter.addListener('OPENMENUCONTACT', ()=>{
  32. navigation.navigate({ routeName:"AddFriend" })
  33. });
  34. }
  35. componentWillUnmount(){
  36. this.subscription.remove();
  37. }
  38. render() {
  39. return (
  40. // <View style={styles.container}>
  41. // <Text style={styles.welcome} onPress={this.openContactPicker}>打开通讯录选择器</Text>
  42. // <Text style={styles.welcome} onPress={this.getAllContact}>获取全部通讯录</Text>
  43. // <Text style={styles.welcome} onPress={this.checkContactPermissions}>是否有通讯录权限</Text>
  44. // <Text style={styles.welcome} onPress={()=>{this.onButtonPressed()}}>另外一个</Text>
  45. // </View>
  46. <ContactList props={this.props}/>
  47. );
  48. }
  49. onButtonPressed() {
  50. ContactsWrapper.getContact()
  51. .then((contact) => {
  52. // Replace this code
  53. console.log(contact);
  54. })
  55. .catch((error) => {
  56. console.log("ERROR CODE: ", error.code);
  57. console.log("ERROR MESSAGE: ", error.message);
  58. });
  59. }
  60. openContactPicker = () => {
  61. ContactPickerBridge.openContactPicker((result) => {
  62. console.log('openContactPicker ---->', JSON.stringify(result));
  63. });
  64. };
  65. getAllContact = () => {
  66. ContactPickerBridge
  67. .getAllContact((result) => {
  68. console.log('getAllContact ---->', JSON.stringify(result));
  69. });
  70. };
  71. checkContactPermissions = () => {
  72. ContactPickerBridge
  73. .checkContactPermissions((result) => {
  74. console.log('getAllContact ---->', JSON.stringify(result));
  75. });
  76. };
  77. }
  78. const styles = StyleSheet.create({
  79. container: {
  80. flex: 1,
  81. justifyContent: 'center',
  82. alignItems: 'center',
  83. backgroundColor: '#F5FCFF',
  84. },
  85. welcome: {
  86. fontSize: 20,
  87. textAlign: 'center',
  88. margin: 10,
  89. },
  90. instructions: {
  91. textAlign: 'center',
  92. color: '#333333',
  93. marginBottom: 5,
  94. },
  95. });
  96. ContactPicker.navigationOptions ={
  97. header: null
  98. }
  99. const getHeaderButtonClick =(state)=>{
  100. return {...state.menu}
  101. }
  102. export default connect(getHeaderButtonClick)(ContactPicker);