Skip to content

Commit 212b2a3

Browse files
committed
feat: testing case
1 parent c070294 commit 212b2a3

1 file changed

Lines changed: 23 additions & 114 deletions

File tree

apps/example/src/screens/DevScreen.tsx

Lines changed: 23 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
11
import { View, StyleSheet, Text, ScrollView } from 'react-native';
22
import { EnrichedTextInput } from 'react-native-enriched-html';
33
import { Button } from '../components/Button';
4-
import { Toolbar } from '../components/Toolbar';
5-
import { LinkModal } from '../components/LinkModal';
6-
import { ValueModal } from '../components/ValueModal';
7-
import { MentionPopup } from '../components/MentionPopup';
8-
import { HtmlSection } from '../components/HtmlSection';
9-
import { ImageModal } from '../components/ImageModal';
10-
import { useEditorState } from '../hooks/useEditorState';
114
import {
125
LINK_REGEX,
136
htmlStyle,
147
ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS,
158
} from '../constants/editorConfig';
169
import { useState } from 'react';
17-
import { TextRenderer } from '../components/TextRenderer';
1810

1911
interface DevScreenProps {
2012
onSwitch: () => void;
2113
}
2214

23-
export function DevScreen({ onSwitch }: DevScreenProps) {
24-
const editor = useEditorState();
25-
const [textNodes, setTextNodes] = useState<Array<string>>([]);
26-
27-
const handlePushTextNode = async () => {
28-
const currentText = await editor.ref.current?.getHTML();
29-
if (currentText) {
30-
setTextNodes((prevTextNodes) => [...prevTextNodes, currentText]);
31-
}
32-
33-
editor.ref.current?.setValue('');
34-
};
15+
export function DevScreen({}: DevScreenProps) {
16+
const [showEditor, setShowEditor] = useState(false);
3517

3618
return (
3719
<>
@@ -40,103 +22,32 @@ export function DevScreen({ onSwitch }: DevScreenProps) {
4022
contentContainerStyle={styles.content}
4123
>
4224
<Text style={styles.label}>Enriched Text Input</Text>
43-
<View style={styles.editor} testID="editor-container">
44-
<EnrichedTextInput
45-
ref={editor.ref}
46-
mentionIndicators={['@', '#']}
47-
style={styles.editorInput}
48-
htmlStyle={htmlStyle}
49-
placeholder="Type something here..."
50-
placeholderTextColor="rgb(0, 26, 114)"
51-
selectionColor="deepskyblue"
52-
cursorColor="dodgerblue"
53-
autoCapitalize="sentences"
54-
linkRegex={LINK_REGEX}
55-
onChangeText={(e) => editor.handleChangeText(e.nativeEvent)}
56-
onChangeHtml={(e) => editor.handleChangeHtml(e.nativeEvent)}
57-
onChangeState={(e) => editor.handleChangeState(e.nativeEvent)}
58-
onLinkDetected={editor.handleLinkDetected}
59-
onMentionDetected={console.log}
60-
onStartMention={editor.handleStartMention}
61-
onChangeMention={editor.handleChangeMention}
62-
onEndMention={editor.handleEndMention}
63-
onFocus={editor.handleFocusEvent}
64-
onBlur={editor.handleBlurEvent}
65-
onChangeSelection={(e) =>
66-
editor.handleSelectionChangeEvent(e.nativeEvent)
67-
}
68-
onSubmitEditing={(e) =>
69-
editor.handleSubmitEditingEvent(e.nativeEvent)
70-
}
71-
onKeyPress={(e) => editor.handleKeyPress(e.nativeEvent)}
72-
androidExperimentalSynchronousEvents={
73-
ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS
74-
}
75-
onPasteImages={(e) => editor.handlePasteImagesEvent(e.nativeEvent)}
76-
testID="editor-input"
77-
/>
78-
<Toolbar
79-
stylesState={editor.stylesState}
80-
editorRef={editor.ref}
81-
onOpenLinkModal={editor.openLinkModal}
82-
onSelectImage={editor.openImageModal}
83-
layout="horizontal"
84-
/>
85-
</View>
86-
<HtmlSection currentHtml={editor.currentHtml} />
87-
<View style={styles.buttonStack}>
88-
<Button
89-
title="Set input's value"
90-
onPress={editor.openValueModal}
91-
style={styles.button}
92-
/>
93-
<Button
94-
title="Push text"
95-
onPress={handlePushTextNode}
96-
style={styles.button}
97-
/>
98-
</View>
9925
<Button
100-
title="Test Screen"
101-
onPress={onSwitch}
26+
title="Toggle editor's presence"
27+
onPress={() => setShowEditor((prev) => !prev)}
10228
style={styles.valueButton}
10329
testID="toggle-screen-button"
10430
/>
105-
<TextRenderer nodes={textNodes} />
31+
<View style={styles.editor} testID="editor-container">
32+
{showEditor && (
33+
<EnrichedTextInput
34+
style={styles.editorInput}
35+
htmlStyle={htmlStyle}
36+
placeholder="Type something here..."
37+
placeholderTextColor="rgb(0, 26, 114)"
38+
selectionColor="deepskyblue"
39+
cursorColor="dodgerblue"
40+
autoCapitalize="sentences"
41+
linkRegex={LINK_REGEX}
42+
androidExperimentalSynchronousEvents={
43+
ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS
44+
}
45+
defaultValue={`<html><h4>heading</h4><ul><li>list1</li><li>list2</li><li><code>codelist</code></li></ul><h3><code>codeheading</code></h3></html>`}
46+
testID="editor-input"
47+
/>
48+
)}
49+
</View>
10650
</ScrollView>
107-
<LinkModal
108-
isOpen={editor.isLinkModalOpen}
109-
editedText={
110-
editor.insideCurrentLink
111-
? editor.currentLink.text
112-
: (editor.selection?.text ?? '')
113-
}
114-
editedUrl={editor.insideCurrentLink ? editor.currentLink.url : ''}
115-
onSubmit={editor.submitLink}
116-
onClose={editor.closeLinkModal}
117-
/>
118-
<ImageModal
119-
isOpen={editor.isImageModalOpen}
120-
onSubmit={editor.selectImage}
121-
onClose={editor.closeImageModal}
122-
/>
123-
<ValueModal
124-
isOpen={editor.isValueModalOpen}
125-
onSubmit={editor.submitSetValue}
126-
onClose={editor.closeValueModal}
127-
/>
128-
<MentionPopup
129-
variant="user"
130-
data={editor.userMention.data}
131-
isOpen={editor.isUserPopupOpen}
132-
onItemPress={editor.handleUserMentionSelected}
133-
/>
134-
<MentionPopup
135-
variant="channel"
136-
data={editor.channelMention.data}
137-
isOpen={editor.isChannelPopupOpen}
138-
onItemPress={editor.handleChannelMentionSelected}
139-
/>
14051
</>
14152
);
14253
}
@@ -176,9 +87,7 @@ const styles = StyleSheet.create({
17687
editorInput: {
17788
marginTop: 24,
17889
width: '100%',
179-
maxHeight: 180,
18090
backgroundColor: 'gainsboro',
181-
fontSize: 18,
18291
fontFamily: 'Nunito-Regular',
18392
paddingVertical: 12,
18493
paddingHorizontal: 14,

0 commit comments

Comments
 (0)