Skip to content

Commit 11b8c1d

Browse files
authored
feat: allow making input non editable (#39)
1 parent 3352947 commit 11b8c1d

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager<ReactNativeRichTe
102102
view?.setAutoFocus(autoFocus)
103103
}
104104

105+
@ReactProp(name = "editable", defaultBoolean = true)
106+
override fun setEditable(view: ReactNativeRichTextEditorView?, editable: Boolean) {
107+
view?.isEnabled = editable
108+
}
109+
105110
@ReactProp(name = "mentionIndicators")
106111
override fun setMentionIndicators(view: ReactNativeRichTextEditorView?, indicators: ReadableArray?) {
107112
if (indicators == null) return

src/ReactNativeRichTextEditorViewNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface OnPressMentionEvent {
5555
export interface NativeProps extends ViewProps {
5656
// base props
5757
autoFocus?: boolean;
58+
editable?: boolean;
5859
defaultValue?: string;
5960
placeholder?: string;
6061
placeholderTextColor?: ColorValue;

src/RichTextInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface OnChangeMentionEvent {
6060
export interface RichTextInputProps extends Omit<ViewProps, 'children'> {
6161
ref?: RefObject<RichTextInputInstance | null>;
6262
autoFocus?: boolean;
63+
editable?: boolean;
6364
mentionIndicators?: string[];
6465
defaultValue?: string;
6566
placeholder?: string;
@@ -97,6 +98,7 @@ type ComponentType = (Component<NativeProps, {}, any> & NativeMethods) | null;
9798
export const RichTextInput = ({
9899
ref,
99100
autoFocus,
101+
editable = true,
100102
mentionIndicators = ['@'],
101103
defaultValue,
102104
placeholder,
@@ -228,6 +230,7 @@ export const RichTextInput = ({
228230
<ReactNativeRichTextEditorView
229231
ref={nativeRef}
230232
mentionIndicators={mentionIndicators}
233+
editable={editable}
231234
autoFocus={autoFocus}
232235
defaultValue={defaultValue}
233236
placeholder={placeholder}

0 commit comments

Comments
 (0)