|
| 1 | +--- |
| 2 | +sidebar_label: 'Platform Colors' |
| 3 | +sidebar_position: 2 |
| 4 | +--- |
| 5 | + |
| 6 | +# Platform Colors |
| 7 | + |
| 8 | +React Native macOS extends the core `PlatformColor` API with helpers that map directly to AppKit system colors. These helpers make it easier to adopt macOS appearance and accessibility behaviors without writing native code. |
| 9 | + |
| 10 | +## `DynamicColorMacOS` |
| 11 | + |
| 12 | +`DynamicColorMacOS` creates a color that automatically adapts to light, dark, and high-contrast appearances on macOS. |
| 13 | + |
| 14 | +:::note |
| 15 | +`DynamicColorIOS` works on macOS too, they are essentially equivalent |
| 16 | +::: |
| 17 | + |
| 18 | +| Option | Description | |
| 19 | +| -------------------- | --------------------------------------------------------------- | |
| 20 | +| `light` | Color used in the standard light appearance. | |
| 21 | +| `dark` | Color used in the standard dark appearance. | |
| 22 | +| `highContrastLight` | Optional color for high-contrast light mode. Defaults to `light`.| |
| 23 | +| `highContrastDark` | Optional color for high-contrast dark mode. Defaults to `dark`. | |
| 24 | + |
| 25 | +## `ColorWithSystemEffectMacOS` |
| 26 | + |
| 27 | +`ColorWithSystemEffectMacOS(color, effect)` wraps an existing color so AppKit can apply control state effects such as pressed, disabled, or rollover. |
| 28 | + |
| 29 | +| Parameter | Description | |
| 30 | +| --------- | ----------- | |
| 31 | +| `color` | A string produced by `PlatformColor`, `DynamicColorMacOS`, or a CSS color string. | |
| 32 | +| `effect` | One of `none`, `pressed`, `deepPressed`, `disabled`, or `rollover`. | |
| 33 | + |
| 34 | +```javascript |
| 35 | +import { |
| 36 | + ColorWithSystemEffectMacOS, |
| 37 | + DynamicColorMacOS, |
| 38 | + PlatformColor, |
| 39 | + StyleSheet, |
| 40 | +} from 'react-native'; |
| 41 | + |
| 42 | +const styles = StyleSheet.create({ |
| 43 | + buttonPressed: { |
| 44 | + backgroundColor: ColorWithSystemEffectMacOS( |
| 45 | + PlatformColor('controlColor'), |
| 46 | + 'pressed', |
| 47 | + ), |
| 48 | + }, |
| 49 | +}); |
| 50 | +``` |
0 commit comments