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

expo-native-wechat

v0.1.8

Published

A Expo Module for supporting Wechat APIs on Android and iOS

Downloads

66

Readme

For Bare React Native Project

Please refer to Native Wechat

Motivation

Most developers using React Native to build apps are not equipped with native developing skills, not to mention connecting their apps with WeChat.

Especially, WeChat OpenSDK is something pain in the ass because of shitty docs where lots of APIs are not clear and intuitive. To help developers using React Native, I tried as much as possible to create this library. And I hope you benefit from this and be less frustrated with WeChat.

Why

  • Native WeChat is new, and many libraries like it are no longer maintained and keep up with the latest WeChat.
  • Native WeChat supports both legacy and new React Native architecture.
  • Native WeChat is a TurboModule that supports lazy loading, allowing for faster app startup.
  • Supports TypeScript for better intellisense and easy-to-check typing errors.
  • All Apis are promisified.

Getting Started

Configuration

Open app.json and add the following information:

{
    // Add your WeChat app ID
    "scheme": ["wx123456nxabcdefg"],
    "ios": {
      // Add your iOS universal link
      // Example "applinks:(google.com)"
      "associatedDomains": ["applinks:(Universal Link Here)"]
    },
    // Add Expo Native Wechat plugin
    "plugins": ["expo-native-wechat"]
}

Register SDK

Before invoking any APIs, registering Native WeChat by invoking registerApp is essential.

import { registerApp } from "expo-native-wechat";

useEffect(() => {
  return registerApp("wx964290141ebe9b7b");
}, []);

When invoking registerApp, there will be a listener to receive events from Wechat. registerApp returns a function to remove the listener, and no events will be received from Wechat.

Invoking API

Now is the time to invoke API. For example, we will send an auth request to Wechat and receive the code. You may use the API named sendAuthRequest here.

import { registerApp, sendAuthRequest } from "expo-native-wechat";
import { Button, Text } from "react-native";
import { verifyWechatCode } from "@/api/auth/wechat";

useEffect(() => {
  registerApp("wx964290141ebe9b7b");
}, []);

const onButtonClicked = async () => {
  const {
    data: { code },
  } = await sendAuthRequest();

  await verifyWechatCode(code);
};

return (
  <Button onClick={onButtonClicked}>
    <Text>Send Auth Request</Text>
  </Button>
);

Most APIs in Native WeChat are promisified. So is sendAuthRequest which will return a promise. When the user confirms the request on Wechat, the promise is resolved to be data with a code. All promisifed APIs return a generic type named NativeWechatResponse.

export type NativeWechatResponse<T = Record<string, unknown>> = {
  type: string;
  errorCode: number;
  errorStr: string | null;
  data: T;
};

Support

If you have trouble using this library, do not hesitate to open an issue. I am always here to help.