How adaptyteam/adaptysdk-react-native works
Project Type and Purpose
• This is an open-source React Native SDK (“react-native-adapty”) for in-app purchase and subscription management.
• It provides a JavaScript/TypeScript API, native bridges (Android & iOS), UI components for paywalls, and integrates with the Adapty backend to handle A/B testing, analytics, and purchase events without server coding.
File-Structure Analysis
• Root: config files (.eslintrc.js, babel.config.js, TypeScript configs, CI scripts).
• src/: core TS library
• index.ts exports public API
• bridge.ts → RN bridge to native modules (NativeModules/TurboModules)
• coders/ → Data-Mapper layer (maps raw JSON ↔ TS models)
• native-request-handler/ → unified request dispatcher for platform calls
• ui/ → JS wrapper for native UI (OnboardingView), view controller & emitter
• logger/ → structured logging context & scopes
• types/ → shared type definitions
• android/: Android native module code
• AdaptyReactModule.kt, AdaptyOnboardingViewManager.kt
• Gradle build scripts & manifest
• ios/: iOS native module code
• Obj-C/Swift bridge files (RNAdapty.m, AdaptyOnboardingWrapperView.swift, bridging header)
• Xcode project & Podspec
• scripts/: packaging, version bumping, linking, cleaning
• examples/: two sample apps (bare RN + Expo) showcasing integration
README Insights
• Highlights compatibility with RN New Architecture (TurboModules) & legacy bridge
• Emphasizes no-server integration, real-time analytics, UI paywalls, A/B tests
• Points to examples/ for usage reference
a. Main Components
• App Code (Consumer): Your React Native app imports react-native-adapty.
• JS/TS Layer:
– *Public API* (src/index.ts)
– *Data Mapper* (src/coders)
– *Bridge* (src/bridge.ts)
– *Logger* (src/logger)
• Native Modules:
– Android (android/src/.../AdaptyReactModule.kt, view manager)
– iOS (ios/RNAdapty.*, AdaptyOnboardingWrapperView.*)
• Native Adapty SDK: platform SDKs for purchase handling & networking
• Adapty Backend: REST/WebSocket endpoints for paywalls, analytics, user profiles
• UI Component:
– *JS Wrapper* (src/ui/AdaptyOnboardingView.tsx)
– *Native View Managers* (Android/iOS)
• Build & Release: TS compiler, Podspec (iOS), Gradle & Maven (Android), npm packaging
b. Relationships & Interactions
1. App Code calls → JS/TS Public API
2. Public API delegates → Bridge
3. Bridge invokes → Native Module (via NativeModules or TurboModule)
4. Native Module interacts → Native Adapty SDK for purchases, paywall configs, analytics
5. Native SDK communicates → Adapty Backend over HTTPS/WebSockets
6. Responses flow back → native → bridge → JS → coders convert → API returns to app
7. UI Events (purchase button tapped) propagate from Native View → emitter → JS handler
c. Architectural Patterns & Principles
• Layered Architecture: clear separation between JS logic, bridge, native code, and external services
• Bridge Pattern: cross‐language communication (JS ↔ Native)
• Data Mapper: coders/ modules translate raw JSON to rich TS models
• Publisher/Subscriber: UI emitter & logger scopes for events and diagnostics
• Modularization: separate folders for coders, UI, types, and native‐request handling
d. Key Technologies & Frameworks
• React Native (legacy bridge & TurboModules)
• Kotlin/Java for Android module
• Swift/Objective-C for iOS module
• TypeScript for core library
• Gradle, CocoaPods, npm for build & distribution
• Jest for tests (jest.config.cjs, tests in src/coders)
Diagrammatic Elements
• Blue = JavaScript/TypeScript layers
• Green = Native modules (Android/iOS)
• Orange = External Adapty backend
• Gray = Build tooling & scripts
• Rounded rectangles for code modules
• Parallelograms for UI components