Skip to content

Commit

Permalink
feat(rich-text): add onChange for android
Browse files Browse the repository at this point in the history
  • Loading branch information
IslamRustamov committed Sep 26, 2024
1 parent 4e11f1e commit bcae185
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditText>() {
override fun getName() = "RichTextInputView"

override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> {
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")
Expand Down

0 comments on commit bcae185

Please sign in to comment.