reactjscordovaionic-frameworkcordova-pluginsionic-native

Ionic Native contacts spent a lot of time and blocks UI


I am developing with Ionic + Capacitor + React and I need to read all contacts numbers. Using ionic-native/contacts in this way:

import { Contacts, ContactFindOptions } from '@ionic-native/contacts';

...

loadContacts() => {
    this.setState(
        {
            loading: true,
        },
    () => {
        var contacts = new Contacts();
        const desiderFields = ['phoneNumbers'];
        var options = new ContactFindOptions();
        options.filter = '';

        options.multiple = true;
        options.hasPhoneNumber = true;
        contacts.find(desiderFields, options).then((result) => { ... } );
    });
}

componentDidMount() {
    this.loadContacts();
}

But as soon as loadContacts start reading contacts the UI blocks and not even the state has time to render to show the loader.

Plus, the it is very slow importing contacts, showing repeatedly Fetching in bulk 250 contacts!.

I know that cordova-plugin-contacts is deprecated but I can't believe that those not exists valide alternatives to this fundamental feature.

Can't find solution.


Solution

  • I found this cordova plug-in that saved my life:

    https://github.com/dbaq/cordova-plugin-contacts-phone-numbers