Skip to content

Commit e198cf0

Browse files
fixing italics
1 parent 38c04ce commit e198cf0

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

packages/streamdown-rn/src/core/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,16 @@ export interface ThemeColors {
217217

218218
/**
219219
* Theme configuration
220+
*
221+
* Font-agnostic: regular and bold fonts are optional (undefined uses platform defaults).
222+
* Only mono is required for code blocks.
220223
*/
221224
export interface ThemeConfig {
222225
colors: ThemeColors;
223226
fonts: {
224-
regular: string;
225-
bold: string;
226-
mono: string;
227+
regular?: string; // Optional - uses platform default if undefined
228+
bold?: string; // Optional - uses platform default if undefined
229+
mono: string; // Required for code blocks
227230
};
228231
spacing: {
229232
block: number; // Space between blocks

packages/streamdown-rn/src/renderers/ASTRenderer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ function renderCodeBlock(
337337
web: 'monospace',
338338
default: 'monospace',
339339
})}
340-
PreTag={View}
341-
CodeTag={Text}
340+
PreTag={View as any}
341+
CodeTag={Text as any}
342342
>
343343
{code}
344344
</SyntaxHighlighter>

packages/streamdown-rn/src/themes/index.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*
44
* Dark and light themes with consistent styling.
55
* Optimized for readability and streaming performance.
6+
*
7+
* Font-agnostic: Uses platform defaults for text, allowing host apps
8+
* to set their own fonts. Only monospace is specified for code blocks.
69
*/
710

811
import { Platform } from 'react-native';
@@ -56,17 +59,12 @@ const lightColors: ThemeColors = {
5659
// Font Configuration
5760
// ============================================================================
5861

62+
// Font-agnostic: undefined lets React Native use platform defaults
63+
// This allows host apps to set fonts at the root level and have them inherited
64+
// Only monospace is specified for code blocks
5965
const fonts = {
60-
regular: Platform.select({
61-
ios: 'System',
62-
android: 'System',
63-
default: 'System',
64-
}) as string,
65-
bold: Platform.select({
66-
ios: 'System',
67-
android: 'System',
68-
default: 'System',
69-
}) as string,
66+
regular: undefined as string | undefined,
67+
bold: undefined as string | undefined,
7068
mono: Platform.select({
7169
ios: 'Menlo',
7270
android: 'monospace',
@@ -114,79 +112,87 @@ export function getTheme(theme: 'dark' | 'light' | ThemeConfig): ThemeConfig {
114112

115113
/**
116114
* Generate text styles for a theme
115+
*
116+
* Font-agnostic: Only applies fontFamily when explicitly set in theme.
117+
* This allows host apps to set fonts at the root level and have them inherited.
117118
*/
118119
export function getTextStyles(theme: ThemeConfig) {
120+
// Helper to conditionally include fontFamily
121+
const withFont = (fontKey: 'regular' | 'bold' | 'mono') =>
122+
theme.fonts[fontKey] ? { fontFamily: theme.fonts[fontKey] } : {};
123+
119124
return {
120125
body: {
121126
color: theme.colors.foreground,
122-
fontFamily: theme.fonts.regular,
127+
...withFont('regular'),
123128
fontSize: 16,
124129
lineHeight: 24,
125130
},
126131
heading1: {
127132
color: theme.colors.foreground,
128-
fontFamily: theme.fonts.bold,
133+
...withFont('bold'),
129134
fontSize: 28,
130135
lineHeight: 36,
131136
fontWeight: 'bold' as const,
132137
marginBottom: theme.spacing.block,
133138
},
134139
heading2: {
135140
color: theme.colors.foreground,
136-
fontFamily: theme.fonts.bold,
141+
...withFont('bold'),
137142
fontSize: 24,
138143
lineHeight: 32,
139144
fontWeight: 'bold' as const,
140145
marginBottom: theme.spacing.block,
141146
},
142147
heading3: {
143148
color: theme.colors.foreground,
144-
fontFamily: theme.fonts.bold,
149+
...withFont('bold'),
145150
fontSize: 20,
146151
lineHeight: 28,
147152
fontWeight: 'bold' as const,
148153
marginBottom: theme.spacing.block,
149154
},
150155
heading4: {
151156
color: theme.colors.foreground,
152-
fontFamily: theme.fonts.bold,
157+
...withFont('bold'),
153158
fontSize: 18,
154159
lineHeight: 26,
155160
fontWeight: 'bold' as const,
156161
marginBottom: theme.spacing.block,
157162
},
158163
heading5: {
159164
color: theme.colors.foreground,
160-
fontFamily: theme.fonts.bold,
165+
...withFont('bold'),
161166
fontSize: 16,
162167
lineHeight: 24,
163168
fontWeight: 'bold' as const,
164169
marginBottom: theme.spacing.block,
165170
},
166171
heading6: {
167172
color: theme.colors.foreground,
168-
fontFamily: theme.fonts.bold,
173+
...withFont('bold'),
169174
fontSize: 14,
170175
lineHeight: 22,
171176
fontWeight: 'bold' as const,
172177
marginBottom: theme.spacing.block,
173178
},
174179
paragraph: {
175180
color: theme.colors.foreground,
176-
fontFamily: theme.fonts.regular,
181+
...withFont('regular'),
177182
fontSize: 16,
178183
lineHeight: 24,
179184
marginBottom: theme.spacing.block,
180185
},
181186
bold: {
182-
fontFamily: theme.fonts.bold,
187+
...withFont('bold'),
183188
fontWeight: 'bold' as const,
184189
},
185190
italic: {
186191
fontStyle: 'italic' as const,
192+
// No fontFamily - inherits from parent, allowing platform italic to work
187193
},
188194
code: {
189-
fontFamily: theme.fonts.mono,
195+
...withFont('mono'),
190196
fontSize: 14,
191197
color: theme.colors.codeForeground,
192198
backgroundColor: theme.colors.codeBackground,

0 commit comments

Comments
 (0)