Skip to content

Commit 01a7b5a

Browse files
authored
Fix disable scrolling for multiline text input (#1244)
1 parent 277129c commit 01a7b5a

File tree

9 files changed

+80
-5
lines changed

9 files changed

+80
-5
lines changed

Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h

+4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ NS_ASSUME_NONNULL_BEGIN
1212
@interface RCTMultilineTextInputView : RCTBaseTextInputView
1313

1414
#if TARGET_OS_OSX // [TODO(macOS GH#774)
15+
16+
@property (nonatomic, assign) BOOL scrollEnabled;
17+
1518
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
1619
@property (nonatomic, assign) BOOL hideVerticalScrollIndicator;
1720
#endif // ]TODO(macOS GH#774)
21+
1822
@end
1923

2024
NS_ASSUME_NONNULL_END

Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m

+24-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ @implementation RCTMultilineTextInputView
1515
{
1616
#if TARGET_OS_OSX // [TODO(macOS GH#774)
1717
RCTUIScrollView *_scrollView;
18+
RCTClipView *_clipView;
1819
#endif // ]TODO(macOS GH#774)
1920
RCTUITextView *_backedTextInputView;
2021
}
@@ -38,6 +39,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
3839
_scrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
3940
[_scrollView setHasVerticalScroller:YES];
4041

42+
_clipView = [[RCTClipView alloc] initWithFrame:_scrollView.frame];
43+
[_scrollView setContentView:_clipView];
44+
4145
_backedTextInputView.verticallyResizable = YES;
4246
_backedTextInputView.horizontallyResizable = YES;
4347
_backedTextInputView.textContainer.containerSize = NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX);
@@ -94,17 +98,35 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets
9498
[self setNeedsLayout];
9599
}
96100

97-
- (void)setEnableFocusRing:(BOOL)enableFocusRing {
101+
- (void)setEnableFocusRing:(BOOL)enableFocusRing
102+
{
98103
[super setEnableFocusRing:enableFocusRing];
99104
if ([_scrollView respondsToSelector:@selector(setEnableFocusRing:)]) {
100105
[_scrollView setEnableFocusRing:enableFocusRing];
101106
}
102107
}
103108

104-
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes {
109+
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
110+
{
105111
[_backedTextInputView setReadablePasteBoardTypes:readablePasteboardTypes];
106112
}
107113

114+
- (void)setScrollEnabled:(BOOL)scrollEnabled
115+
{
116+
if (scrollEnabled) {
117+
_scrollView.scrollEnabled = YES;
118+
[_clipView setConstrainScrolling:NO];
119+
} else {
120+
_scrollView.scrollEnabled = NO;
121+
[_clipView setConstrainScrolling:YES];
122+
}
123+
}
124+
125+
- (BOOL)scrollEnabled
126+
{
127+
return _scrollView.isScrollEnabled;
128+
}
129+
108130
- (BOOL)shouldShowVerticalScrollbar
109131
{
110132
// Hide vertical scrollbar if explicity set to NO

Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ - (RCTUIView *)view // TODO(macOS ISS#3536887)
2424
RCT_REMAP_OSX_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.enabledTextCheckingTypes, NSTextCheckingTypes) // TODO(macOS GH#774)
2525

2626
#if TARGET_OS_OSX // [TODO(macOS GH#774)
27+
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
2728
RCT_EXPORT_VIEW_PROPERTY(hideVerticalScrollIndicator, BOOL)
2829
RCT_CUSTOM_VIEW_PROPERTY(pastedTypes, NSArray<NSPasteboardType>*, RCTUITextView)
2930
{

Libraries/Text/TextInput/Multiline/RCTUITextView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
4646
@property (nonatomic, strong, nullable) NSString *inputAccessoryViewID;
4747

4848
#if TARGET_OS_OSX // [TODO(macOS GH#774)
49-
@property (nonatomic, assign) BOOL scrollEnabled;
49+
@property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
5050
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor; // TODO(OSS Candidate ISS#2710739)
5151
@property (nonatomic, assign) UIEdgeInsets textContainerInsets;
5252
@property (nonatomic, copy) NSString *text;

Libraries/Text/TextInput/RCTBaseTextInputViewManager.m

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ @implementation RCTBaseTextInputViewManager
5353
RCT_REMAP_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.continuousSpellCheckingEnabled, BOOL) // TODO(macOS GH#774)
5454
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) // TODO(macOS GH#774)
5555
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode) // TODO(macOS GH#774)
56-
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
5756
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) // TODO(macOS GH#774)
5857
RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL)
5958
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)

