Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.graphics.BlendModeColorFilter
import android.graphics.Color
import android.graphics.Rect
import android.os.Build
import android.text.InputType
import android.text.Spannable
import android.util.AttributeSet
import android.util.Log
Expand Down Expand Up @@ -306,6 +307,22 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
}
}

fun setAutoCapitalize(flagName: String?) {
val flag = when (flagName) {
"none" -> InputType.TYPE_NULL
"sentences" -> InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
"words" -> InputType.TYPE_TEXT_FLAG_CAP_WORDS
"characters" -> InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
else -> InputType.TYPE_NULL
}

inputType = (inputType and
InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS.inv() and
InputType.TYPE_TEXT_FLAG_CAP_WORDS.inv() and
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES.inv()
) or if (flag == InputType.TYPE_NULL) 0 else flag
}

// https://github.com/facebook/react-native/blob/36df97f500aa0aa8031098caf7526db358b6ddc1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L283C2-L284C1
// After the text changes inside an EditText, TextView checks if a layout() has been requested.
// If it has, it will not scroll the text to the end of the new text inserted, but wait for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager<ReactNativeRichTe
// this prop isn't used on Android as of now, but the setter must be present
}

override fun setAutoCapitalize(view: ReactNativeRichTextEditorView?, flag: String?) {
view?.setAutoCapitalize(flag)
}

override fun focus(view: ReactNativeRichTextEditorView?) {
view?.requestFocusProgrammatically()
}
Expand Down
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export default function App() {
placeholderTextColor="blue"
selectionColor="red"
cursorColor="yellow"
autocapitalize="sentences"
defaultValue={defaultValue}
onChangeText={handleChangeText}
onChangeHtml={handleChangeHtml}
Expand Down
1 change: 1 addition & 0 deletions src/ReactNativeRichTextEditorViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface NativeProps extends ViewProps {
mentionIndicators: string[];
cursorColor?: ColorValue;
selectionColor?: ColorValue;
autoCapitalize?: string;
richTextStyle?: RichTextStyleInternal;

// event callbacks
Expand Down
3 changes: 3 additions & 0 deletions src/RichTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface RichTextInputProps extends Omit<ViewProps, 'children'> {
placeholderTextColor?: ColorValue;
cursorColor?: ColorValue;
selectionColor?: ColorValue;
autocapitalize?: 'none' | 'sentences' | 'words' | 'characters';
richTextStyle?: RichTextStyle;
style?: ViewStyle | TextStyle;
onFocus?: () => void;
Expand Down Expand Up @@ -163,6 +164,7 @@ export const RichTextInput = ({
cursorColor,
selectionColor,
style,
autocapitalize = 'sentences',
richTextStyle = {},
onFocus,
onBlur,
Expand Down Expand Up @@ -320,6 +322,7 @@ export const RichTextInput = ({
cursorColor={cursorColor}
selectionColor={selectionColor}
style={style}
autoCapitalize={autocapitalize}
richTextStyle={normalizedRichTextStyle}
onInputFocus={onFocus}
onInputBlur={onBlur}
Expand Down
Loading