Skip to content

Commit

Permalink
feat(rich-text): add android component
Browse files Browse the repository at this point in the history
  • Loading branch information
IslamRustamov committed Sep 23, 2024
1 parent e34e935 commit b197a6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cd ios && pod install

## Installation for Android

Android is not implemented yet
No specific installation needed, just install the lib and launch the project

## Usage

Expand Down Expand Up @@ -71,12 +71,12 @@ const handleChange = (event: RichTextChangeEvent) => {
# What was done
1. Setting placeholder (iOS)
1. Setting placeholder (iOS, Android)
2. Select a portion of text and add different styles (bold, italic, underline, strikethrough) (iOS)
3. Add native context menu for formatting (iOS)
4. Add onChange prop (iOS)
5. Return text without markdown
6. Add method that returns rich text in RTF
5. Return text without markdown (iOS)
6. Add method that returns rich text in RTF (iOS)
# TODO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.richtextinput

import android.graphics.Color
import android.view.View
import android.widget.EditText
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp

class RichTextInputViewManager : SimpleViewManager<View>() {
class RichTextInputViewManager : SimpleViewManager<EditText>() {
override fun getName() = "RichTextInputView"

override fun createViewInstance(reactContext: ThemedReactContext): View {
return View(reactContext)
override fun createViewInstance(reactContext: ThemedReactContext): EditText {
return EditText(reactContext)
}

@ReactProp(name = "color")
fun setColor(view: View, color: String) {
view.setBackgroundColor(Color.parseColor(color))
@ReactProp(name = "placeholder")
fun setPlaceholder(view: EditText, placeholder: String) {
view.hint = placeholder
}
}
17 changes: 11 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ const RichTextInput = forwardRef<RichTextRef, RichTextProps>(
const inputRef = useRef<RichTextRef>();

useEffect(() => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(inputRef.current as unknown as Component),
'setPlaceholder',
[placeholder]
);
// Temporary hack for iOS
if (Platform.OS === 'ios') {
UIManager.dispatchViewManagerCommand(
findNodeHandle(inputRef.current as unknown as Component),
'setPlaceholder',
[placeholder]
);
}
}, [placeholder]);

useImperativeHandle(ref, () => {
Expand Down Expand Up @@ -95,7 +98,9 @@ const RichTextInput = forwardRef<RichTextRef, RichTextProps>(
};
}, []);

return <RichTextInputView ref={inputRef} {...rest} />;
return (
<RichTextInputView ref={inputRef} placeholder={placeholder} {...rest} />
);
}
);

Expand Down

0 comments on commit b197a6b

Please sign in to comment.