From 8ed0e1eba5227a87dfe140f53c44b02604f3e77a Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Mon, 6 Oct 2025 12:05:31 -0700 Subject: [PATCH] Add Platform Color example (#53908) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53908 Changelog: [Internal] Add an example to show how Platform Color can react to changes in appearance. This currently works on iOS for all colors, but for Android we need to "reset" desired tree with `key`. Reviewed By: zeyap Differential Revision: D82751014 fbshipit-source-id: 3e4b2b3ddff8c003ca835d6f26dbf9f7e82d413d --- .../PlatformColor/PlatformColorExample.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js b/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js index 9bc01fcd3af..6cb4a94567d 100644 --- a/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js +++ b/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js @@ -14,11 +14,14 @@ import type {ColorValue} from 'react-native'; import RNTesterText from '../../components/RNTesterText'; import React from 'react'; import { + Appearance, + Button, DynamicColorIOS, Platform, PlatformColor, StyleSheet, View, + useColorScheme, } from 'react-native'; function PlatformColorsExample() { @@ -315,6 +318,48 @@ function VariantColorsExample() { ); } +function ReactsToAppearanceChangesExample() { + const theme = useColorScheme(); + const key = Platform.select({ + android: theme ?? '', + default: undefined, + }); + + return ( + // using a key here forces the component to unmount and remount + // which is necessary to trigger the appearance change + + + + {Platform.select({ + ios: "DynamicColorIOS({light: 'red', dark: 'blue'})", + android: "PlatformColor('?attr/colorAccent')", + default: 'Unexpected Platform.OS: ' + Platform.OS, + })} + + + + +