How bndkt/react-native-widget-extension works
Main Components
• Expo Config Plugin Module (Plugin Code):
• Located in the “plugin” folder (and supplementary code in “src”).
• Contains code that integrates with the Expo (React Native) ecosystem via functions such as withConfig, withPodfile, withWidgetExtensionEntitlements, and withXcode.
• Houses helper methods in “plugin/src/lib” and “plugin/src/xcode” that modify the native iOS project files.
• Widget Extension Swift Files:
• Provided by the developer in a folder (e.g., “SampleWidgetExtension” as shown in the “example” folder).
• Contains key Swift source files like Attributes.swift, Module.swift, and additional asset/configuration files (e.g., Info.plist, Assets.xcassets).
• React Native App & App Configuration:
• The configuration happens via app.json where the plugin is referenced and configured (parameters like frequentUpdates, widgetsFolder, deploymentTarget, etc.).
• Acts as an entry point from the React side that calls functions such as startActivity, updateActivity, endActivity.
• Xcode Project Modifications:
• Implicit in the plugin code: the plugin uses its helper functions to update the Xcode project automatically to include the widget extension.
• This process involves modifying build phases, PBX project groups, targets, and entitlements.
• Example Application:
• Located in the “example” folder.
• Acts as a demo project that uses the plugin, providing a concrete illustration of how the widget extension is integrated.
Relationships and Data Flow
• The React Native application uses the Expo config plugin by referencing it in app.json.
• The Expo config plugin then invokes various helper functions (from “plugin/src/lib” and “plugin/src/xcode”) to modify the iOS Xcode project.
• The plugin services leverage the provided Swift widget extension code from the specified widgetsFolder.
• Relationship between the plugin processing and the native Swift widget components (e.g., Assets, module definitions, attributes).
• Finally, on the runtime side, the native Swift module exposes functions (startActivity, stopActivity, etc.) that can be called from JavaScript.
Architectural Patterns & Design Principles
• Extensibility and Modularity: The plugin is highly modular – it separates concerns between Expo configuration, native iOS modifications (handled by the helper functions) and the widget code provided by the developer.
• Integration/Bridging Layer: The plugin serves as a bridge between JavaScript (Expo/React Native) and native iOS (Swift), so it’s important to clearly mark the boundary between these layers.