Skip to content

Commit b6b09bd

Browse files
committed
fix: remove huge html generation
1 parent a4314eb commit b6b09bd

File tree

1 file changed

+25
-101
lines changed

1 file changed

+25
-101
lines changed

example/src/App.tsx

Lines changed: 25 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -77,77 +77,6 @@ const DEBUG_SCROLLABLE = false;
7777
// See: https://github.com/software-mansion/react-native-enriched/issues/229
7878
const ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS = false;
7979

80-
const generateHugeHtml = (repeat = 200) => {
81-
const parts: string[] = [];
82-
parts.push('<html>');
83-
84-
// small helper to make deterministic colors
85-
const colorAt = (i: number) => {
86-
const r = (37 * (i + 1)) % 256;
87-
const g = (83 * (i + 7)) % 256;
88-
const b = (199 * (i + 13)) % 256;
89-
const toHex = (n: number) => n.toString(16).padStart(2, '0');
90-
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
91-
};
92-
93-
for (let i = 0; i < repeat; i++) {
94-
const col = colorAt(i);
95-
const imgW = 200 + (i % 5) * 40;
96-
const imgH = 100 + (i % 3) * 30;
97-
98-
parts.push(
99-
// Headings
100-
`\n<h1>Section ${i + 1}</h1>`,
101-
`\n<h2>Subsection ${i + 1}.1</h2>`,
102-
`\n<h3>Topic ${i + 1}.1.a</h3>`,
103-
104-
// Paragraph with mixed inline styles
105-
`\n<p>This is a <b>bold</b> and <i>italic</i> paragraph with <u>underline</u>, ` +
106-
`<s>strike</s>, <code>inline_code_${i}</code>, ` +
107-
`<a href="https://example.com/${i}">a link ${i}</a>, ` +
108-
`<mention text="@alex_${i}" indicator="@"></mention>, ` +
109-
`<mention text="#general_${i}" indicator="#"></mention>, ` +
110-
`<font color="${col}">colored text ${col}</font> and some plain text to bulk it up.</p>`,
111-
112-
// Line break
113-
`\n<br>`,
114-
115-
// Unordered list
116-
`<ul>`,
117-
`<li>bullet A ${i}</li>`,
118-
`<li>bullet B ${i}</li>`,
119-
`<li>bullet C ${i}</li>`,
120-
`</ul>`,
121-
122-
// Ordered list
123-
`\n<ol>`,
124-
`\n<li>step 1.${i}</li>`,
125-
`\n<li>step 2.${i}</li>`,
126-
`\n<li>step 3.${i}</li>`,
127-
`\n</ol>`,
128-
129-
// Blockquote
130-
`\n<blockquote>`,
131-
`\n<p>“Blockquote line 1 for ${i}.”</p>`,
132-
`\n<p>“Blockquote line 2 for ${i}.”</p>`,
133-
`\n</blockquote>`,
134-
135-
// Code block (escaped characters)
136-
`\n<codeblock>`,
137-
`\n<p>for (let k = 0; k < ${i % 7}; k++) { console.log(&quot;block_${i}&quot;); }</p>`,
138-
`\n</codeblock>`,
139-
140-
// Image (self-closing)
141-
`\n<p><img src="https://picsum.photos/seed/${i}/${imgW}/${imgH}" width="${imgW}" height="${imgH}" /></p>`
142-
);
143-
}
144-
145-
parts.push('\n</html>');
146-
return parts.join('');
147-
};
148-
149-
const initialHugeHtml = generateHugeHtml();
150-
15180
export default function App() {
15281
const [isChannelPopupOpen, setIsChannelPopupOpen] = useState(false);
15382
const [isUserPopupOpen, setIsUserPopupOpen] = useState(false);
@@ -160,7 +89,6 @@ export default function App() {
16089
const [stylesState, setStylesState] = useState<StylesState>(DEFAULT_STYLE);
16190
const [currentLink, setCurrentLink] =
16291
useState<CurrentLinkState>(DEFAULT_LINK_STATE);
163-
const [visible, setVisible] = useState(false);
16492

16593
const ref = useRef<EnrichedTextInputInstance>(null);
16694

@@ -370,37 +298,33 @@ export default function App() {
370298
style={styles.container}
371299
contentContainerStyle={styles.content}
372300
>
373-
<Button title="Set visible" onPress={() => setVisible(!visible)} />
374301
<Text style={styles.label}>Enriched Text Input</Text>
375302
<View style={styles.editor}>
376-
{visible && (
377-
<EnrichedTextInput
378-
ref={ref}
379-
mentionIndicators={['@', '#']}
380-
style={styles.editorInput}
381-
htmlStyle={htmlStyle}
382-
placeholder="Type something here..."
383-
placeholderTextColor="rgb(0, 26, 114)"
384-
selectionColor="deepskyblue"
385-
cursorColor="dodgerblue"
386-
defaultValue={initialHugeHtml}
387-
autoCapitalize="sentences"
388-
onChangeText={handleChangeText}
389-
onChangeHtml={handleChangeHtml}
390-
onChangeState={handleChangeState}
391-
onLinkDetected={handleLinkDetected}
392-
onMentionDetected={console.log}
393-
onStartMention={handleStartMention}
394-
onChangeMention={handleChangeMention}
395-
onEndMention={handleEndMention}
396-
onFocus={handleFocusEvent}
397-
onBlur={handleBlurEvent}
398-
onChangeSelection={handleSelectionChangeEvent}
399-
androidExperimentalSynchronousEvents={
400-
ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS
401-
}
402-
/>
403-
)}
303+
<EnrichedTextInput
304+
ref={ref}
305+
mentionIndicators={['@', '#']}
306+
style={styles.editorInput}
307+
htmlStyle={htmlStyle}
308+
placeholder="Type something here..."
309+
placeholderTextColor="rgb(0, 26, 114)"
310+
selectionColor="deepskyblue"
311+
cursorColor="dodgerblue"
312+
autoCapitalize="sentences"
313+
onChangeText={handleChangeText}
314+
onChangeHtml={handleChangeHtml}
315+
onChangeState={handleChangeState}
316+
onLinkDetected={handleLinkDetected}
317+
onMentionDetected={console.log}
318+
onStartMention={handleStartMention}
319+
onChangeMention={handleChangeMention}
320+
onEndMention={handleEndMention}
321+
onFocus={handleFocusEvent}
322+
onBlur={handleBlurEvent}
323+
onChangeSelection={handleSelectionChangeEvent}
324+
androidExperimentalSynchronousEvents={
325+
ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS
326+
}
327+
/>
404328
<Toolbar
405329
stylesState={stylesState}
406330
editorRef={ref}

0 commit comments

Comments
 (0)