forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting packages into core bridge and core RN
Reviewed By: javache Differential Revision: D4953811 fbshipit-source-id: 05ab9acc81e31bbb85005cd80eeebc550a6c452e
- Loading branch information
1 parent
0fd061e
commit e301a36
Showing
5 changed files
with
319 additions
and
13 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
ReactAndroid/src/main/java/com/facebook/react/BridgeCorePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* 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 javax.inject.Provider; | ||
|
||
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; | ||
import com.facebook.react.module.annotations.ReactModuleList; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
import com.facebook.react.modules.core.HeadlessJsTaskSupportModule; | ||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; | ||
import com.facebook.react.modules.core.DeviceEventManagerModule; | ||
import com.facebook.react.modules.core.ExceptionsManagerModule; | ||
import com.facebook.react.modules.core.Timing; | ||
import com.facebook.react.modules.debug.SourceCodeModule; | ||
import com.facebook.react.modules.deviceinfo.DeviceInfoModule; | ||
import com.facebook.react.modules.systeminfo.AndroidInfoModule; | ||
|
||
/** | ||
* Package defining core framework modules for basic JS interop. | ||
* It should be used for modules that are always necessary for interacting with | ||
* JS, not for modules that provide RN specific functionality | ||
*/ | ||
@ReactModuleList( | ||
nativeModules = { | ||
AndroidInfoModule.class, | ||
DeviceEventManagerModule.class, | ||
ExceptionsManagerModule.class, | ||
HeadlessJsTaskSupportModule.class, | ||
SourceCodeModule.class, | ||
Timing.class, | ||
DeviceInfoModule.class, | ||
} | ||
) | ||
/* package */ class BridgeCorePackage extends LazyReactPackage { | ||
|
||
private final ReactInstanceManager mReactInstanceManager; | ||
private final DefaultHardwareBackBtnHandler mHardwareBackBtnHandler; | ||
|
||
BridgeCorePackage( | ||
ReactInstanceManager reactInstanceManager, | ||
DefaultHardwareBackBtnHandler hardwareBackBtnHandler) { | ||
mReactInstanceManager = reactInstanceManager; | ||
mHardwareBackBtnHandler = hardwareBackBtnHandler; | ||
} | ||
|
||
@Override | ||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) { | ||
List<ModuleSpec> moduleSpecList = new ArrayList<>(); | ||
|
||
moduleSpecList.add( | ||
new ModuleSpec(AndroidInfoModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new AndroidInfoModule(); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(DeviceEventManagerModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(ExceptionsManagerModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager()); | ||
} | ||
})); | ||
moduleSpecList | ||
.add(new ModuleSpec(HeadlessJsTaskSupportModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new HeadlessJsTaskSupportModule(reactContext); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(SourceCodeModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new SourceCodeModule(reactContext); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(Timing.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new Timing(reactContext, mReactInstanceManager.getDevSupportManager()); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(DeviceInfoModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new DeviceInfoModule(reactContext); | ||
} | ||
})); | ||
|
||
return moduleSpecList; | ||
} | ||
|
||
@Override | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
return LazyReactPackage.getReactModuleInfoProviderViaReflection(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* 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 javax.inject.Provider; | ||
|
||
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; | ||
import com.facebook.react.devsupport.JSCHeapCapture; | ||
import com.facebook.react.devsupport.JSCSamplingProfiler; | ||
import com.facebook.react.module.annotations.ReactModuleList; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
import com.facebook.react.uimanager.debug.DebugComponentOwnershipModule; | ||
|
||
/** | ||
* Package defining core framework modules (e.g. UIManager). It should be used for modules that | ||
* require special integration with other framework parts (e.g. with the list of packages to load | ||
* view managers from). | ||
*/ | ||
@ReactModuleList( | ||
nativeModules = { | ||
DebugComponentOwnershipModule.class, | ||
JSCHeapCapture.class, | ||
JSCSamplingProfiler.class, | ||
} | ||
) | ||
/* package */ class DebugCorePackage extends LazyReactPackage { | ||
|
||
DebugCorePackage() { | ||
} | ||
|
||
@Override | ||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) { | ||
List<ModuleSpec> moduleSpecList = new ArrayList<>(); | ||
|
||
moduleSpecList.add( | ||
new ModuleSpec(DebugComponentOwnershipModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new DebugComponentOwnershipModule(reactContext); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(JSCHeapCapture.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new JSCHeapCapture(reactContext); | ||
} | ||
})); | ||
moduleSpecList.add( | ||
new ModuleSpec(JSCSamplingProfiler.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return new JSCSamplingProfiler(reactContext); | ||
} | ||
})); | ||
return moduleSpecList; | ||
} | ||
|
||
@Override | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
return LazyReactPackage.getReactModuleInfoProviderViaReflection(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
ReactAndroid/src/main/java/com/facebook/react/ReactNativeCorePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* 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 javax.inject.Provider; | ||
|
||
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; | ||
import com.facebook.react.bridge.ReactMarker; | ||
import com.facebook.react.module.annotations.ReactModuleList; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
import com.facebook.react.uimanager.UIImplementationProvider; | ||
import com.facebook.react.uimanager.UIManagerModule; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.systrace.Systrace; | ||
|
||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END; | ||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START; | ||
|
||
/** | ||
* Package defining core framework modules for initializing ReactNative (e.g. UIManager). It should be used for modules that | ||
* require special integration with other framework parts (e.g. with the list of packages to load | ||
* view managers from). | ||
*/ | ||
@ReactModuleList( | ||
nativeModules = { | ||
UIManagerModule.class, | ||
} | ||
) | ||
public class ReactNativeCorePackage extends LazyReactPackage { | ||
|
||
private final ReactInstanceManager mReactInstanceManager; | ||
private final UIImplementationProvider mUIImplementationProvider; | ||
private final boolean mLazyViewManagersEnabled; | ||
|
||
public ReactNativeCorePackage( | ||
ReactInstanceManager reactInstanceManager, | ||
UIImplementationProvider uiImplementationProvider, | ||
boolean lazyViewManagersEnabled) { | ||
mReactInstanceManager = reactInstanceManager; | ||
mUIImplementationProvider = uiImplementationProvider; | ||
mLazyViewManagersEnabled = lazyViewManagersEnabled; | ||
} | ||
|
||
@Override | ||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) { | ||
List<ModuleSpec> moduleSpecList = new ArrayList<>(); | ||
|
||
moduleSpecList.add( | ||
new ModuleSpec(UIManagerModule.class, new Provider<NativeModule>() { | ||
@Override | ||
public NativeModule get() { | ||
return createUIManager(reactContext); | ||
} | ||
})); | ||
|
||
return moduleSpecList; | ||
} | ||
|
||
@Override | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
// This has to be done via reflection or we break open source. | ||
ReactModuleInfoProvider reactModuleInfoProvider = | ||
LazyReactPackage.getReactModuleInfoProviderViaReflection(this); | ||
return reactModuleInfoProvider; | ||
} | ||
|
||
private UIManagerModule createUIManager(ReactApplicationContext reactContext) { | ||
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START); | ||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule"); | ||
try { | ||
List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers( | ||
reactContext); | ||
return new UIManagerModule( | ||
reactContext, | ||
viewManagersList, | ||
mUIImplementationProvider, | ||
mLazyViewManagersEnabled); | ||
} finally { | ||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); | ||
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END); | ||
} | ||
} | ||
} |