Skip to content

Commit 8fc6472

Browse files
IvanIhnatsiuktomekzawexploIF
authored
feat: add scrollEnabled prop (#226)
### Description The scrollEnabled option has been added to prohibit scrolling of content inside a text field. In some cases, this can be useful (as in our application) when we want to show multiple EnrichedTextInput and a single ScrollView. ### Screenshots Android: https://github.com/user-attachments/assets/f8c09315-ffe1-4a53-b9c8-e07e64a70884 iOS: https://github.com/user-attachments/assets/0e61ef2a-a15a-4d5a-ac9b-9b33651bceab --------- Co-authored-by: Tomasz Zawadzki <tomekzawadzki98@gmail.com> Co-authored-by: Igor Furgała <74370735+exploIF@users.noreply.github.com>
1 parent 6996dfd commit 8fc6472

5 files changed

Lines changed: 22 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: Boolean = true
5758

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

143+
override fun canScrollVertically(direction: Int): Boolean {
144+
return scrollEnabled
145+
}
146+
147+
override fun canScrollHorizontally(direction: Int): Boolean {
148+
return scrollEnabled
149+
}
150+
142151
override fun onSelectionChanged(selStart: Int, selEnd: Int) {
143152
super.onSelectionChanged(selStart, selEnd)
144153
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
@@ -154,6 +154,11 @@ class EnrichedTextInputViewManager : SimpleViewManager<EnrichedTextInputView>(),
154154
view?.setFontStyle(style)
155155
}
156156

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

ios/EnrichedTextInputView.mm

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

361+
if(newViewProps.scrollEnabled != oldViewProps.scrollEnabled || textView.scrollEnabled != newViewProps.scrollEnabled) {
362+
[textView setScrollEnabled:newViewProps.scrollEnabled];
363+
}
364+
361365
folly::dynamic oldMentionStyle = oldViewProps.htmlStyle.mention;
362366
folly::dynamic newMentionStyle = newViewProps.htmlStyle.mention;
363367
if(oldMentionStyle != newMentionStyle) {

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)