Expo System UI adds support for locking the user interface (appearance) and updating the root view background color. It provides asynchronous functions to set and get the root view background color across different platforms including React Native and web, with support for any valid CSS 3 (SVG) color values.
npx expo install expo-system-uiimport { setBackgroundColorAsync, getBackgroundColorAsync } from "expo-system-ui";For CommonJS:
const { setBackgroundColorAsync, getBackgroundColorAsync } = require("expo-system-ui");import { setBackgroundColorAsync, getBackgroundColorAsync } from "expo-system-ui";
// Set the root view background color
await setBackgroundColorAsync("black");
await setBackgroundColorAsync("#FF5733");
await setBackgroundColorAsync("rgba(255, 87, 51, 0.8)");
// Get the current root view background color
const currentColor = await getBackgroundColorAsync();
console.log(currentColor); // Returns color in hex format or null
// Clear the background color (set to null)
await setBackgroundColorAsync(null);Expo System UI provides a unified API that works across different platforms:
expo-modules-coredocument.body.style.backgroundColorAsynchronous functions for setting and getting the root view background color with cross-platform support.
/**
* Changes the root view background color.
* Call this function in the root file outside of your component.
* @param color Any valid CSS 3 (SVG) color or null to clear
* @returns Promise that resolves when the color is set
*/
function setBackgroundColorAsync(color: ColorValue | null): Promise<void>;
/**
* Gets the root view background color.
* @returns Promise resolving to current root view background color in hex format, or null if not set
*/
function getBackgroundColorAsync(): Promise<ColorValue | null>;Usage Examples:
import { setBackgroundColorAsync, getBackgroundColorAsync } from "expo-system-ui";
// Set various color formats
await setBackgroundColorAsync("red"); // Named color
await setBackgroundColorAsync("#FF0000"); // Hex color
await setBackgroundColorAsync("rgb(255,0,0)"); // RGB color
await setBackgroundColorAsync("rgba(255,0,0,0.5)"); // RGBA color
await setBackgroundColorAsync("hsl(0,100%,50%)"); // HSL color
// Clear the background color
await setBackgroundColorAsync(null);
// Get current color
const color = await getBackgroundColorAsync();
if (color) {
console.log(`Current background color: ${color}`);
} else {
console.log("No background color set");
}Configuration plugin for automatic native setup during build process.
/**
* Expo config plugin for system UI configuration
* Applies Android and iOS native configuration changes automatically
*/
const systemUIPlugin: ConfigPlugin<void>;Plugin Usage:
Add to your app.config.js or app.config.ts:
module.exports = {
name: "my-app",
plugins: [
"expo-system-ui" // Automatically applies native configuration
]
};The plugin handles:
/**
* React Native color value type supporting various color formats
* Imported from react-native package
*/
type ColorValue = string | number;Valid color formats include:
"red", "blue", "transparent""#FF0000", "#F00""rgb(255,0,0)", "rgba(255,0,0,0.5)""hsl(0,100%,50%)", "hsla(0,100%,50%,0.5)"No additional setup required - the plugin handles native configuration automatically.
Ensure you have the native expo package setup:
npx install-expo-modulesThe functions handle color processing errors gracefully:
try {
await setBackgroundColorAsync("invalid-color");
} catch (error) {
console.error("Failed to set background color:", error);
}