Skip to main content

Theme Settings

ThemeSettings screen provide a user interface where end-users can customize the visual appearance of the application. Here is a breakdown of its specific responsibilities:

1. Orchestration of Theme Controls

It aggregates several specialized sub-components to build a complete settings page:

  • colorScheme: Allows switching between Light, Dark, and System (automatic) modes.
  • ColorOptions: Provides a palette for selecting the "Accent" or "Primary" color of the application.
  • Slider: Controls the global scale factor, effectively acting as a "Screen Zoom" feature to adjust font sizes and spacing proportionally.

2. Integration with ThemeContext

The file acts as the bridge between the UI and the application's global state. It consumes the useThemeContext hook to:

  • Access the current theme state (current colors, active scheme, current scale).
  • Invoke setter functions (setTheme, setColorScheme, setScale) to apply user changes globally across the app.

3. Layout and Styling

It defines the high-level structure of the settings screen using a ScrollView and grouped View sections (referred to as "sessions" in the styles). It applies consistent padding, margins, and background colors derived from the active theme to ensure the settings screen itself is themed correctly.

Code Quality Observations

  • Modularity: The code is well-structured, delegating specific logic to sub-components like Title, Divider, and ColorOptions.
  • Error Handling: It includes explicit checks for the existence of context methods (e.g., if (!setTheme) throw new Error(...)), which is a good defensive programming practice to ensure the component is used within a valid ThemeProvider.
  • Clean API: It allows passing a custom colors object via props, making the component flexible if a developer wants to provide a specific set of accent colors different from the defaults.

Properties

PropertyTypeOptionalDescription
colors{ [key: string]: ColorValue }YesAn object mapping string keys (color names) to ColorValue types. It defines the available accent colors shown in the settings. If omitted, it defaults to the defaultColors constant.

defaultColors

KeyValue
red #ff2325
orangeRed #ff5c1a
orange #ff9411
yellow #ffcb00
green #53b827
turquoise #28bfba
turquoise2 #19ebdc
blueSky #23bde0
blueOcean #1274AC
blue #6043f4
purple #bb65ff
pink #fe6f9b
salmon #EA5A51
black #3a3e59

Example used

import React from "react";

import ThemeSettingsScreen from "@flexnative/screens";

export default function Index() {
return <ThemeSettingsScreen />;
}