mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
add more Systrace to native module / view manager constants
Reviewed By: lexs Differential Revision: D3739966 fbshipit-source-id: 4ba31aade00852132e528f96252197b823bb58a3
This commit is contained in:
parent
14188289fc
commit
924187eb9a
@ -15,6 +15,10 @@ 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.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
/**
|
||||
* React package supporting lazy creation of native modules.
|
||||
@ -33,7 +37,14 @@ public abstract class LazyReactPackage implements ReactPackage {
|
||||
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
for (ModuleSpec holder : getNativeModules(reactContext)) {
|
||||
modules.add(holder.getProvider().get());
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
|
||||
.arg("module", holder.getType())
|
||||
.flush();
|
||||
try {
|
||||
modules.add(holder.getProvider().get());
|
||||
} finally {
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
@ -925,10 +925,10 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
}
|
||||
|
||||
private void processPackage(
|
||||
ReactPackage reactPackage,
|
||||
ReactApplicationContext reactContext,
|
||||
NativeModuleRegistry.Builder nativeRegistryBuilder,
|
||||
JavaScriptModuleRegistry.Builder jsModulesBuilder) {
|
||||
ReactPackage reactPackage,
|
||||
ReactApplicationContext reactContext,
|
||||
NativeModuleRegistry.Builder nativeRegistryBuilder,
|
||||
JavaScriptModuleRegistry.Builder jsModulesBuilder) {
|
||||
for (NativeModule nativeModule : reactPackage.createNativeModules(reactContext)) {
|
||||
nativeRegistryBuilder.add(nativeModule);
|
||||
}
|
||||
|
@ -15,13 +15,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.ExecutorToken;
|
||||
import com.facebook.react.bridge.NativeArray;
|
||||
import com.facebook.react.bridge.ReadableNativeArray;
|
||||
import com.facebook.react.bridge.WritableNativeArray;
|
||||
import com.facebook.react.bridge.WritableNativeMap;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
/**
|
||||
* This is part of the glue which wraps a java BaseJavaModule in a C++
|
||||
@ -120,8 +124,23 @@ import com.facebook.react.bridge.WritableNativeArray;
|
||||
// NativeMap out of OnLoad.
|
||||
@DoNotStrip
|
||||
public NativeArray getConstants() {
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants")
|
||||
.arg("moduleName", getName())
|
||||
.flush();
|
||||
Map<String, Object> map = mModule.getConstants();
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants")
|
||||
.arg("moduleName", getName())
|
||||
.flush();
|
||||
WritableNativeMap writableNativeMap;
|
||||
try {
|
||||
writableNativeMap = Arguments.makeNativeMap(map);
|
||||
} finally {
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
WritableNativeArray array = new WritableNativeArray();
|
||||
array.pushMap(Arguments.makeNativeMap(mModule.getConstants()));
|
||||
array.pushMap(writableNativeMap);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@ -103,11 +101,6 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||
return "RKCameraRollManager";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an image to the gallery (i.e. {@link MediaStore.Images}). This copies the original file
|
||||
* from wherever it may be to the external storage pictures directory, so that it can be scanned
|
||||
@ -440,5 +433,4 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||
node.putMap("location", location);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
/**
|
||||
* Helps generate constants map for {@link UIManagerModule} by collecting and merging constants from
|
||||
@ -42,29 +46,36 @@ import com.facebook.react.common.MapBuilder;
|
||||
Map directEventTypesConstants = UIManagerModuleConstants.getDirectEventTypeConstants();
|
||||
|
||||
for (ViewManager viewManager : viewManagers) {
|
||||
Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
|
||||
if (viewManagerBubblingEvents != null) {
|
||||
recursiveMerge(bubblingEventTypesConstants, viewManagerBubblingEvents);
|
||||
}
|
||||
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
|
||||
if (viewManagerDirectEvents != null) {
|
||||
recursiveMerge(directEventTypesConstants, viewManagerDirectEvents);
|
||||
}
|
||||
Map viewManagerConstants = MapBuilder.newHashMap();
|
||||
Map customViewConstants = viewManager.getExportedViewConstants();
|
||||
if (customViewConstants != null) {
|
||||
viewManagerConstants.put("Constants", customViewConstants);
|
||||
}
|
||||
Map viewManagerCommands = viewManager.getCommandsMap();
|
||||
if (viewManagerCommands != null) {
|
||||
viewManagerConstants.put("Commands", viewManagerCommands);
|
||||
}
|
||||
Map<String, String> viewManagerNativeProps = viewManager.getNativeProps();
|
||||
if (!viewManagerNativeProps.isEmpty()) {
|
||||
viewManagerConstants.put("NativeProps", viewManagerNativeProps);
|
||||
}
|
||||
if (!viewManagerConstants.isEmpty()) {
|
||||
constants.put(viewManager.getName(), viewManagerConstants);
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "constants for ViewManager")
|
||||
.arg("ViewManager", viewManager.getName())
|
||||
.flush();
|
||||
try {
|
||||
Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
|
||||
if (viewManagerBubblingEvents != null) {
|
||||
recursiveMerge(bubblingEventTypesConstants, viewManagerBubblingEvents);
|
||||
}
|
||||
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
|
||||
if (viewManagerDirectEvents != null) {
|
||||
recursiveMerge(directEventTypesConstants, viewManagerDirectEvents);
|
||||
}
|
||||
Map viewManagerConstants = MapBuilder.newHashMap();
|
||||
Map customViewConstants = viewManager.getExportedViewConstants();
|
||||
if (customViewConstants != null) {
|
||||
viewManagerConstants.put("Constants", customViewConstants);
|
||||
}
|
||||
Map viewManagerCommands = viewManager.getCommandsMap();
|
||||
if (viewManagerCommands != null) {
|
||||
viewManagerConstants.put("Commands", viewManagerCommands);
|
||||
}
|
||||
Map<String, String> viewManagerNativeProps = viewManager.getNativeProps();
|
||||
if (!viewManagerNativeProps.isEmpty()) {
|
||||
viewManagerConstants.put("NativeProps", viewManagerNativeProps);
|
||||
}
|
||||
if (!viewManagerConstants.isEmpty()) {
|
||||
constants.put(viewManager.getName(), viewManagerConstants);
|
||||
}
|
||||
} finally {
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user