How hyochan/react-native-iap works
Project Type and Purpose
• This is a multi‐platform React Native library (an NPM package) that provides a unified JavaScript API for in-app purchases (IAP) across Apple App Store (StoreKit1 & StoreKit2), Google Play Billing, and Amazon IAP.
• It includes:
• Core TypeScript/JavaScript code under /src implementing hooks, event emitters, and platform abstraction.
• Native Android modules under /android/src (Play, Amazon, common) written in Kotlin/Java.
• Native iOS modules under /ios (Swift/Objective-C) bridging to StoreKit1/StoreKit2.
• An Expo config plugin (/plugin) for automating native project setup.
• An example React Native application (/IapExample) illustrating end-to-end usage.
• A documentation site (/docs) built with Docusaurus.
• CI/CD pipelines under .github/workflows, release scripts, and testing harnesses.
File Structure Analysis
• Top-level components:
• /src – Core JS API: entry point, iap.ts, hooks/, modules/ (amazon.ts, android.ts, ios.ts, iosSk2.ts, common.ts), eventEmitter.ts, PromiseUtils.
• /android – Android library source tree, with subfolders for each store flavor (main, play, amazon), test targets (testPlay, testAmazon).
• /ios – iOS native module source (Swift & Obj-C), bridging header, promise keeper, support for StoreKit2.
• /plugin – Expo config plugin source for auto-linking (withIAP.ts).
• /IapExample – React Native example app: TypeScript UI (src/), native Android & iOS projects, Metro config.
• /docs – Documentation content (MDX), config, UI components.
• CI & publishing: .github/workflows/*.yml, release-it.js, scripts/bootstrap.js.
• Tests: unit tests under /src/__tests__, /android/src/test*, /plugin/__tests__, /IapExample/__tests__.
Key Insights from README
• Unified IAP interface for multiple store SDKs.
• Hooks API for React (useIAP, withIAPContext).
• Migration notes: StoreKit2, Play Billing Library v5, Amazon 3.x SDK.
• Example usage in IapExample.
• Documentation published separately via Docusaurus.