Plugin Architecture
Starting with version 7.0, Smart WebView introduces a powerful plugin architecture, transforming it into a more extensible foundation for building hybrid applications. This allows developers to add or modify native functionalities without altering the core project code.
Core Concepts
- Self-Contained: Plugins are designed as independent modules.
- Self-Registration: Plugins typically register themselves with the
PluginManager
(or equivalent) when their class is loaded. - Standardized Interface: Plugins implement a common interface (e.g.,
PluginInterface
on Android) defining essential lifecycle methods and interaction points. - Central Management: A manager class (e.g.,
PluginManager
) handles plugin registration, initialization, lifecycle event routing (likeonActivityResult
,onRequestPermissionsResult
,onDestroy
), and provides controlled access to shared application contexts (Activity
,WebView
,Functions
). - Configuration: Plugin behavior can often be configured externally, for instance, through the Playground class, without needing to modify the plugin’s source code.
- Event Handling: Plugins can react to WebView events (
shouldOverrideUrlLoading
,onPageStarted
,onPageFinished
) and native lifecycle events passed through thePluginManager
. - Communication: Plugins can interact with web content via JavaScript Interfaces or by handling custom URL schemes.
Benefits
- Modularity: Keeps custom features separate, improving maintainability.
- Extensibility: Easily add new native capabilities.
- Reusability: Potential for sharing plugins across projects.
- Simplified Updates: Easier core project updates when custom code is isolated.
Key Components
Ready to build your own? Check out the Creating Plugins guide. Explore the individual plugin pages for details on specific functionalities.