mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: The `StatusBarManager` NativeModule does not have a uniform API on iOS and Android. In particular, the `setStyle` and the `setHidden` methods have an additional parameter on iOS: ``` /** * - statusBarStyles can be: * - 'default' * - 'dark-content' * - 'light-content' */ +setStyle: (statusBarStyle?: ?string, animated: boolean) => void; /** * - withAnimation can be: 'none' | 'fade' | 'slide' */ +setHidden: (hidden: boolean, withAnimation: string) => void; ``` If we keep the NativeModule spec the same between the two platforms, we'd have to keep the second parameter optional for both methods. This works for `setHidden`, because the second parameter is a string, and optional strings are allowed. However, for `setStyle`, the second parameter is a number, and we don't support optional numbers/booleans on Android in the NativeModule system. If we keep the optional number, then the following check triggers in our RedBox tests on iOS, which makes them fail: https://fburl.com/diffusion/b7adezd9. So, since the two specs are sufficiently different, I figured that the easiest path forward is to split them apart. Changelog: [iOS][Changed] - Separated NativeStatusBarManager into NativeStatusBarManager{IOS,Android} Reviewed By: PeteTheHeat Differential Revision: D18214161 fbshipit-source-id: 6fd8b8c5f576244b5b90ee47faa7f50508c5e1d3
70 lines
2.5 KiB
Java
70 lines
2.5 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.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 NativeStatusBarManagerAndroidSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
public NativeStatusBarManagerAndroidSpec(ReactApplicationContext reactContext) {
|
|
super(reactContext);
|
|
}
|
|
|
|
@ReactMethod
|
|
public abstract void setTranslucent(boolean translucent);
|
|
|
|
@ReactMethod
|
|
public abstract void setColor(double color, boolean animated);
|
|
|
|
@ReactMethod
|
|
public abstract void setHidden(boolean hidden);
|
|
|
|
@ReactMethod
|
|
public abstract void setStyle(@Nullable String statusBarStyle);
|
|
|
|
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(
|
|
"DEFAULT_BACKGROUND_COLOR",
|
|
"HEIGHT"
|
|
));
|
|
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;
|
|
}
|
|
}
|