Skip to content

Commit 12d8de3

Browse files
committed
feat: add scrollEnabled prop
1 parent a16c4d0 commit 12d8de3

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class EnrichedTextInputView : AppCompatEditText {
5454
val parametrizedStyles: ParametrizedStyles? = ParametrizedStyles(this)
5555
var isDuringTransaction: Boolean = false
5656
var isRemovingMany: Boolean = false
57+
var scrollEnabled = true
5758

5859
val mentionHandler: MentionHandler? = MentionHandler(this)
5960
var htmlStyle: HtmlStyle = HtmlStyle(this, null)
@@ -137,6 +138,14 @@ class EnrichedTextInputView : AppCompatEditText {
137138
return super.onTouchEvent(ev)
138139
}
139140

141+
override fun canScrollVertically(direction: Int): Boolean {
142+
return scrollEnabled
143+
}
144+
145+
override fun canScrollHorizontally(direction: Int): Boolean {
146+
return scrollEnabled
147+
}
148+
140149
override fun onSelectionChanged(selStart: Int, selEnd: Int) {
141150
super.onSelectionChanged(selStart, selEnd)
142151
selection?.onSelection(selStart, selEnd)

android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class EnrichedTextInputViewManager : SimpleViewManager<EnrichedTextInputView>(),
155155
view?.setFontStyle(style)
156156
}
157157

158+
@ReactProp(name = "scrollEnabled")
159+
override fun setScrollEnabled(view: EnrichedTextInputView, scrollEnabled: Boolean) {
160+
view.scrollEnabled = scrollEnabled
161+
}
162+
158163
override fun onAfterUpdateTransaction(view: EnrichedTextInputView) {
159164
super.onAfterUpdateTransaction(view)
160165
view.updateTypeface()

ios/EnrichedTextInputView.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
357357
stylePropChanged = YES;
358358
}
359359

360+
if(newViewProps.scrollEnabled != oldViewProps.scrollEnabled || textView.scrollEnabled != newViewProps.scrollEnabled) {
361+
[self setScrollEnabled: newViewProps.scrollEnabled];
362+
}
363+
360364
folly::dynamic oldMentionStyle = oldViewProps.htmlStyle.mention;
361365
folly::dynamic newMentionStyle = newViewProps.htmlStyle.mention;
362366
if(oldMentionStyle != newMentionStyle) {
@@ -862,6 +866,10 @@ - (void)tryEmittingOnChangeHtmlEvent {
862866
}
863867
}
864868

869+
-(void)setScrollEnabled:(bool)scrollEnabled {
870+
[textView setScrollEnabled: scrollEnabled];
871+
}
872+
865873
// MARK: - Styles manipulation
866874

867875
- (void)toggleRegularStyle:(StyleType)type {

src/EnrichedTextInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export interface EnrichedTextInputProps extends Omit<ViewProps, 'children'> {
130130
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
131131
htmlStyle?: HtmlStyle;
132132
style?: ViewStyle | TextStyle;
133+
scrollEnabled?: boolean;
133134
onFocus?: () => void;
134135
onBlur?: () => void;
135136
onChangeText?: (e: NativeSyntheticEvent<OnChangeTextEvent>) => void;
@@ -192,6 +193,7 @@ export const EnrichedTextInput = ({
192193
onEndMention,
193194
onChangeSelection,
194195
androidExperimentalSynchronousEvents = false,
196+
scrollEnabled = true,
195197
...rest
196198
}: EnrichedTextInputProps) => {
197199
const nativeRef = useRef<ComponentType | null>(null);
@@ -352,6 +354,7 @@ export const EnrichedTextInput = ({
352354
androidExperimentalSynchronousEvents={
353355
androidExperimentalSynchronousEvents
354356
}
357+
scrollEnabled={scrollEnabled}
355358
{...rest}
356359
/>
357360
);

src/EnrichedTextInputNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export interface NativeProps extends ViewProps {
135135
selectionColor?: ColorValue;
136136
autoCapitalize?: string;
137137
htmlStyle?: HtmlStyleInternal;
138+
scrollEnabled?: boolean;
138139

139140
// event callbacks
140141
onInputFocus?: DirectEventHandler<null>;

0 commit comments

Comments
 (0)