How appodeal/react-native-appodeal works
Project Type and Purpose
• Project Type: This is a React Native module/bridge.
• Purpose: To integrate Appodeal’s native advertising SDK into React Native apps, providing both JavaScript APIs and native modules for iOS and Android.
• Key Indicators: The README describes installation steps for both platforms (iOS via CocoaPods and Android via Gradle), usage examples, extensive callback handling, and mediation adapter configuration.
File Structure
• Top-level directories include:
• android – Contains native Java code for Android (Java classes like RNAppodealModule, RNAppodealBannerManager, etc.), Gradle configuration files, and AndroidManifest.
• ios – Contains native Objective-C/Swift code (e.g., RNAppodeal.h/m, RNAppodealBannerView, etc.) and Xcode project files for iOS integration.
• src – Contains the JavaScript/TypeScript wrappers (e.g., RNAppodeal.ts, RNAppodealBanner.tsx) and event files for handling ad events.
• example – A complete sample application demonstrating how to use the module. It has its own Android and iOS folders, JavaScript code (screens, components) for the UI, and configuration files.
• The structure indicates a clear separation between the native code for each platform, the JavaScript bridge, and an example app for hands-on testing.
Key Components in the System
a. Application Layer:
• React Native Application: The app that uses react-native-appodeal via JavaScript.
b. JavaScript Bridge/Wrapper:
• Files in src (including index.ts, RNAppodeal.ts, related view components) expose the public API to the React Native layer. They call into native modules through the React Native bridge.
c. Native Modules:
• Android: Java classes (e.g., RNAppodealModule, RNAppodealPackage, managers for banner and MREC, etc.) serve as the interface to the underlying Appodeal SDK.
• iOS: Objective-C/Swift classes (e.g., RNAppodeal, RNAppodealBannerView, etc.) interact with the Appodeal SDK.
d. External SDKs and Adapters:
• Appodeal SDK: The actual advertisement platform’s SDK (versioned as per the README) and various mediation adapters (e.g., Facebook, Admob, etc.) integrated via CocoaPods or Gradle.
e. Event Handling:
• Events are managed within the JS layer (via src/events) and propagate results from native SDK callbacks up to the React Native application.
Relationships and Interactions
• The React Native Application calls API functions from the JavaScript module.
• The JavaScript API acts as a bridge by calling into the platform-specific native modules.
• The native code (Android/iOS) interfaces with the Appodeal SDK for ad management including initialization, caching, display, and event callbacks.
• Callbacks and events are sent back from the native modules to the JS layer (e.g., ad loaded, ad clicked, revenue event).
• External services such as AdMob, Facebook, Adjust, etc., may be indirectly involved through the mediation adapters as configured via dependency files (Podfile, Gradle).
Architectural Patterns and Design Principles
• Bridge Pattern: The React Native bridge effectively decouples the JS interface from the native implementations.
• Modular Design: Separation between platform-specific modules (android and ios directories) and the universal React Native module (src).
• Layered Architecture: Dividing the system into presentation (React Native screens in the example), bridging (JS API), native business logic (SDK integration), and external service adapters.
• Event-Driven Design: Extensive use of event listeners to handle asynchronous callbacks for ad lifecycle events.
Instructing the Principal Software Engineer to Include the Following Elements
• Each component should be represented as a separate entity with clear descriptive labels:
• "React Native Application" (or "Example App" from the example folder) as the consumer of the library.
• "JavaScript Bridge/API" representing the files in src.
• "Android Native Module" (detailing classes found under android/src/main/java/com/appodeal/rnappodeal) with its specific responsibilities.
• "iOS Native Module" (from the ios directory) with reference to its classes.
• "External Appodeal SDK & Adapters" which involves the underlying third-party advertising frameworks.
• Invocation calls from the React Native app to the JavaScript API.
• Communication flow from the JS API to the native modules.