File tree Expand file tree Collapse file tree
android/src/main/java/com/swmansion/reactnativerichtexteditor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
4444 val paragraphStyles: ParagraphStyles ? = ParagraphStyles (this )
4545 val listStyles: ListStyles ? = ListStyles (this )
4646 val parametrizedStyles: ParametrizedStyles ? = ParametrizedStyles (this )
47- var isSettingDefaultValue : Boolean = false
47+ var isSettingValue : Boolean = false
4848
4949 var linkHandler: LinkHandler ? = LinkHandler (this )
5050 val mentionHandler: MentionHandler ? = MentionHandler (this )
@@ -144,9 +144,9 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
144144 setSelection(selection?.start ? : text?.length ? : 0 )
145145 }
146146
147- fun setDefaultValue (value : String? ) {
147+ fun setValue (value : String? ) {
148148 if (value == null ) return
149- isSettingDefaultValue = true
149+ isSettingValue = true
150150
151151 val isHtml = value.startsWith(" <html>" ) && value.endsWith(" </html>" )
152152 if (isHtml) {
@@ -162,7 +162,7 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
162162 // Scroll to the last line of text
163163 setSelection(text?.length ? : 0 )
164164
165- isSettingDefaultValue = false
165+ isSettingValue = false
166166 }
167167
168168 fun setAutoFocus (autoFocus : Boolean ) {
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager<ReactNativeRichTe
7474
7575 @ReactProp(name = " defaultValue" )
7676 override fun setDefaultValue (view : ReactNativeRichTextEditorView ? , value : String? ) {
77- view?.setDefaultValue (value)
77+ view?.setValue (value)
7878 }
7979
8080 @ReactProp(name = " placeholder" )
@@ -171,6 +171,10 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager<ReactNativeRichTe
171171 view?.clearFocus()
172172 }
173173
174+ override fun setValue (view : ReactNativeRichTextEditorView ? , text : String ) {
175+ view?.setValue(text)
176+ }
177+
174178 override fun toggleBold (view : ReactNativeRichTextEditorView ? ) {
175179 view?.verifyAndToggleStyle(EditorSpans .BOLD )
176180 }
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class EditorTextWatcher(private val editorView: ReactNativeRichTextEditorView) :
2222 }
2323
2424 override fun afterTextChanged (s : Editable ? ) {
25- if (s == null || editorView.isSettingDefaultValue ) return
25+ if (s == null || editorView.isSettingValue ) return
2626
2727 emitEvent(s)
2828 applyStyles(s)
Original file line number Diff line number Diff line change @@ -101,6 +101,10 @@ export default function App() {
101101 ref . current ?. blur ( ) ;
102102 } ;
103103
104+ const handleSetValue = ( ) => {
105+ ref . current ?. setValue ( '<html><b>Hello</b> <i>world</i></html>' ) ;
106+ } ;
107+
104108 const openLinkModal = ( ) => {
105109 setIsLinkModalOpen ( true ) ;
106110 } ;
@@ -196,6 +200,7 @@ export default function App() {
196200 />
197201 < Button title = "Focus" onPress = { handleFocus } />
198202 < Button title = "Blur" onPress = { handleBlur } />
203+ < Button title = "Set value" onPress = { handleSetValue } />
199204 { DEBUG_SCROLLABLE && < View style = { styles . scrollPlaceholder } /> }
200205 </ ScrollView >
201206 < LinkModal
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ interface NativeCommands {
8787 // General commands
8888 focus : ( viewRef : React . ElementRef < ComponentType > ) => void ;
8989 blur : ( viewRef : React . ElementRef < ComponentType > ) => void ;
90+ setValue : ( viewRef : React . ElementRef < ComponentType > , text : string ) => void ;
9091
9192 // Text formatting commands
9293 toggleBold : ( viewRef : React . ElementRef < ComponentType > ) => void ;
@@ -124,6 +125,7 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
124125 // General commands
125126 'focus' ,
126127 'blur' ,
128+ 'setValue' ,
127129
128130 // Text formatting commands
129131 'toggleBold' ,
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export interface RichTextInputInstance extends NativeMethods {
3232 // General commands
3333 focus : ( ) => void ;
3434 blur : ( ) => void ;
35+ setValue : ( value : string ) => void ;
3536
3637 // Text formatting commands
3738 toggleBold : ( ) => void ;
@@ -146,6 +147,9 @@ export const RichTextInput = ({
146147 blur : ( ) => {
147148 Commands . blur ( nullthrows ( nativeRef . current ) ) ;
148149 } ,
150+ setValue : ( value : string ) => {
151+ Commands . setValue ( nullthrows ( nativeRef . current ) , value ) ;
152+ } ,
149153 toggleBold : ( ) => {
150154 Commands . toggleBold ( nullthrows ( nativeRef . current ) ) ;
151155 } ,
You can’t perform that action at this time.
0 commit comments