Skip to content

Commit

Permalink
feat: export defaultSystemFonts and defaultFallbackFonts
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent e304e2f commit 0c4207c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 58 deletions.
126 changes: 69 additions & 57 deletions packages/render-html/src/TRenderEngineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,73 @@ export const tRenderEngineProviderPropTypes: Record<
onDocumentMetadataLoaded: PropTypes.func
};

/**
* Default fallback font for special keys such as 'sans-serif', 'monospace',
* 'serif', based on current platform.
*/
export const defaultFallbackFonts = {
'sans-serif': Platform.select({ ios: 'system', default: 'sans-serif' }),
monospace: Platform.select({ ios: 'Menlo', default: 'monospace' }),
serif: Platform.select({ ios: 'Times New Roman', default: 'serif' })
};

/**
* Default system fonts based on current platform. If you are using Expo, use
* `Constants.systemFonts` instead.
*/
export const defaultSystemFonts = Platform.select({
default: [],
ios: [
'San Francisco',
'Arial',
'ArialHebrew',
'Avenir',
'Baskerville',
'Bodoni 72',
'Bradley Hand',
'Chalkboard SE',
'Cochin',
'Copperplate',
'Courier',
'Courier New',
'Damascus',
'Didot',
'Futura',
'Geeza Pro',
'Georgia',
'Gill Sans',
'Helvetica',
'Helvetica Neue',
'Hiragino Sans',
'Hoefler Text',
'Iowan Old Style',
'Kailasa',
'Khmer Sangam MN',
'Marker Felt',
'Menlo',
'Mishafi',
'Noteworthy',
'Optima',
'Palatino',
'Papyrus',
'Savoye LET',
'Symbol',
'Thonburi',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Zapf Dingbats',
'Zapfino'
],
android: [
'Roboto',
'notoserif',
'sans-serif-light',
'sans-serif-thin',
'sans-serif-medium'
]
});

export const defaultTRenderEngineProviderProps: TransientRenderEngineConfig = {
htmlParserOptions: {
decodeEntities: true
Expand All @@ -55,63 +122,8 @@ export const defaultTRenderEngineProviderProps: TransientRenderEngineConfig = {
enableUserAgentStyles: true,
enableCSSInlineProcessing: true,
renderers: {},
fallbackFonts: {
'sans-serif': Platform.select({ ios: 'system', default: 'sans-serif' }),
monospace: Platform.select({ ios: 'Menlo', default: 'monospace' }),
serif: Platform.select({ ios: 'Times New Roman', default: 'serif' })
},
systemFonts: Platform.select({
default: [],
ios: [
'San Francisco',
'Arial',
'ArialHebrew',
'Avenir',
'Baskerville',
'Bodoni 72',
'Bradley Hand',
'Chalkboard SE',
'Cochin',
'Copperplate',
'Courier',
'Courier New',
'Damascus',
'Didot',
'Futura',
'Geeza Pro',
'Georgia',
'Gill Sans',
'Helvetica',
'Helvetica Neue',
'Hiragino Sans',
'Hoefler Text',
'Iowan Old Style',
'Kailasa',
'Khmer Sangam MN',
'Marker Felt',
'Menlo',
'Mishafi',
'Noteworthy',
'Optima',
'Palatino',
'Papyrus',
'Savoye LET',
'Symbol',
'Thonburi',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Zapf Dingbats',
'Zapfino'
],
android: [
'Roboto',
'notoserif',
'sans-serif-light',
'sans-serif-thin',
'sans-serif-medium'
]
}),
fallbackFonts: defaultFallbackFonts,
systemFonts: defaultSystemFonts,
triggerTREInvalidationPropNames: []
};

Expand Down
6 changes: 5 additions & 1 deletion packages/render-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export {
} from './TNodeChildrenRenderer';
export type { TNodeChildrenRendererProps } from './TNodeChildrenRenderer';
export { default as TNodeRenderer } from './TNodeRenderer';
export { default as TRenderEngineProvider } from './TRenderEngineProvider';
export {
default as TRenderEngineProvider,
defaultFallbackFonts,
defaultSystemFonts
} from './TRenderEngineProvider';
export { default as RenderHTMLFragment } from './RenderHTMLFragment';
export { default as useInternalRenderer } from './hooks/useInternalRenderer';
export { default as useNormalizedUrl } from './hooks/useNormalizedUrl';
Expand Down

0 comments on commit 0c4207c

Please sign in to comment.