-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix disable scrolling for multiline text input #1244
Fix disable scrolling for multiline text input #1244
Conversation
Summary: # Context RN iOS supports disabling scrolling via `scrollEnabled` prop for multiline text inputs. https://reactnative.dev/docs/0.68/textinput#scrollenabled-ios This does [not work](microsoft#925) on MacOS Since MacOS does not use `UITextView` which inherits from `UIScrollView`, the view manager property was set but not actually passed down to the underlying scroll view. `RCTMultilineTextInputView` creates a `RCTUIScrollView` which is where we need to disable scrolling. https://www.internalfb.com/code/archon_react_native_macos/[fde4113acd89fb13ee11636c48b59eac49c21bae]/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m?lines=31 `RCTUIScrollView` inherits from `NSScrollView` which does not have a `scrollEnabled` property, but there is an api we can use to disable scrolling when the property is set. https://developer.apple.com/documentation/appkit/nsscrollview/1403494-scrollwheel # Usage NOTE: Only works with `multiline={true}` ``` <TextInput multiline={true} scrollEnabled={false} ... /> ``` # Change * Only expose the `scrollEnabled` property on `RCTMultilineTextInputView`. * `RCTSinglelineTextInputView` does not have scrolling so this property is unused. * `RCTMultilineTextInputView` delegates the `scrollEnabled` to it's underlying `_scrollView` * `RCTUIScrollView` defaults initial `scrollEnabled` to `YES` * `RCTUIScrollView` disables scrolling when the `scrollEnabled` is `NO`
506ed17
to
338e0e6
Compare
@mischreiber Could I get a second pair of eyes on this PR? |
And maybe also @chiuam who was looking at TextInput recently |
We're waiting on the "disable keyboard scrolling" bit to move this PR forward. |
Quick update. There is a better solution that disables scroll wheel & text that uses a custom clip view. Here is a native repro of how it should work: https://github.com/shwanton/DisabledScrollingTextViewExample There is some weird behavior with how we create textview, so overriding the clip view has unexpected behavior. |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
Uh... Don't close? |
Still working on this fix! |
Will this change now conflict with |
…line-textview-scroll-enabled # Conflicts: # Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h # Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m # React/Base/RCTUIKit.h # React/Base/macOS/RCTUIKit.m
# Conflicts: # React/Base/macOS/RCTUIKit.m
I've updated the description with the latest implementation details for disabling scrolling in multiline textview. The vertical scrollbar should be optional, I will follow up #1368 with a change we made. CleanShot.2022-09-26.at.10.15.22-converted.mp4 |
…line-textview-scroll-enabled
…line-textview-scroll-enabled
…hwanton/fix-multiline-textview-scroll-enabled
@Saadnajmi The updated fix here is ready to be merged! |
Please select one of the following
Summary
RN iOS supports disabling Multiline text input scrolling with
scrollEnabled
prop. https://reactnative.dev/docs/0.68/textinput#scrollenabled-iosSince macOS does not use
UITextView
which inherits fromUIScrollView
, theRCTBaseTextInputViewManager
scrollEnabled
remap was not used.On macOS,
RCTMultilineTextInputView
creates aRCTUIScrollView
which is where we need to disable scrolling.react-native-macos/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m
Line 31 in d9bcca9
RCTUIScrollView
inherits fromNSScrollView
which does not have ascrollEnabled
property, but there is a scrollWheel callback api we can use to disable scrolling whenscrollEnabled
isfalse
.UPDATE:
This approach was problematic since overriding
scrollWheel
for all scrollViews caused issues when pasting large amounts of text.This also did not disable keyboard scrolling with up/down keys.
Another solution is to disable scrolling for TextInput is to create a custom clipview & constrain scrolling.
#1366 added vertical scrollbars to all multiline text inputs. This introduced a layout regression where the scrollbar padding was not taken into account. The scrollbar should also be optional since scrolling can still happen w/o the vertical scrollbar.
Will add follow on diff to move this to configurable prop.
Changelog
[macOS] [Fixed] - Scrolling on Multiline Text Input can be disabled
Fixes #558 & #925
Usage
NOTE: Only works with
multiline={true}
Test Plan
Added Example to RNTester TextInput -> Multiline
CleanShot.2022-09-26.at.10.15.22-converted.mp4