Skip to content

Commit cf85c1d

Browse files
mdvaccameta-codesync[bot]
authored andcommitted
Add KDoc documentation to ViewManagerOnDemandReactPackage (#54394)
Summary: Pull Request resolved: #54394 Added comprehensive KDoc documentation to the ViewManagerOnDemandReactPackage interface and its public methods. This interface enables lazy initialization of ViewManagers by deferring their creation until they are actually needed by JavaScript code. The documentation explains the purpose, benefits, and implementation considerations of this on-demand loading pattern. The documentation includes: - Interface-level overview explaining the lazy loading pattern and its performance benefits - Detailed method documentation for getViewManagerNames() and createViewManager() - Thread safety considerations - Parameter and return value descriptions - Usage guidelines and best practices changelog: [internal] internal Reviewed By: alanleedev Differential Revision: D86012042 fbshipit-source-id: d54fef193111c76e07aab0b69f2b567d69856bf6
1 parent 502efe1 commit cf85c1d

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.kt

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,65 @@ package com.facebook.react
1010
import com.facebook.react.bridge.ReactApplicationContext
1111
import com.facebook.react.uimanager.ViewManager
1212

13+
/**
14+
* Interface for React Native packages that provide ViewManagers on-demand rather than eagerly.
15+
*
16+
* This interface enables lazy initialization of ViewManagers, improving startup performance by
17+
* deferring the creation of ViewManager instances until they are actually needed by the JavaScript
18+
* code. Instead of instantiating all ViewManagers during package initialization, implementing
19+
* classes can defer creation until a specific ViewManager is requested by name.
20+
*
21+
* This pattern is particularly beneficial for applications with many ViewManagers, as it reduces
22+
* memory footprint and initialization time by only creating the ViewManagers that are actively
23+
* used.
24+
*
25+
* Implementing classes should maintain a registry or factory mechanism to create ViewManagers based
26+
* on their names when requested.
27+
*
28+
* @see com.facebook.react.uimanager.ViewManager
29+
* @see com.facebook.react.ReactPackage
30+
*/
1331
public interface ViewManagerOnDemandReactPackage {
1432
/**
15-
* Provides a list of names of ViewManagers with which these modules can be accessed from JS.
16-
* Typically, this is ViewManager.getName().
33+
* Provides the names of all ViewManagers available in this package.
34+
*
35+
* This method returns a collection of ViewManager names that can be accessed from JavaScript. The
36+
* names returned should match the values returned by [ViewManager.getName] for each ViewManager
37+
* that this package can create. The React Native framework uses these names to determine which
38+
* ViewManagers are available and to request their creation on-demand.
39+
*
40+
* This method is called during the initialization phase to register available ViewManagers
41+
* without actually instantiating them, enabling lazy loading.
42+
*
43+
* @param reactContext The React application context, which provides access to the Android
44+
* application context and React Native lifecycle information
45+
* @return A collection of ViewManager names. Returns an empty collection if no ViewManagers are
46+
* available. The returned names should be unique within this package
1747
*/
1848
public fun getViewManagerNames(reactContext: ReactApplicationContext): Collection<String>
1949

2050
/**
21-
* Creates and returns a ViewManager with a specific name {@param viewManagerName}. It's up to an
22-
* implementing package how to interpret the name.
51+
* Creates and returns a ViewManager instance for the specified name.
52+
*
53+
* This method is called lazily when a ViewManager is actually needed by the JavaScript code,
54+
* rather than during package initialization. The implementation should create and configure the
55+
* appropriate ViewManager based on the provided name. The name parameter corresponds to one of
56+
* the names returned by [getViewManagerNames].
57+
*
58+
* Implementations have flexibility in how they interpret the name and create ViewManagers. For
59+
* example, they might use a factory pattern, reflection, or a simple name-to-class mapping.
60+
*
61+
* This method may be called on any thread, so implementations should ensure thread safety if
62+
* necessary.
63+
*
64+
* @param reactContext The React application context, which provides access to the Android
65+
* application context and React Native lifecycle information needed to initialize the
66+
* ViewManager
67+
* @param viewManagerName The name of the ViewManager to create, matching one of the names
68+
* returned by [getViewManagerNames]
69+
* @return A ViewManager instance for the specified name, or null if the name is not recognized or
70+
* the ViewManager cannot be created. Returning null will result in a JavaScript error when the
71+
* native component is used
2372
*/
2473
public fun createViewManager(
2574
reactContext: ReactApplicationContext,

0 commit comments

Comments
 (0)