React/Base/RCTUIKit.h

+8
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,17 @@ CGPathRef UIBezierPathCreateCGPathRef(UIBezierPath *path);
427427
@property (nonatomic, assign) BOOL alwaysBounceVertical;
428428
// macOS specific properties
429429
@property (nonatomic, assign) BOOL enableFocusRing;
430+
@property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled;
430431

431432
@end
432433

434+
@interface RCTClipView : NSClipView // [TODO(macOS GH#774)
435+
436+
@property (nonatomic, assign) BOOL constrainScrolling;
437+
438+
@end // ]TODO(macOS GH#774)
439+
440+
433441
NS_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *event)
434442
{
435443
return [view hitTest:point];

React/Base/macOS/RCTUIKit.m

+33
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ - (void)setCursor:(NSInteger)cursor
436436

437437
@implementation RCTUIScrollView // TODO(macOS ISS#3536887)
438438

439+
- (instancetype)initWithFrame:(CGRect)frame
440+
{
441+
if (self = [super initWithFrame:frame]) {
442+
self.scrollEnabled = YES;
443+
}
444+
445+
return self;
446+
}
447+
439448
- (void)setEnableFocusRing:(BOOL)enableFocusRing {
440449
if (_enableFocusRing != enableFocusRing) {
441450
_enableFocusRing = enableFocusRing;
@@ -542,6 +551,7 @@ - (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical
542551
self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone;
543552
}
544553

554+
545555
@end
546556

547557
BOOL RCTUIViewSetClipsToBounds(RCTPlatformView *view)
@@ -557,3 +567,26 @@ BOOL RCTUIViewSetClipsToBounds(RCTPlatformView *view)
557567

558568
return clipsToBounds;
559569
}
570+
571+
@implementation RCTClipView
572+
573+
- (instancetype)initWithFrame:(NSRect)frameRect
574+
{
575+
if (self = [super initWithFrame:frameRect]) {
576+
self.constrainScrolling = NO;
577+
self.drawsBackground = NO;
578+
}
579+
580+
return self;
581+
}
582+
583+
- (NSRect)constrainBoundsRect:(NSRect)proposedBounds
584+
{
585+
if (self.constrainScrolling) {
586+
return NSMakeRect(0, 0, 0, 0);
587+
}
588+
589+
return [super constrainBoundsRect:proposedBounds];
590+
}
591+
592+
@end

React/Views/ScrollView/RCTScrollView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ - (BOOL)isFlipped
116116

117117
- (void)scrollWheel:(NSEvent *)theEvent
118118
{
119-
if (!self.scrollEnabled) {
119+
if (!self.isScrollEnabled) {
120120
[[self nextResponder] scrollWheel:theEvent];
121121
return;
122122
}

packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js

+8
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,14 @@ exports.examples = ([
742742
multiline={true}
743743
style={styles.multiline}
744744
/>
745+
{/* [TODO(macOS GH#774) */}
746+
<TextInput
747+
placeholder="multiline text input with scroll disabled"
748+
multiline={true}
749+
scrollEnabled={false}
750+
style={styles.multiline}
751+
/>
752+
{/* [TODO(macOS GH#774) */}
745753
<TextInput
746754
placeholder="multiline text input with vertical scrollbar hidden"
747755
multiline={true}

0 commit comments

Comments
 (0)