Skip to content

Commit c8c60d0

Browse files
committed
refactor: remove dynamicTheme prop
1 parent 33b2f4b commit c8c60d0

4 files changed

Lines changed: 14 additions & 35 deletions

File tree

src/core/PaperProvider.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import { useSystemColorScheme } from './useSystemColorScheme';
1212
import MaterialCommunityIcon from '../components/MaterialCommunityIcon';
1313
import PortalHost from '../components/Portal/PortalHost';
1414
import { ReduceMotionContext } from '../theme/accessibility/ReduceMotionContext';
15-
import {
16-
isDynamicColorSupported,
17-
lightDynamicColors,
18-
darkDynamicColors,
19-
} from '../theme/schemes/DynamicTheme';
2015
import type { ThemeProp } from '../types';
2116

2217
export type Props = {
@@ -25,33 +20,26 @@ export type Props = {
2520
settings?: Settings;
2621
direction?: Direction;
2722
reduceMotion?: ReduceMotionPreference;
28-
dynamicColor?: boolean;
2923
};
3024

3125
const PaperProvider = (props: Props) => {
32-
const { reduceMotion = 'auto', dynamicColor = false } = props;
26+
const { reduceMotion = 'auto' } = props;
3327

3428
const colorScheme = useSystemColorScheme(!props.theme);
3529
const resolvedReduceMotion = useResolvedReduceMotion(reduceMotion);
3630

3731
const theme = React.useMemo(() => {
3832
const isDark = props.theme?.dark ?? colorScheme === 'dark';
3933
const base = defaultThemes[isDark ? 'dark' : 'light'];
40-
const dynamicColors =
41-
dynamicColor && isDynamicColorSupported
42-
? isDark
43-
? darkDynamicColors
44-
: lightDynamicColors
45-
: undefined;
4634
const scale = resolvedReduceMotion ? 0 : props.theme?.animation?.scale ?? 1;
4735

4836
return {
4937
...base,
5038
...props.theme,
51-
colors: { ...base.colors, ...props.theme?.colors, ...dynamicColors },
39+
colors: { ...base.colors, ...props.theme?.colors },
5240
animation: { ...props.theme?.animation, scale },
5341
};
54-
}, [colorScheme, props.theme, resolvedReduceMotion, dynamicColor]);
42+
}, [colorScheme, props.theme, resolvedReduceMotion]);
5543

5644
const { children, settings } = props;
5745

src/core/__tests__/PaperProvider.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { render, act } from '@testing-library/react-native';
1010

1111
import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext';
12-
import { LightTheme, DarkTheme } from '../../theme/schemes';
12+
import { DarkTheme, DynamicLightTheme, LightTheme } from '../../theme/schemes';
1313
import type { ThemeProp } from '../../types';
1414
import PaperProvider from '../PaperProvider';
1515
import { useTheme } from '../theming';
@@ -213,17 +213,10 @@ describe('PaperProvider', () => {
213213
).toStrictEqual(0);
214214
});
215215

216-
it('leaves theme.colors unchanged when dynamicColor is true on an unsupported platform', async () => {
217-
mockAppearance();
218-
const { getByTestId } = render(
219-
<PaperProvider dynamicColor>
220-
<FakeChild />
221-
</PaperProvider>
222-
);
223-
// `isDynamicColorSupported` is false on the test platform → no color override.
224-
expect(getByTestId('provider-child-view').props.theme.colors.primary).toBe(
225-
LightTheme.colors.primary
226-
);
216+
it('DynamicLightTheme falls back to LightTheme on unsupported platforms', () => {
217+
// On non-Android (and Android API <31), DynamicLightTheme is structurally
218+
// identical to LightTheme, so consumers can import it unconditionally.
219+
expect(DynamicLightTheme.colors).toStrictEqual(LightTheme.colors);
227220
});
228221

229222
it('should set Appearance listeners, if there is no theme', async () => {

src/theme/schemes/DynamicTheme.android.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,12 @@ function buildDynamicColors(scheme: 'light' | 'dark'): Partial<ThemeColors> {
473473

474474
export const isDynamicColorSupported = apiLevel >= 31;
475475

476-
export const lightDynamicColors = buildDynamicColors('light');
477-
export const darkDynamicColors = buildDynamicColors('dark');
476+
const lightDynamicColors = isDynamicColorSupported
477+
? buildDynamicColors('light')
478+
: undefined;
479+
const darkDynamicColors = isDynamicColorSupported
480+
? buildDynamicColors('dark')
481+
: undefined;
478482

479483
export const DynamicLightTheme: Theme = {
480484
...LightTheme,

src/theme/schemes/DynamicTheme.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
import type { ThemeColors } from '../types/color';
2-
31
export { DarkTheme as DynamicDarkTheme } from './DarkTheme';
42
export { LightTheme as DynamicLightTheme } from './LightTheme';
5-
6-
export const isDynamicColorSupported = false;
7-
export const lightDynamicColors: Partial<ThemeColors> = {};
8-
export const darkDynamicColors: Partial<ThemeColors> = {};

0 commit comments

Comments
 (0)