npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-jsi-contacts

v0.2.3

Published

A contacts library for React Native using JSI

Downloads

11

Readme

react-native-jsi-contacts

The current react-native-contacts library uses the React Native Bridge to convert the native Java/Objective-C types to JavaScript values. This is asynchronous, batched, and serializes the huge contacts list in the native world (write into WritableArray/WritableMap, then let the Bridge convert to JSON), then deserializes it on the JavaScript side using JSON. It is therefore slow.

react-native-jsi-contacts uses JSI to be way faster.

  • Direct invocation (no batching!)
  • No JSON serialization happening
  • Directly convert object into JSI Types
  • Lazily get individual Contact fields (jsi::HostObject lazy-get)

⚠️ react-native-jsi-contacts only works on Android. If you want me to implement iOS support, consider funding the project.

Performance

The library uses almost the same native "getContacts()" function as react-native-contacts (minor tweaks to not use the Bridge types WritableArray/WritableMap), so the only difference is the conversion speed.

For 25 contacts, I have measured an average speed increase of ~35%, this greatly scales with the amount of contacts you have though.

 LOG  JSI: Contacts Permission: granted
 LOG  JSI: Got: 25 contacts in 55.14947900176048ms.
 LOG  Bridge: Contacts Permission: granted
 LOG  Bridge: Got: 25 contacts in 74.15260401368141ms.

For 25 contacts, the conversion between the native Java Contacts list and the JavaScript Contacts list takes only ~3 milliseconds!

Installation

  1. Install using npm/yarn

    npm install react-native-jsi-contacts
  2. Add this code:

    JsiContactsModule.install(reactApplicationContext);

    to your JSIModulePackage's getJSIModules method. See the react-native-mmkv installation guide on how to create a JSIModulePackage.

Sponsors

This project is sponsored by Galaxycard.

Usage

Get a list of all contacts:

import { getContactsAsync } from "react-native-jsi-contacts";

const contacts = await getContactsAsync();

Get a hashsum to compare for any changes in the contact book:

import { getHashAsync } from "react-native-jsi-contacts";
import { MMKV } from "react-native-mmkv";

const storage = new MMKV();

const hash = await getHashAsync();
const previousHash = storage.getString("contactsHash")
if (previousHash !== hash) {
  // get all contacts and reload hash now.
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Thanks

  • Thanks to GalaxyCard for sponsoring this project
  • Thanks to react-native-contacts for the native "getContacts()" implementation