Skip to content

Commit 8aabe1e

Browse files
committed
refactor: remove mode from theme
1 parent a06aab0 commit 8aabe1e

File tree

8 files changed

+16
-90
lines changed

8 files changed

+16
-90
lines changed

docs/docs/guides/02-theming.mdx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ A theme usually contains the following properties:
6868
- `version`: specify which design system components should follow in the app
6969
- 3 - new Material You (MD3)
7070
- 2 - previous Material Design (MD2)
71-
- `mode` (`'adaptive' | 'exact'`): color mode for dark theme (See [Dark Theme](#dark-theme)).
7271
- `roundness` (`number`): roundness of common elements, such as buttons.
7372
- `colors` (`object`): various colors used throughout different elements.
7473

@@ -616,22 +615,6 @@ export default function FancyButton(props) {
616615

617616
Now you can use your `FancyButton` component everywhere instead of using `Button` from Paper.
618617

619-
## Dark Theme
620-
621-
Since 3.0 we adapt dark theme to follow [Material design guidelines](https://material.io/design/color/dark-theme.html). <br/>
622-
In contrast to light theme, dark theme by default uses `surface` colour instead of `primary` on large components like `AppBar` or `BottomNavigation`.<br/>
623-
The dark theme adds a white overlay with opacity depending on elevation of surfaces. It uses it for the better accentuation of surface elevation. Using only shadow is highly imperceptible on dark surfaces.
624-
625-
We are aware that users often use dark theme in their own ways and may not want to use the default dark theme features from the guidelines.<br/>
626-
That's why if you are using dark theme you can switch between two dark theme `mode`s:
627-
628-
- `exact` where everything is like it was before. `Appbar` and `BottomNavigation` will still use primary colour by default.<br/>
629-
- `adaptive` where we follow [Material design guidelines](https://material.io/design/color/dark-theme.html), the surface will use white overlay with opacity to show elevation, `Appbar` and `BottomNavigation` will use surface colour as a background.
630-
631-
If you don't use a custom theme, Paper will automatically change between the default theme and the default dark theme, depending on device settings.
632-
633-
Otherwise, your custom theme will need to handle it manually, using React Native's [Appearance API](https://reactnative.dev/docs/appearance).
634-
635618
## Gotchas
636619

637620
The `PaperProvider` exposes the theme to the components via [React's context API](https://reactjs.org/docs/context.html), which means that the component must be in the same tree as the `PaperProvider`. Some React Native components will render a different tree such as a `Modal`, in which case the components inside the `Modal` won't be able to access the theme. The work around is to get the theme using the `withTheme` HOC and pass it down to the components as props, or expose it again with the exported `ThemeProvider` component.

example/src/Examples/AppbarExample.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ const AppbarExample = ({ navigation }: Props) => {
4646
header: () => (
4747
<Appbar.Header
4848
style={showCustomColor ? styles.customColor : null}
49-
theme={{
50-
mode: 'adaptive',
51-
}}
5249
mode={appbarMode}
5350
elevated={showElevated}
5451
>
@@ -171,7 +168,6 @@ const AppbarExample = ({ navigation }: Props) => {
171168
},
172169
]}
173170
safeAreaInsets={{ bottom, left, right }}
174-
theme={{ mode: 'adaptive' }}
175171
>
176172
<Appbar.Action icon="archive" onPress={() => {}} />
177173
<Appbar.Action icon="email" onPress={() => {}} />

src/components/Appbar/Appbar.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ export type Props = Omit<
6969
* The top bar usually contains the screen title, controls such as navigation buttons, menu button etc.
7070
* The bottom bar usually provides access to a drawer and up to four actions.
7171
*
72-
* By default Appbar uses primary color as a background, in dark theme with `adaptive` mode it will use surface colour instead.
73-
* See [Dark Theme](https://callstack.github.io/react-native-paper/docs/guides/theming#dark-theme) for more informations
74-
*
7572
* ## Usage
7673
* ### Top bar
7774
* ```js

src/components/BottomNavigation/BottomNavigation.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ const SceneComponent = React.memo(({ component, ...rest }: any) =>
271271
* BottomNavigation provides quick navigation between top-level views of an app with a bottom navigation bar.
272272
* It is primarily designed for use on mobile. If you want to use the navigation bar only see [`BottomNavigation.Bar`](BottomNavigationBar).
273273
*
274-
* By default BottomNavigation uses primary color as a background, in dark theme with `adaptive` mode it will use surface colour instead.
275-
* See [Dark Theme](https://callstack.github.io/react-native-paper/docs/guides/theming#dark-theme) for more information.
276-
*
277274
* ## Usage
278275
* ```js
279276
* import * as React from 'react';

src/components/Card/Card.tsx

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const Card = (
145145
onLongPress,
146146
onPressOut,
147147
onPressIn,
148-
mode: cardMode = 'elevated',
148+
mode = 'elevated',
149149
children,
150150
style,
151151
contentStyle,
@@ -158,11 +158,16 @@ const Card = (
158158
ref: React.ForwardedRef<View>
159159
) => {
160160
const theme = useInternalTheme(themeOverrides);
161+
const {
162+
animation: { scale },
163+
roundness,
164+
} = theme;
165+
161166
const isMode = React.useCallback(
162167
(modeToCompare: Mode) => {
163-
return cardMode === modeToCompare;
168+
return mode === modeToCompare;
164169
},
165-
[cardMode]
170+
[mode]
166171
);
167172

168173
const hasPassedTouchHandler = hasTouchHandler({
@@ -172,65 +177,21 @@ const Card = (
172177
onPressOut,
173178
});
174179

175-
// Default animated value
176180
const { current: elevation } = React.useRef<Animated.Value>(
177181
new Animated.Value(cardElevation)
178182
);
179-
// Dark adaptive animated value, used in case of toggling the theme,
180-
// it prevents animating the background with native drivers inside Surface
181-
const { current: elevationDarkAdaptive } = React.useRef<Animated.Value>(
182-
new Animated.Value(cardElevation)
183-
);
184-
const { animation, dark, mode, roundness } = theme;
185-
186-
const prevDarkRef = React.useRef<boolean>(dark);
187-
React.useEffect(() => {
188-
prevDarkRef.current = dark;
189-
});
190-
191-
const prevDark = prevDarkRef.current;
192-
const isAdaptiveMode = mode === 'adaptive';
193-
const animationDuration = 150 * animation.scale;
194-
195-
React.useEffect(() => {
196-
/**
197-
* Resets animations values if updating to dark adaptive mode,
198-
* otherwise, any card that is in the middle of animation while
199-
* toggling the theme will stay at that animated value until
200-
* the next press-in
201-
*/
202-
if (dark && isAdaptiveMode && !prevDark) {
203-
elevation.setValue(cardElevation);
204-
elevationDarkAdaptive.setValue(cardElevation);
205-
}
206-
}, [
207-
prevDark,
208-
dark,
209-
isAdaptiveMode,
210-
cardElevation,
211-
elevation,
212-
elevationDarkAdaptive,
213-
]);
214183

215184
const runElevationAnimation = (pressType: HandlePressType) => {
216185
if (isMode('contained')) {
217186
return;
218187
}
219188

220189
const isPressTypeIn = pressType === 'in';
221-
if (dark && isAdaptiveMode) {
222-
Animated.timing(elevationDarkAdaptive, {
223-
toValue: isPressTypeIn ? 2 : cardElevation,
224-
duration: animationDuration,
225-
useNativeDriver: false,
226-
}).start();
227-
} else {
228-
Animated.timing(elevation, {
229-
toValue: isPressTypeIn ? 2 : cardElevation,
230-
duration: animationDuration,
231-
useNativeDriver: false,
232-
}).start();
233-
}
190+
Animated.timing(elevation, {
191+
toValue: isPressTypeIn ? 2 : cardElevation,
192+
duration: 150 * scale,
193+
useNativeDriver: false,
194+
}).start();
234195
};
235196

236197
const handlePressIn = useLatestCallback((e: GestureResponderEvent) => {
@@ -249,12 +210,10 @@ const Card = (
249210
? (child.type as any).displayName
250211
: null
251212
);
252-
const computedElevation =
253-
dark && isAdaptiveMode ? elevationDarkAdaptive : elevation;
254213

255214
const { backgroundColor, borderColor: themedBorderColor } = getCardColors({
256215
theme,
257-
mode: cardMode,
216+
mode,
258217
});
259218

260219
const flattenedStyles = (StyleSheet.flatten(style) || {}) as ViewStyle;
@@ -292,13 +251,13 @@ const Card = (
292251
style={[
293252
!isMode('elevated') && { backgroundColor },
294253
{
295-
elevation: computedElevation as unknown as number,
254+
elevation,
296255
},
297256
borderRadiusCombinedStyles,
298257
style,
299258
]}
300259
theme={theme}
301-
elevation={isMode('elevated') ? computedElevation : 0}
260+
elevation={isMode('elevated') ? elevation : 0}
302261
testID={`${testID}-container`}
303262
{...rest}
304263
>

src/components/Surface.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ const SurfaceIOS = forwardRef<
201201

202202
/**
203203
* Surface is a basic container that can give depth to an element with elevation shadow.
204-
* On dark theme with `adaptive` mode, surface is constructed by also placing a semi-transparent white overlay over a component surface.
205-
* See [Dark Theme](https://callstack.github.io/react-native-paper/docs/guides/theming#dark-theme) for more information.
206204
* Overlay and shadow can be applied by specifying the `elevation` property both on Android and iOS.
207205
*
208206
* ## Usage

src/styles/themes/DarkTheme.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const { palette, opacity } = tokens.md.ref;
99
export const DarkTheme: Theme = {
1010
...LightTheme,
1111
dark: true,
12-
mode: 'adaptive',
1312
colors: {
1413
primary: palette.primary80,
1514
primaryContainer: palette.primary30,

src/types.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export type Font = {
1919
fontStyle?: 'normal' | 'italic' | undefined;
2020
};
2121

22-
type Mode = 'adaptive' | 'exact';
23-
2422
export type Colors = {
2523
primary: string;
2624
primaryContainer: string;
@@ -61,7 +59,6 @@ export type ThemeProp = $DeepPartial<InternalTheme>;
6159

6260
export type ThemeBase = {
6361
dark: boolean;
64-
mode?: Mode;
6562
roundness: number;
6663
animation: {
6764
scale: number;

0 commit comments

Comments
 (0)