@@ -9,9 +9,10 @@ import {
99import styled from "styled-components/native" ;
1010import { space , flexbox , border , layout } from "styled-system" ;
1111
12- import { Container } from "@components" ;
1312import { useKeyboard } from "@hooks" ;
1413
14+ import Container from "./Container" ;
15+
1516export const ScrollView = styled . ScrollView . attrs ( ( ) => ( {
1617 keyboardShouldPersistTaps : "handled" ,
1718 showsVerticalScrollIndicator : true ,
@@ -80,13 +81,17 @@ export const RichTextEditor = ({
8081 toolbarActions,
8182 editorProps,
8283 toolBarProps,
84+ richTextRef : externalRichTextRef ,
8385 ...rest
8486} ) => {
85- const richTextRef = useRef ( ) ;
87+ const internalRichTextRef = useRef ( ) ;
8688 const keyboardHeight = useKeyboard ( ) ;
8789 const [ toolbarVisible , setToolbarVisible ] = useState ( false ) ;
8890 const showToolbar = keyboardHeight > 0 && toolbarVisible ;
8991
92+ // Use the external ref if provided, otherwise use the internal ref
93+ const richTextRef = externalRichTextRef || internalRichTextRef ;
94+
9095 const computeToolbarActions = ( ) => {
9196 const actionItems = [ ] ;
9297 toolbarActions ?. map ( actionItem => {
@@ -116,11 +121,11 @@ export const RichTextEditor = ({
116121 onChange = { onChange }
117122 onBlur = { ( ) => {
118123 setToolbarVisible ( false ) ;
119- editorProps ?. onBlurFn ( ) ;
124+ editorProps ?. onBlurFn ?. ( ) ;
120125 } }
121126 onFocus = { ( ) => {
122127 setToolbarVisible ( true ) ;
123- editorProps ?. onFocusFn ( ) ;
128+ editorProps ?. onFocusFn ?. ( ) ;
124129 } }
125130 { ...editorProps }
126131 />
@@ -160,4 +165,8 @@ RichTextEditor.propTypes = {
160165 toolBarProps : PropTypes . object ,
161166 editorWrapperStyle : PropTypes . object ,
162167 toolbarWrapperStyle : PropTypes . object ,
168+ /**
169+ * Ref object to control the editor from outside the component.
170+ */
171+ richTextRef : PropTypes . object ,
163172} ;
0 commit comments