Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/babel/__fixtures__/rewrite-imports/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import {
NonExistentSecond as Stuff,
ThemeProvider,
withTheme,
DefaultTheme,
} from 'react-native-paper';
1 change: 0 additions & 1 deletion src/babel/__fixtures__/rewrite-imports/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ import { MD3Colors } from "react-native-paper/lib/module/deprecated";
import { NonExistent, NonExistentSecond as Stuff } from "react-native-paper/lib/module/index.js";
import { ThemeProvider } from "react-native-paper/lib/module/core/theming";
import { withTheme } from "react-native-paper/lib/module/core/theming";
import { DefaultTheme } from "react-native-paper/lib/module/core/theming";
7 changes: 4 additions & 3 deletions src/components/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Platform, StyleSheet, Text, View } from 'react-native';
import { fireEvent } from '@testing-library/react-native';

import PaperProvider from '../../core/PaperProvider';
import { DefaultTheme, getTheme, ThemeProvider } from '../../core/theming';
import { getTheme, ThemeProvider } from '../../core/theming';
import { render } from '../../test-utils';
import { red500 } from '../../theme/colors';
import { LightTheme } from '../../theme/schemes';
import { tokens } from '../../theme/tokens';
import {
getFlatInputColors,
Expand Down Expand Up @@ -369,9 +370,9 @@ it('calls onLayout on right-side affix adornment', () => {
it("correctly applies theme background to label when input's background is transparent", () => {
const backgroundColor = 'transparent';
const theme = {
...DefaultTheme,
...LightTheme,
colors: {
...DefaultTheme.colors,
...LightTheme.colors,
background: 'pink',
},
};
Expand Down
14 changes: 6 additions & 8 deletions src/core/PaperProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ const PaperProvider = (props: Props) => {
const resolvedReduceMotion = useResolvedReduceMotion(reduceMotion);

const theme = React.useMemo(() => {
const scheme = colorScheme === 'dark' ? 'dark' : 'light';
const defaultThemeBase = defaultThemes[scheme];
const userScale = props.theme?.animation?.scale ?? 1;
const isDark = props.theme?.dark ?? colorScheme === 'dark';
const base = defaultThemes[isDark ? 'dark' : 'light'];
const scale = resolvedReduceMotion ? 0 : props.theme?.animation?.scale ?? 1;

return {
...defaultThemeBase,
...base,
...props.theme,
animation: {
...props.theme?.animation,
scale: resolvedReduceMotion ? 0 : userScale,
},
colors: { ...base.colors, ...props.theme?.colors },
animation: { ...props.theme?.animation, scale },
};
}, [colorScheme, props.theme, resolvedReduceMotion]);

Expand Down
11 changes: 10 additions & 1 deletion src/core/__tests__/PaperProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as React from 'react';
import {
Appearance,
AccessibilityInfo,
Platform,
View,
ColorSchemeName,
} from 'react-native';

import { render, act } from '@testing-library/react-native';

import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext';
import { LightTheme, DarkTheme } from '../../theme/schemes';
import { DarkTheme, DynamicLightTheme, LightTheme } from '../../theme/schemes';
import type { ThemeProp } from '../../types';
import PaperProvider from '../PaperProvider';
import { useTheme } from '../theming';
Expand Down Expand Up @@ -106,9 +107,12 @@ const createProvider = (theme?: ThemeProp) => {
const ExtendedLightTheme = { ...LightTheme } as ThemeProp;
const ExtendedDarkTheme = { ...DarkTheme } as ThemeProp;

const defaultPlatform = Platform.OS;

describe('PaperProvider', () => {
beforeEach(() => {
jest.resetModules();
Platform.OS = defaultPlatform;
});

it('handles theme change', async () => {
Expand Down Expand Up @@ -213,6 +217,11 @@ describe('PaperProvider', () => {
).toStrictEqual(0);
});

it('DynamicLightTheme falls back to LightTheme on non-Android platforms', () => {
Platform.OS = 'ios';
expect(DynamicLightTheme.colors).toStrictEqual(LightTheme.colors);
});

it('should set Appearance listeners, if there is no theme', async () => {
mockAppearance();
const { getByTestId } = render(createProvider());
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export {
useTheme,
withTheme,
ThemeProvider,
DefaultTheme,
adaptNavigationTheme,
} from './core/theming';

Expand Down
12 changes: 5 additions & 7 deletions src/theme/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import type { ComponentType } from 'react';
import { $DeepPartial, createTheming } from '@callstack/react-theme-provider';

import { DarkTheme, LightTheme } from './schemes';
import type { InternalTheme, Theme, NavigationTheme } from './types';

export const DefaultTheme = LightTheme;
import type { Theme, NavigationTheme } from './types';

export const {
ThemeProvider,
Expand All @@ -18,11 +16,11 @@ export function useTheme<T = Theme>(overrides?: $DeepPartial<T>) {
}

export const useInternalTheme = (
themeOverrides: $DeepPartial<InternalTheme> | undefined
) => useAppTheme<InternalTheme>(themeOverrides);
themeOverrides: $DeepPartial<Theme> | undefined
) => useAppTheme<Theme>(themeOverrides);

export const withInternalTheme = <Props extends { theme: InternalTheme }, C>(
WrappedComponent: ComponentType<Props & { theme: InternalTheme }> & C
export const withInternalTheme = <Props extends { theme: Theme }, C>(
WrappedComponent: ComponentType<Props & { theme: Theme }> & C
) => withTheme<Props, C>(WrappedComponent);

export const defaultThemes = {
Expand Down
Loading
Loading