Skip to content

Commit 49c524f

Browse files
committed
[ptmt#18] Add padding prop to TextInput multiline={true}
1 parent 2fc7846 commit 49c524f

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Libraries/Text/RCTTextView.m

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ @implementation RCTTextView
3434
NSString *_placeholder;
3535
TextViewWithPlaceHolder *_textView;
3636
NSInteger _nativeEventCount;
37+
CGFloat _padding;
3738
}
3839

3940
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
@@ -49,6 +50,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
4950
//_textView.scrollsToTop = NO;
5051
_jsRequestingFirstResponder = YES;
5152
_textView.delegate = self;
53+
_padding = 0;
5254
[self addSubview:_textView];
5355
}
5456
return self;
@@ -66,22 +68,24 @@ - (void)updateFrames
6668
// We apply the left inset to the frame since a negative left text-container
6769
// inset mysteriously causes the text to be hidden until the text view is
6870
// first focused.
69-
NSEdgeInsets adjustedFrameInset = NSEdgeInsetsZero;
70-
adjustedFrameInset.left = _contentInset.left - 5;
71-
72-
NSEdgeInsets adjustedTextContainerInset = _contentInset;
73-
adjustedTextContainerInset.top += 5;
74-
adjustedTextContainerInset.left = 0;
75-
71+
// NSEdgeInsets adjustedFrameInset = NSEdgeInsetsZero;
72+
// adjustedFrameInset.left = _contentInset.left - 5;
73+
//
74+
// NSEdgeInsets adjustedTextContainerInset = _contentInset;
75+
// adjustedTextContainerInset.top += 5;
76+
// adjustedTextContainerInset.left = 0;
77+
//
7678
CGRect frame = self.frame;// TODO: UIEdgeInsetsInsetRect(self.bounds, adjustedFrameInset);
7779
_textView.frame = frame;
7880

7981
// TODO:
80-
// _textView.textContainerInset = adjustedTextContainerInset;
81-
// _placeholderView.textContainerInset = adjustedTextContainerInset;
82+
[_textView setTextContainerInset:CGSizeMake(_padding, _padding)];
83+
//_textView.textContainerInset = adjustedTextContainerInset;
84+
8285
}
8386

8487

88+
8589
- (void)updatePlaceholder
8690
{
8791
if (_placeholder) {
@@ -132,6 +136,13 @@ - (void)setPlaceholderTextColor:(NSColor *)placeholderTextColor
132136
[self updatePlaceholder];
133137
}
134138

139+
- (void)setPadding:(CGFloat )padding
140+
{
141+
// NSLog(@"padding %@", padding);
142+
_padding = padding;
143+
[self updateFrames];
144+
}
145+
135146
- (void)setContentInset:(NSEdgeInsets)contentInset
136147
{
137148
_contentInset = contentInset;

Libraries/Text/RCTTextViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ - (NSView *)view
2828
RCT_REMAP_VIEW_PROPERTY(editable, textView.editable, BOOL)
2929
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
3030
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, NSColor)
31+
RCT_EXPORT_VIEW_PROPERTY(padding, CGFloat)
3132
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
3233
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
3334
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)

0 commit comments

Comments
 (0)