How hyochan/expo-iap works
Project type and purpose
• This is an open-source Expo “in-app purchases” (IAP) module conforming to the Open IAP specification.
• It’s a library (not a standalone app) that exposes a JavaScript API, bridges into native Android/iOS modules, and includes an Expo plugin for project configuration.
Main components
a. Host Application (Expo/React-Native)
b. JS Layer (expo-iap package)
• src/index.ts, useIAP.ts, helpers, utils
c. Native Modules
• Android: ExpoIapModule.kt, PlayUtils.kt, Types.kt
• iOS: ExpoIapModule.swift, Podspec
d. Expo Module Infrastructure
• expo-module.config.json, expo-modules-core at runtime
e. Expo Plugin
• plugin/src/withIAP.ts, withLocalOpenIAP.ts – configures Android build properties
f. External Services
• Google Play Billing (Android)
• Apple App Store StoreKit (iOS)
• Open IAP specification endpoint (for standardization)
g. Example App & Test Harness
• example/ directory: demonstrates usage, test files, metro/jest configs
h. Documentation Site
• docs/ directory powered by Docusaurus
Relationships & data flows
• Host App → JS Layer: imports expo-iap API calls (e.g., getProducts, requestPurchase)
• JS Layer → Native Module: through the Expo Modules bridge
• Native Module ↔ External Service:
• Android native module ↔ Google Play Billing Library v8
• iOS native module ↔ StoreKit API
• Responses flow back: Store → Native → JS → Host
• Plugin at build time modifies Gradle/Kotlin settings to support required billing library version
• Example App illustrates end-to-end flow and triggers tests
• Documentation site is static content—no runtime flow but part of repo
Architectural patterns & design principles
• Bridge pattern: JS calls bridged into native code
• Adapter pattern: Native modules adapt to the Open IAP spec
• Modular layering: clear separation between JS, native, build-time plugin, and docs
• Platform abstraction: src/modules/android.ts & src/modules/ios.ts select platform-specific implementations
Detailed elements to capture
• JS entrypoint (src/index.ts) and hooks (useIAP.ts)
• Platform files (modules/android.ts, modules/ios.ts)
• Native code under android/src/main/java and ios/
• Expo plugin folder (plugin/src/...) and expo-module.config.json
• Example app illustrating consumption of the module
• Documentation site driven by docs/docusaurus.config.ts
• Top: Host Application
• Next row: JS Layer (expo-iap API) invoking helper/util modules
• Middle: Platform selection → native modules
• Bottom: External Billing Services
• Side: Build-time plugin modifying project config
This detailed breakdown ensures you capture every key part—JS API, native bridge, external services, build-time configuration, docs, and example usage.