mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
TurboModule Android: move SampleTurboModule impl and spec to OSS
Summary: This is the Java/JNI impl of the NativeSampleTurboModule.js, just like on iOS. The files here are supposed to be generated by the react-native-codegen, but they are checked in to the repo for easier build integration with RNTester. Changelog: [Internal] Reviewed By: hramos Differential Revision: D23985746 fbshipit-source-id: 46340d778f3d964efe5b538d15ebe0f2cab04862
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b931bd33fe
commit
b9a1ea9e9e
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// NOTE: This entire file should be codegen'ed.
|
||||
|
||||
package com.facebook.fbreact.specs;
|
||||
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReactModuleWithSpec;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class NativeSampleTurboModuleSpec extends ReactContextBaseJavaModule
|
||||
implements ReactModuleWithSpec, TurboModule {
|
||||
public NativeSampleTurboModuleSpec(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract double getNumber(double arg);
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract WritableMap getValue(double x, String y, ReadableMap z);
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract WritableMap getObject(ReadableMap arg);
|
||||
|
||||
@ReactMethod
|
||||
public abstract void voidFunc();
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract WritableArray getArray(ReadableArray arg);
|
||||
|
||||
@ReactMethod
|
||||
public abstract void getValueWithPromise(boolean error, Promise promise);
|
||||
|
||||
@ReactMethod
|
||||
public abstract void getValueWithCallback(Callback callback);
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract String getString(String arg);
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract double getRootTag(double arg);
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public abstract boolean getBool(boolean arg);
|
||||
|
||||
protected abstract Map<String, Object> getTypedExportedConstants();
|
||||
|
||||
@Override
|
||||
public final @Nullable Map<String, Object> getConstants() {
|
||||
Map<String, Object> constants = getTypedExportedConstants();
|
||||
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
|
||||
Set<String> obligatoryFlowConstants =
|
||||
new HashSet<>(Arrays.asList("const2", "const1", "const3"));
|
||||
Set<String> optionalFlowConstants = new HashSet<>();
|
||||
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
|
||||
undeclaredConstants.removeAll(obligatoryFlowConstants);
|
||||
undeclaredConstants.removeAll(optionalFlowConstants);
|
||||
if (!undeclaredConstants.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
|
||||
}
|
||||
undeclaredConstants = obligatoryFlowConstants;
|
||||
undeclaredConstants.removeAll(constants.keySet());
|
||||
if (!undeclaredConstants.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
|
||||
}
|
||||
}
|
||||
return constants;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user