Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,17 @@ class StatusBar extends React.Component<StatusBarProps> {
console.warn(
`\`StatusBar._updatePropsStack\`: Color ${mergedProps.backgroundColor.value} parsed to null or undefined`,
);
} else {
invariant(
typeof processedColor === 'number',
'Unexpected color given in StatusBar._updatePropsStack',
);
} else if (typeof processedColor === 'number') {
NativeStatusBarManagerAndroid.setColor(
processedColor,
mergedProps.backgroundColor.animated,
);
} else {
NativeStatusBarManagerAndroid.setColorObject(
// $FlowFixMe[incompatible-type] - Opaque NativeColorValue on Android matches the spec shape {resource_paths: Array<string>}.
processedColor,
mergedProps.backgroundColor.animated,
);
}
if (!oldProps || oldProps.hidden?.value !== mergedProps.hidden.value) {
NativeStatusBarManagerAndroid.setHidden(mergedProps.hidden.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.common.logging.FLog
import com.facebook.fbreact.specs.NativeStatusBarManagerAndroidSpec
import com.facebook.react.bridge.ColorPropConverter
import com.facebook.react.bridge.GuardedRunnable
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.common.ReactConstants
import com.facebook.react.interfaces.ExtraWindowEventListener
Expand Down Expand Up @@ -79,7 +81,24 @@ internal class StatusBarModule(reactContext: ReactApplicationContext?) :

@Suppress("DEPRECATION")
override fun setColor(colorDouble: Double, animated: Boolean) {
val color = colorDouble.toInt()
applyStatusBarColor(colorDouble.toInt(), animated)
}

@Suppress("DEPRECATION")
override fun setColorObject(color: ReadableMap, animated: Boolean) {
val resolved = ColorPropConverter.getColor(color, reactApplicationContext)
if (resolved == null) {
FLog.w(
ReactConstants.TAG,
"StatusBarModule: Ignored status bar change, unable to resolve color.",
)
return
}
applyStatusBarColor(resolved, animated)
}

@Suppress("DEPRECATION")
private fun applyStatusBarColor(color: Int, animated: Boolean) {
val activity = reactApplicationContext.getCurrentActivity()
if (activity == null) {
FLog.w(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ import type {TurboModule} from '../../../../Libraries/TurboModule/RCTExport';

import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboModuleRegistry';

export type NativePlatformColorValue = {
+resource_paths: Array<string>,
};

export interface Spec extends TurboModule {
readonly getConstants: () => {
readonly HEIGHT: number,
readonly DEFAULT_BACKGROUND_COLOR: number,
};
readonly setColor: (color: number, animated: boolean) => void;
readonly setColorObject: (
color: NativePlatformColorValue,
animated: boolean,
) => void;
readonly setTranslucent: (translucent: boolean) => void;

/**
Expand Down Expand Up @@ -47,6 +55,10 @@ const NativeStatusBarManager = {
NativeModule.setColor(color, animated);
},

setColorObject(color: NativePlatformColorValue, animated: boolean): void {
NativeModule.setColorObject(color, animated);
},

setTranslucent(translucent: boolean): void {
NativeModule.setTranslucent(translucent);
},
Expand Down
14 changes: 14 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -8591,6 +8591,12 @@ struct facebook::react::NativeSourceCodeSourceCodeConstants {
public bool operator==(const facebook::react::NativeSourceCodeSourceCodeConstants& other) const;
}

template <typename P0>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue {
public P0 resource_paths;
public bool operator==(const facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue& other) const;
}

template <typename R, typename... Args>
class facebook::react::SyncCallback<R(Args...)> {
public R call(Args... args) const;
Expand Down Expand Up @@ -9433,6 +9439,14 @@ struct facebook::react::NativeSourceCodeSourceCodeConstantsBridging {
public static facebook::jsi::String scriptURLToJs(facebook::jsi::Runtime& rt, decltype(types.scriptURL) value);
}

template <typename T>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValueBridging {
public static T fromJs(facebook::jsi::Runtime& rt, const facebook::jsi::Object& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
public static T types;
public static facebook::jsi::Array resource_pathsToJs(facebook::jsi::Runtime& rt, decltype(types.resource_paths) value);
public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
}

template <typename T>
struct facebook::react::RectangleCorners {
public T bottomLeft;
Expand Down
13 changes: 13 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -8367,6 +8367,12 @@ struct facebook::react::NativeSourceCodeSourceCodeConstants {
public bool operator==(const facebook::react::NativeSourceCodeSourceCodeConstants& other) const;
}

template <typename P0>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue {
public P0 resource_paths;
public bool operator==(const facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue& other) const;
}

template <typename R, typename... Args>
class facebook::react::SyncCallback<R(Args...)> {
public R call(Args... args) const;
Expand Down Expand Up @@ -9071,6 +9077,13 @@ struct facebook::react::NativeSourceCodeSourceCodeConstantsBridging {
public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
}

template <typename T>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValueBridging {
public static T fromJs(facebook::jsi::Runtime& rt, const facebook::jsi::Object& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
public static T types;
public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
}

template <typename T>
struct facebook::react::RectangleCorners {
public T bottomLeft;
Expand Down
13 changes: 13 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -8582,6 +8582,12 @@ struct facebook::react::NativeSourceCodeSourceCodeConstants {
public bool operator==(const facebook::react::NativeSourceCodeSourceCodeConstants& other) const;
}

template <typename P0>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue {
public P0 resource_paths;
public bool operator==(const facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValue& other) const;
}

template <typename R, typename... Args>
class facebook::react::SyncCallback<R(Args...)> {
public R call(Args... args) const;
Expand Down Expand Up @@ -9286,6 +9292,13 @@ struct facebook::react::NativeSourceCodeSourceCodeConstantsBridging {
public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
}

template <typename T>
struct facebook::react::NativeStatusBarManagerAndroidNativePlatformColorValueBridging {
public static T fromJs(facebook::jsi::Runtime& rt, const facebook::jsi::Object& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
public static T types;
public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker);
}

template <typename T>
struct facebook::react::RectangleCorners {
public T bottomLeft;
Expand Down
Loading