mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: It's possible for us to return no constants from the BlobModule. Therefore, I'm correcting the flow-type. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D18932328 fbshipit-source-id: 2b415d12effd16eda313d5591825c711a20f9ae3
78 lines
2.7 KiB
Java
78 lines
2.7 KiB
Java
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
|
* directory of this source tree.
|
|
*
|
|
* <p>Generated by an internal genrule from Flow types.
|
|
*
|
|
* @generated
|
|
* @nolint
|
|
*/
|
|
|
|
package com.facebook.fbreact.specs;
|
|
|
|
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.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 NativeBlobModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
public NativeBlobModuleSpec(ReactApplicationContext reactContext) {
|
|
super(reactContext);
|
|
}
|
|
|
|
@ReactMethod
|
|
public abstract void sendOverSocket(ReadableMap blob, double socketID);
|
|
|
|
@ReactMethod
|
|
public abstract void addNetworkingHandler();
|
|
|
|
@ReactMethod
|
|
public abstract void createFromParts(ReadableArray parts, String withId);
|
|
|
|
@ReactMethod
|
|
public abstract void addWebSocketHandler(double id);
|
|
|
|
@ReactMethod
|
|
public abstract void release(String blobId);
|
|
|
|
@ReactMethod
|
|
public abstract void removeWebSocketHandler(double id);
|
|
|
|
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<>();
|
|
Set<String> optionalFlowConstants = new HashSet<>(Arrays.asList(
|
|
"BLOB_URI_HOST",
|
|
"BLOB_URI_SCHEME"
|
|
));
|
|
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;
|
|
}
|
|
}
|