Skip to content

Commit 96869a3

Browse files
committed
refactor(example): drop unused theme helpers
useThemedStyles had no call sites — screens keep static rules in a module-level StyleSheet and read theme-dependent values at the call site. The glass colour token was superseded by controlOnImage, and TypeToken was never referenced.
1 parent f4cc2fd commit 96869a3

2 files changed

Lines changed: 5 additions & 32 deletions

File tree

example/src/theme/index.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
*
44
* Dark-first: an unknown/unset system scheme resolves to the dark theme, which
55
* is the one the app was designed against.
6+
*
7+
* Screens keep their static rules in a module-level `StyleSheet.create` and pull
8+
* only the theme-dependent values (colours, radii) from `useTheme()` at the call
9+
* site, so nothing is rebuilt per render.
610
*/
711

8-
import { useMemo } from 'react';
9-
import { StyleSheet, useColorScheme } from 'react-native';
10-
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
12+
import { useColorScheme } from 'react-native';
1113

1214
import { darkTheme, lightTheme } from './tokens';
1315
import type { Theme } from './tokens';
@@ -19,26 +21,3 @@ export function useTheme(): Theme {
1921
const scheme = useColorScheme();
2022
return scheme === 'light' ? lightTheme : darkTheme;
2123
}
22-
23-
type NamedStyles<T> = {
24-
[P in keyof T]: ViewStyle | TextStyle | ImageStyle;
25-
};
26-
27-
/**
28-
* Build a themed stylesheet once per theme rather than on every render.
29-
*
30-
* `factory` must be a stable reference — declare it at module scope, not inline
31-
* in the component, or the memo will miss on every render.
32-
*
33-
* ```ts
34-
* const createStyles = (t: Theme) => ({ root: { backgroundColor: t.color.canvas } });
35-
* // inside the component:
36-
* const styles = useThemedStyles(createStyles);
37-
* ```
38-
*/
39-
export function useThemedStyles<T extends NamedStyles<T>>(
40-
factory: (theme: Theme) => T
41-
): T {
42-
const theme = useTheme();
43-
return useMemo(() => StyleSheet.create(factory(theme)), [factory, theme]);
44-
}

example/src/theme/tokens.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ export const type = {
102102
},
103103
} as const;
104104

105-
export type TypeToken = keyof typeof type;
106-
107105
// =============================================================================
108106
// Motion
109107
// =============================================================================
@@ -125,7 +123,6 @@ export interface ThemeColor {
125123
canvas: string;
126124
surface: string;
127125
surfaceRaised: string;
128-
glass: string;
129126
/**
130127
* Fill for a control that sits directly on a photograph. Identical in both
131128
* schemes on purpose: the backdrop is the image, not the canvas, so it must
@@ -157,8 +154,6 @@ const darkColor: ThemeColor = {
157154
surface: '#15151D',
158155
/** A surface sitting on top of another surface. */
159156
surfaceRaised: '#1E1E28',
160-
/** Translucent fill for controls over imagery. */
161-
glass: 'rgba(20, 20, 28, 0.62)',
162157
controlOnImage: 'rgba(10, 10, 16, 0.46)',
163158
borderOnImage: 'rgba(255, 255, 255, 0.28)',
164159
/** Hairline separators and card outlines. */
@@ -185,7 +180,6 @@ const lightColor: ThemeColor = {
185180
canvas: '#FBFAF8',
186181
surface: '#FFFFFF',
187182
surfaceRaised: '#FFFFFF',
188-
glass: 'rgba(255, 255, 255, 0.74)',
189183
controlOnImage: 'rgba(10, 10, 16, 0.46)',
190184
borderOnImage: 'rgba(255, 255, 255, 0.28)',
191185
border: 'rgba(17, 17, 24, 0.10)',

0 commit comments

Comments
 (0)