Skip to content

Commit 544813b

Browse files
authored
feat: add textProps support to all text components
2 parents 724b626 + 7611477 commit 544813b

27 files changed

Lines changed: 361 additions & 213 deletions

File tree

example/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default function App() {
1010
data={data}
1111
showFallback={true}
1212
style={styles.editorJsContainer}
13+
textProps={{
14+
maxFontSizeMultiplier: 1.0,
15+
}}
1316
/>
1417
</ScrollView>
1518
</SafeAreaView>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"!**/.*"
3838
],
3939
"scripts": {
40+
"postinstall": "patch-package",
4041
"example": "yarn workspace react-native-editorjs-viewer-example",
4142
"test": "jest",
4243
"typecheck": "tsc",
@@ -77,6 +78,7 @@
7778
"eslint-config-prettier": "^9.0.0",
7879
"eslint-plugin-prettier": "^5.0.1",
7980
"jest": "^29.7.0",
81+
"patch-package": "^8.0.0",
8082
"prettier": "^3.0.3",
8183
"react": "18.2.0",
8284
"react-native": "0.74.5",
@@ -188,7 +190,6 @@
188190
"html-entities": "^2.5.2",
189191
"react-native-code-highlighter": "^1.2.3",
190192
"react-native-render-html": "^6.3.4",
191-
"react-native-syntax-highlighter": "^2.1.0",
192193
"react-syntax-highlighter": "^15.5.0"
193194
}
194195
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/node_modules/react-native-code-highlighter/src/lib/CodeHighlighter.tsx b/node_modules/react-native-code-highlighter/src/lib/CodeHighlighter.tsx
2+
index d034ada..42aaedf 100644
3+
--- a/node_modules/react-native-code-highlighter/src/lib/CodeHighlighter.tsx
4+
+++ b/node_modules/react-native-code-highlighter/src/lib/CodeHighlighter.tsx
5+
@@ -1,4 +1,4 @@
6+
-import React, { type FunctionComponent, type ReactNode, useMemo } from "react";
7+
+import { type FunctionComponent, type ReactNode, useMemo } from "react";
8+
import {
9+
ScrollView,
10+
type ScrollViewProps,

src/components/checkList/checkListItem/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type ICheckListItemProps = {
2424
textStyle?: TextProps['style'];
2525
otherStyles?: IUseParseHtmlTags['styles'];
2626
checkmarkStyle?: ViewProps['style'];
27+
textProps?: Omit<TextProps, 'style' | 'children'>;
2728
};
2829

2930
const CheckListItem = ({
@@ -35,12 +36,14 @@ const CheckListItem = ({
3536
textStyle,
3637
otherStyles,
3738
checkmarkStyle,
39+
textProps,
3840
}: ICheckListItemProps) => {
3941
const { parseHtmlTag, defaultTagList } = useParseHtmlTags({
4042
styles: {
4143
...otherStyles,
4244
textStyle: textStyle,
4345
},
46+
textProps,
4447
});
4548

4649
const parsedText = useMemo(
@@ -57,7 +60,9 @@ const CheckListItem = ({
5760
uncheckedStyle={checkboxUncheckedStyle}
5861
checkmarkStyle={checkmarkStyle}
5962
/>
60-
<Text style={[styles.text, textStyle]}>{parsedText}</Text>
63+
<Text {...textProps} style={[styles.text, textStyle]}>
64+
{parsedText}
65+
</Text>
6166
</View>
6267
);
6368
};

src/components/checkList/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ICheckListProps = {
1616
checkboxUncheckedStyle?: ViewProps['style'];
1717
checkmarkStyle?: ViewProps['style'];
1818
otherStyles?: IUseParseHtmlTags['styles'];
19+
textProps?: Omit<TextProps, 'style' | 'children'>;
1920
};
2021

2122
const CheckList = ({
@@ -29,6 +30,7 @@ const CheckList = ({
2930
contentContainerStyle,
3031
checkmarkStyle,
3132
otherStyles,
33+
textProps,
3234
}: ICheckListProps) => {
3335
return (
3436
<FlatList
@@ -44,6 +46,7 @@ const CheckList = ({
4446
textStyle={textStyle}
4547
otherStyles={otherStyles}
4648
checkmarkStyle={checkmarkStyle}
49+
textProps={textProps}
4750
/>
4851
)}
4952
keyExtractor={(_, index) => index.toString()}

src/components/code/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { View, StyleSheet } from 'react-native';
1+
import type { TextProps, ViewProps } from 'react-native';
2+
import { StyleSheet, View } from 'react-native';
23
import CodeHighlighter from 'react-native-code-highlighter';
3-
import { atomOneDarkReasonable } from 'react-syntax-highlighter/dist/esm/styles/hljs';
4-
import type { ViewProps, TextProps } from 'react-native';
54
import { type CodeHighlighterProps } from 'react-native-code-highlighter/src/lib/CodeHighlighter';
5+
import { atomOneDarkReasonable } from 'react-syntax-highlighter/dist/esm/styles/hljs';
66

77
export type ICodeProps = {
88
data: {

src/components/delimiter/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,25 @@ export type IDelimiterProps = {
1111
data: Record<string, never>;
1212
containerStyle?: ViewProps['style'];
1313
textStyle?: TextProps['style'];
14+
textProps?: Omit<TextProps, 'style' | 'children'>;
1415
};
1516

16-
const Delimiter = ({ containerStyle, textStyle }: IDelimiterProps) => {
17+
const Delimiter = ({
18+
containerStyle,
19+
textStyle,
20+
textProps,
21+
}: IDelimiterProps) => {
1722
return (
1823
<View aria-hidden style={[styles.container, containerStyle]}>
19-
<Text style={[styles.delimiter, textStyle]}>{decode('&ast;')}</Text>
20-
<Text style={[styles.delimiter, textStyle]}>{decode('&ast;')}</Text>
21-
<Text style={[styles.delimiter, textStyle]}>{decode('&ast;')}</Text>
24+
<Text {...textProps} style={[styles.delimiter, textStyle]}>
25+
{decode('&ast;')}
26+
</Text>
27+
<Text {...textProps} style={[styles.delimiter, textStyle]}>
28+
{decode('&ast;')}
29+
</Text>
30+
<Text {...textProps} style={[styles.delimiter, textStyle]}>
31+
{decode('&ast;')}
32+
</Text>
2233
</View>
2334
);
2435
};

src/components/fallback/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ export type IFallbackProps = {
1010
blockType: string;
1111
containerStyle?: ViewProps['style'];
1212
textStyle?: TextProps['style'];
13+
textProps?: Omit<TextProps, 'style' | 'children'>;
1314
};
1415

15-
const Fallback = ({ blockType, containerStyle, textStyle }: IFallbackProps) => {
16+
const Fallback = ({
17+
blockType,
18+
containerStyle,
19+
textStyle,
20+
textProps,
21+
}: IFallbackProps) => {
1622
return (
1723
<View accessibilityRole="alert" style={[styles.container, containerStyle]}>
18-
<Text accessible style={[styles.alertText, textStyle]}>
24+
<Text accessible {...textProps} style={[styles.alertText, textStyle]}>
1925
Type &quot;{blockType}&quot; is yet not supported
2026
</Text>
2127
</View>

src/components/header/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export type IHeaderProps = {
1010
};
1111
style?: (level: 1 | 2 | 3 | 4 | 5 | 6) => TextProps['style'];
1212
otherStyles?: (level: 1 | 2 | 3 | 4 | 5 | 6) => IUseParseHtmlTags['styles'];
13+
textProps?: Omit<TextProps, 'style' | 'children'>;
1314
};
1415

15-
const Header = ({ data, style, otherStyles }: IHeaderProps) => {
16+
const Header = ({ data, style, otherStyles, textProps }: IHeaderProps) => {
1617
const headingStyleByLevel = useMemo(
1718
() => styles[`h${data.level}`],
1819
[data.level]
@@ -23,6 +24,7 @@ const Header = ({ data, style, otherStyles }: IHeaderProps) => {
2324
...otherStyles?.(data.level),
2425
textStyle: style?.(data.level),
2526
},
27+
textProps,
2628
});
2729

2830
const parsedText = useMemo(
@@ -35,6 +37,7 @@ const Header = ({ data, style, otherStyles }: IHeaderProps) => {
3537
accessible
3638
accessibilityRole="header"
3739
allowFontScaling={true}
40+
{...textProps}
3841
style={[styles.header, headingStyleByLevel, style?.(data.level)]}
3942
>
4043
{parsedText}

src/components/image/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type IImageProps = {
2222
imageStyle?: ImageProps['style'];
2323
textStyle?: TextProps['style'];
2424
otherStyles?: IUseParseHtmlTags['styles'];
25+
textProps?: Omit<TextProps, 'style' | 'children'>;
2526
};
2627

2728
const Image = ({
@@ -30,12 +31,14 @@ const Image = ({
3031
textStyle,
3132
imageStyle,
3233
otherStyles,
34+
textProps,
3335
}: IImageProps) => {
3436
const { parseHtmlTag, defaultTagList } = useParseHtmlTags({
3537
styles: {
3638
...otherStyles,
3739
textStyle: textStyle,
3840
},
41+
textProps,
3942
});
4043

4144
const parsedText = useMemo(
@@ -55,7 +58,7 @@ const Image = ({
5558
/>
5659

5760
{parsedText && (
58-
<Text aria-hidden style={[styles.caption, textStyle]}>
61+
<Text aria-hidden {...textProps} style={[styles.caption, textStyle]}>
5962
{parsedText}
6063
</Text>
6164
)}

0 commit comments

Comments
 (0)