Skip to content

Commit c5c2469

Browse files
committed
fix(minor): remove custom style types and simplify style typings
Removes ViewStyleProp, TextStyleProp, and CustomStyleProp.
1 parent 07d6f90 commit c5c2469

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/lib/Parser.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { ReactNode } from 'react';
2+
import type { TextStyle, ViewStyle, ImageStyle } from 'react-native';
23
import type { marked } from 'marked';
34
import { decode } from 'entities';
45
import Renderer from './Renderer';
56
import type { MarkedStyles } from '../theme/types';
6-
import type { CustomStyleProp, ParserOptions, TextStyleProp } from './types';
7+
import type { ParserOptions } from './types';
78

89
class Parser {
910
private renderer;
1011
private styles: MarkedStyles;
11-
private headingStylesMap: Record<number, TextStyleProp>;
12+
private headingStylesMap: Record<number, TextStyle | undefined>;
1213
constructor(options: ParserOptions) {
1314
this.styles = { ...options.styles };
1415
this.renderer = new Renderer();
@@ -96,7 +97,10 @@ class Parser {
9697
return elements.filter((element) => element !== null);
9798
}
9899

99-
parseInline(tokens: marked.Token[], styles?: CustomStyleProp) {
100+
parseInline(
101+
tokens: marked.Token[],
102+
styles?: ViewStyle | TextStyle | ImageStyle
103+
) {
100104
const elements: ReactNode[] = tokens.map((token) => {
101105
if (!token) return null;
102106

@@ -187,7 +191,7 @@ class Parser {
187191

188192
private getNormalizedSiblingNodesForBlockAndInlineTokens = (
189193
tokens: marked.Token[],
190-
textStyle: TextStyleProp
194+
textStyle?: TextStyle
191195
): ReactNode[] => {
192196
let tokenRenderQueue: marked.Token[] = [];
193197
const siblingNodes: ReactNode[] = [];

src/lib/Renderer.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import React, { ReactNode } from 'react';
2-
import { ScrollView, View, Text, TouchableHighlight } from 'react-native';
2+
import {
3+
ScrollView,
4+
View,
5+
Text,
6+
TouchableHighlight,
7+
TextStyle,
8+
ViewStyle,
9+
} from 'react-native';
310
import MarkedList from '@jsamr/react-native-li';
411
import Disc from '@jsamr/counter-style/presets/disc';
512
import Decimal from '@jsamr/counter-style/presets/decimal';
613
import MDImage from './../components/MDImage';
714
import { generateRandomString } from '../utils/string';
8-
import type { TextStyleProp, ViewStyleProp } from './types';
915
import { onLinkPress } from '../utils/handlers';
1016

1117
class Renderer {
12-
getTextNode = (children: string | ReactNode[], styles: TextStyleProp) => {
18+
getTextNode = (children: string | ReactNode[], styles?: TextStyle) => {
1319
return (
1420
<Text key={generateRandomString()} style={styles}>
1521
{children}
@@ -20,7 +26,7 @@ class Renderer {
2026
getTextLinkNode = (
2127
children: string | ReactNode[],
2228
href: string,
23-
styles: TextStyleProp
29+
styles?: TextStyle
2430
) => {
2531
return (
2632
<Text
@@ -49,7 +55,7 @@ class Renderer {
4955
);
5056
};
5157

52-
getViewNode(children: ReactNode[] | null, styles: ViewStyleProp) {
58+
getViewNode(children: ReactNode[] | null, styles?: ViewStyle) {
5359
return (
5460
<View key={generateRandomString()} style={styles}>
5561
{children}
@@ -59,8 +65,8 @@ class Renderer {
5965

6066
getCodeBlockNode(
6167
text: string,
62-
containerStyle: ViewStyleProp,
63-
textStyle: TextStyleProp
68+
containerStyle?: ViewStyle,
69+
textStyle?: TextStyle
6470
) {
6571
return (
6672
<ScrollView
@@ -73,7 +79,7 @@ class Renderer {
7379
);
7480
}
7581

76-
getBlockquoteNode(children: ReactNode[], styles: ViewStyleProp) {
82+
getBlockquoteNode(children: ReactNode[], styles?: ViewStyle) {
7783
return (
7884
<View key={generateRandomString()} style={styles}>
7985
{children}
@@ -88,8 +94,8 @@ class Renderer {
8894
getListNode(
8995
ordered: boolean,
9096
li: ReactNode[],
91-
listStyle: ViewStyleProp,
92-
textStyle: TextStyleProp
97+
listStyle?: ViewStyle,
98+
textStyle?: TextStyle
9399
) {
94100
return (
95101
<MarkedList

src/lib/types.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import type { ReactNode } from 'react';
2-
import type {
3-
ImageStyle,
4-
TextStyle,
5-
ViewStyle,
6-
FlatListProps,
7-
} from 'react-native';
2+
import type { FlatListProps } from 'react-native';
83
import type { MarkedStyles } from './../theme/types';
94

10-
export type TextStyleProp = TextStyle | undefined;
11-
export type ViewStyleProp = ViewStyle | undefined;
12-
export type CustomStyleProp = ViewStyle | TextStyle | ImageStyle | undefined;
13-
145
export interface ParserOptions {
156
styles?: MarkedStyles;
167
}

0 commit comments

Comments
 (0)