@@ -38,6 +38,8 @@ interface MarkdownTextInputProps extends TextInputProps, InlineImagesInputProps
3838
3939interface MarkdownNativeEvent extends Event {
4040 inputType ?: string ;
41+ isComposing ?: boolean ;
42+ keyCode ?: number ;
4143}
4244
4345type MarkdownTextInput = TextInput & React . Component < MarkdownTextInputProps > ;
@@ -120,7 +122,6 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
120122 throw new Error ( '[react-native-live-markdown] `parser` is not a function' ) ;
121123 }
122124
123- const compositionRef = useRef < boolean > ( false ) ;
124125 const divRef = useRef < MarkdownTextInputElement | null > ( null ) ;
125126 const currentlyFocusedField = useRef < HTMLDivElement | null > ( null ) ;
126127 const contentSelection = useRef < Selection | null > ( null ) ;
@@ -349,6 +350,7 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
349350 }
350351 const nativeEvent = e . nativeEvent as MarkdownNativeEvent ;
351352 const inputType = nativeEvent . inputType ;
353+ const isComposing = isEventComposing ( nativeEvent ) ;
352354
353355 updateTextColor ( divRef . current , e . target . textContent ?? '' ) ;
354356 const previousText = divRef . current . value ;
@@ -370,7 +372,7 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
370372 ? Math . max ( contentSelection . current . start , 0 ) // Don't move the caret when deleting forward with no characters selected
371373 : Math . max ( Math . max ( contentSelection . current . end , 0 ) + ( parsedText . length - previousText . length ) , 0 ) ;
372374
373- if ( compositionRef . current ) {
375+ if ( isComposing ) {
374376 updateTextColor ( divRef . current , parsedText ) ;
375377 updateSelection ( e , {
376378 start : newCursorPosition ,
@@ -657,13 +659,8 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
657659 [ insertText ] ,
658660 ) ;
659661
660- const startComposition = useCallback ( ( ) => {
661- compositionRef . current = true ;
662- } , [ ] ) ;
663-
664662 const endComposition = useCallback (
665663 ( e : React . CompositionEvent < HTMLDivElement > ) => {
666- compositionRef . current = false ;
667664 handleOnChangeText ( e ) ;
668665 } ,
669666 [ handleOnChangeText ] ,
@@ -788,7 +785,6 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
788785 autoCapitalize = { autoCapitalize }
789786 className = { className }
790787 onKeyDown = { handleKeyPress }
791- onCompositionStart = { startComposition }
792788 onCompositionEnd = { endComposition }
793789 onInput = { handleOnChangeText }
794790 onClick = { handleClick }
@@ -829,4 +825,10 @@ const styles = StyleSheet.create({
829825
830826export default MarkdownTextInput ;
831827
832- export type { MarkdownTextInputProps , MarkdownTextInputElement , HTMLMarkdownElement } ;
828+ export type { MarkdownNativeEvent , MarkdownTextInputProps , MarkdownTextInputElement , HTMLMarkdownElement } ;
829+
830+ function getWorkletRuntime ( ) {
831+ throw new Error ( '[react-native-live-markdown] `getWorkletRuntime` is not available on web. Please make sure to use it only on native Android or iOS.' ) ;
832+ }
833+
834+ export { getWorkletRuntime } ;
0 commit comments