mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reviewed By: nicklockwood Differential Revision: D3229626 fb-gh-sync-id: f8b2e8c9fc0d25d67f623cdbbe9930a02a40d1de fbshipit-source-id: f8b2e8c9fc0d25d67f623cdbbe9930a02a40d1de
72 lines
2.2 KiB
Java
72 lines
2.2 KiB
Java
/**
|
|
* 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.bridge;
|
|
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Class stores configuration of javascript modules that can be used across the bridge
|
|
*/
|
|
public class JavaScriptModulesConfig {
|
|
|
|
private final List<JavaScriptModuleRegistration> mModules;
|
|
|
|
public JavaScriptModulesConfig(List<JavaScriptModuleRegistration> modules) {
|
|
mModules = modules;
|
|
}
|
|
|
|
public List<JavaScriptModuleRegistration> getModuleDefinitions() {
|
|
return mModules;
|
|
}
|
|
|
|
public void writeModuleDescriptions(JsonWriter writer) throws IOException {
|
|
writer.beginObject();
|
|
for (JavaScriptModuleRegistration registration : mModules) {
|
|
writer.name(registration.getName()).beginObject();
|
|
appendJSModuleToJSONObject(writer, registration);
|
|
writer.endObject();
|
|
}
|
|
writer.endObject();
|
|
}
|
|
|
|
private void appendJSModuleToJSONObject(
|
|
JsonWriter writer,
|
|
JavaScriptModuleRegistration registration) throws IOException {
|
|
writer.name("moduleID").value(registration.getName());
|
|
writer.name("methods").beginObject();
|
|
for (Method method : registration.getMethods()) {
|
|
writer.name(method.getName()).beginObject();
|
|
writer.name("methodID").value(method.getName());
|
|
writer.endObject();
|
|
}
|
|
writer.endObject();
|
|
if (registration.getModuleInterface().isAnnotationPresent(SupportsWebWorkers.class)) {
|
|
writer.name("supportsWebWorkers").value(true);
|
|
}
|
|
}
|
|
|
|
public static class Builder {
|
|
private List<JavaScriptModuleRegistration> mModules =
|
|
new ArrayList<JavaScriptModuleRegistration>();
|
|
|
|
public Builder add(Class<? extends JavaScriptModule> moduleInterfaceClass) {
|
|
mModules.add(new JavaScriptModuleRegistration(moduleInterfaceClass));
|
|
return this;
|
|
}
|
|
|
|
public JavaScriptModulesConfig build() {
|
|
return new JavaScriptModulesConfig(mModules);
|
|
}
|
|
}
|
|
}
|