add more Systrace to native module / view manager constants

Reviewed By: lexs

Differential Revision: D3739966

fbshipit-source-id: 4ba31aade00852132e528f96252197b823bb58a3
This commit is contained in:
Aaron Chiu 2016-08-19 11:54:22 -07:00 коммит произвёл Facebook Github Bot 9
Родитель 14188289fc
Коммит 924187eb9a
5 изменённых файлов: 71 добавлений и 38 удалений

Просмотреть файл

@ -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);
}
}