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 @@ -614,6 +614,18 @@ class EnrichedTextInputView :
}
}

fun setAutoCorrect(autoCorrect: Boolean) {
val flagsToUnset = InputType.TYPE_TEXT_FLAG_AUTO_CORRECT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS

val flagsToSet =
when (autoCorrect) {
true -> InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
false -> InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
}

this.inputType = (this.inputType and flagsToUnset.inv()) or flagsToSet
}

fun setAutoCapitalize(flagName: String?) {
val flag =
when (flagName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ class EnrichedTextInputViewManager :
view.allowFontScaling = allowFontScaling
}

@ReactProp(name = "autoCorrect")
override fun setAutoCorrect(
view: EnrichedTextInputView?,
autoCorrect: Boolean,
) {
view?.setAutoCorrect(autoCorrect)
}

@ReactProp(name = "spellCheck")
override fun setSpellCheck(
view: EnrichedTextInputView?,
spellCheck: Boolean,
) {
// not supported in Android's RN TextInput
}

override fun onAfterUpdateTransaction(view: EnrichedTextInputView) {
super.onAfterUpdateTransaction(view)
view.afterUpdateTransaction()
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/api-reference/enriched-text-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ If `true`, the input respects the system's accessibility font scaling settings.
| --------- | ------- | ------------ |
| `boolean` | `true` | Android, iOS |

### `autoCorrect` {#autocorrect}

If false, disables auto-correct.

| Type | Default | Platforms |
| --------- | ------- | ------------ |
| `boolean` | `true` | Android, iOS |

### `autoFocus` {#autofocus}

If `true`, focuses the input when it mounts.
Expand Down Expand Up @@ -633,6 +641,14 @@ cursor (caret) also uses this color.
| ---------------------------------------------- | -------------- | ----------------- |
| [`color`](https://reactnative.dev/docs/colors) | system default | Android, iOS, Web |

### `spellCheck` {#spellcheck}

If false, disables spell-check style (i.e. red underlines). The default value is inherited from the [`autoCorrect`](#autocorrect) prop.

| Type | Default | Platforms |
| --------- | ----------------------------- | --------- |
| `boolean` | [`autoCorrect`](#autocorrect) | iOS |

Comment thread
hejsztynx marked this conversation as resolved.
### `style` {#style}

Controls the layout, dimensions, typography, borders, shadows, opacity, and
Expand Down
14 changes: 14 additions & 0 deletions ios/EnrichedTextInputView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,20 @@ - (void)updateProps:(Props::Shared const &)props
}
}

// autoCorrect
if (newViewProps.autoCorrect != oldViewProps.autoCorrect) {
textView.autocorrectionType = newViewProps.autoCorrect
? UITextAutocorrectionTypeYes
: UITextAutocorrectionTypeNo;
}
Comment thread
hejsztynx marked this conversation as resolved.

// spellCheck
if (newViewProps.spellCheck != oldViewProps.spellCheck) {
textView.spellCheckingType = newViewProps.spellCheck
? UITextSpellCheckingTypeYes
: UITextSpellCheckingTypeNo;
}

// isOnChangeHtmlSet
_emitHtml = newViewProps.isOnChangeHtmlSet;

Expand Down
4 changes: 4 additions & 0 deletions src/native/EnrichedTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const EnrichedTextInput = ({
selectionColor,
style,
autoCapitalize = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.autoCapitalize,
autoCorrect = true,
spellCheck,
htmlStyle = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.htmlStyle,
linkRegex: _linkRegex,
onFocus,
Expand Down Expand Up @@ -340,6 +342,8 @@ export const EnrichedTextInput = ({
selectionColor={selectionColor}
style={style}
autoCapitalize={autoCapitalize}
autoCorrect={autoCorrect}
spellCheck={spellCheck ?? autoCorrect}
htmlStyle={normalizedHtmlStyle}
linkRegex={linkRegex}
onInputFocus={onFocus}
Expand Down
2 changes: 2 additions & 0 deletions src/spec/EnrichedTextInputNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ export interface NativeProps extends ViewProps {
cursorColor?: ColorValue;
selectionColor?: ColorValue;
autoCapitalize?: string;
autoCorrect?: boolean;
spellCheck?: boolean;
htmlStyle?: HtmlStyleInternal;
scrollEnabled?: boolean;
linkRegex?: LinkNativeRegex;
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ export interface EnrichedTextInputProps extends Omit<ViewProps, 'children'> {
/** Controls automatic capitalization of typed text. Defaults to `"sentences"`. */
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';

/** If false, disables auto-correct. Defaults `true`. */
autoCorrect?: boolean;

/** If false, disables spell-check style (i.e. red underlines). The default value is inherited from the `autoCorrect` prop.
*
* @platform ios
*/
spellCheck?: boolean;
Comment thread
hejsztynx marked this conversation as resolved.

/** Style overrides applied to the rendered HTML content inside the editor. */
htmlStyle?: HtmlStyle;

Expand Down
Loading