diff --git a/README.md b/README.md index f8caf1a..43e8d10 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ const handleChange = (event: RichTextChangeEvent) => { 1. Setting placeholder (iOS, Android) 2. Select a portion of text and add different styles (bold, italic, underline, strikethrough) (iOS, Android) 3. Add native context menu for formatting (iOS) -4. Add onChange prop (iOS) +4. Add onChange prop (iOS, Android) 5. Return text without markdown (iOS) 6. Add method that returns rich text in RTF (iOS) diff --git a/android/src/main/java/com/richtextinput/RichTextInputViewManager.kt b/android/src/main/java/com/richtextinput/RichTextInputViewManager.kt index 1d6173f..8d2893d 100644 --- a/android/src/main/java/com/richtextinput/RichTextInputViewManager.kt +++ b/android/src/main/java/com/richtextinput/RichTextInputViewManager.kt @@ -6,18 +6,41 @@ import android.text.style.StrikethroughSpan import android.text.style.StyleSpan import android.text.style.UnderlineSpan import android.widget.EditText +import androidx.core.widget.doOnTextChanged import com.facebook.infer.annotation.Assertions +import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReadableArray import com.facebook.react.uimanager.SimpleViewManager import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.annotations.ReactProp - +import com.facebook.react.uimanager.events.RCTEventEmitter class RichTextInputViewManager : SimpleViewManager() { override fun getName() = "RichTextInputView" + override fun getExportedCustomBubblingEventTypeConstants(): Map { + return mapOf( + "topChange" to mapOf( + "phasedRegistrationNames" to mapOf( + "bubbled" to "onChange" + ) + ) + ) + } + override fun createViewInstance(reactContext: ThemedReactContext): EditText { - return EditText(reactContext) + val editText = EditText(reactContext) + + editText.doOnTextChanged { text, start, before, count -> + val event = Arguments.createMap().apply { + putString("text", text.toString()) + } + reactContext + .getJSModule(RCTEventEmitter::class.java) + .receiveEvent(editText.id, "topChange", event) + } + + return editText } @ReactProp(name = "placeholder")