11import { View , StyleSheet , Text , ScrollView } from 'react-native' ;
22import { EnrichedTextInput } from 'react-native-enriched-html' ;
33import { 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' ;
411import {
512 LINK_REGEX ,
613 htmlStyle ,
714 ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS ,
815} from '../constants/editorConfig' ;
916import { useState } from 'react' ;
17+ import { TextRenderer } from '../components/TextRenderer' ;
1018
1119interface DevScreenProps {
1220 onSwitch : ( ) => void ;
1321}
1422
15- export function DevScreen ( { } : DevScreenProps ) {
16- const [ showEditor , setShowEditor ] = useState ( false ) ;
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+ } ;
1735
1836 return (
1937 < >
@@ -22,32 +40,103 @@ export function DevScreen({}: DevScreenProps) {
2240 contentContainerStyle = { styles . content }
2341 >
2442 < 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 >
2599 < Button
26- title = "Toggle editor's presence "
27- onPress = { ( ) => setShowEditor ( ( prev ) => ! prev ) }
100+ title = "Test Screen "
101+ onPress = { onSwitch }
28102 style = { styles . valueButton }
29103 testID = "toggle-screen-button"
30104 />
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 >
105+ < TextRenderer nodes = { textNodes } />
50106 </ 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+ />
51140 </ >
52141 ) ;
53142}
@@ -87,7 +176,9 @@ const styles = StyleSheet.create({
87176 editorInput : {
88177 marginTop : 24 ,
89178 width : '100%' ,
179+ maxHeight : 180 ,
90180 backgroundColor : 'gainsboro' ,
181+ fontSize : 18 ,
91182 fontFamily : 'Nunito-Regular' ,
92183 paddingVertical : 12 ,
93184 paddingHorizontal : 14 ,
0 commit comments