Skip to content

feat: Add TextInput numberOfLines support to iOS #20

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/Multiline/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (instancetype)initWithFrame:(CGRect)frame
self.textColor = [UIColor blackColor];
// This line actually removes 5pt (default value) left and right padding in UITextView.
self.textContainer.lineFragmentPadding = 0;
self.textContainer.maximumNumberOfLines = 2;
self.scrollsToTop = NO;
self.scrollEnabled = YES;
}
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ @implementation RCTBaseTextInputViewManager
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
RCT_REMAP_VIEW_PROPERTY(numberOfLines, backedTextInputView.numberOfLines, NSInteger)
RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL)
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
Expand Down Expand Up @@ -72,6 +73,7 @@ @implementation RCTBaseTextInputViewManager
RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)


RCT_CUSTOM_VIEW_PROPERTY(multiline, BOOL, UIView)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class TextInputTraits final {
*/
bool contextMenuHidden{false};

std::optional<int> numberOfLines{0};

/*
* iOS & Android
* Default value: `true`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ static TextInputTraits convertRawProp(
"spellCheck",
sourceTraits.spellCheck,
defaultTraits.spellCheck);
traits.numberOfLines = convertRawProp(
context,
rawProps,
"numberOfLines",
sourceTraits.numberOfLines,
defaultTraits.numberOfLines);
traits.caretHidden = convertRawProp(
context,
rawProps,
Expand Down