mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-17 12:19:12 +08:00
Add LazyReactPackage
Summary: LazyReactPackage is an extension of ReactPackage that allows us to lazily construct native modules. It's a separate class to avoid breaking existing packages both internally and in open source. Reviewed By: astreet Differential Revision: D3334258 fbshipit-source-id: e090e146adc4e8e156cae217689e2258ab9837aa
This commit is contained in:
committed by
Facebook Github Bot 3
parent
dba1ce46bf
commit
1feb462f44
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
|
||||
/**
|
||||
* React package supporting lazy creation of native modules.
|
||||
*
|
||||
* TODO(t11394819): Make this default and deprecate ReactPackage
|
||||
*/
|
||||
public abstract class LazyReactPackage implements ReactPackage {
|
||||
/**
|
||||
* @param reactContext react application context that can be used to create modules
|
||||
* @return list of module specs that can create the native modules
|
||||
*/
|
||||
public abstract List<ModuleSpec> getNativeModules(
|
||||
ReactApplicationContext reactContext);
|
||||
|
||||
@Override
|
||||
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
for (ModuleSpec holder : getNativeModules(reactContext)) {
|
||||
modules.add(holder.getProvider().get());
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user