Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Last active September 9, 2015 15:55
Show Gist options
  • Save dhrrgn/2e0c84a4075bf0f2d05f to your computer and use it in GitHub Desktop.
Save dhrrgn/2e0c84a4075bf0f2d05f to your computer and use it in GitHub Desktop.
diff --git a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
index f114ac1..70df59f 100644
--- a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
+++ b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
@@ -34,6 +34,7 @@ var onlyMultiline = {
onSelectionChange: true, // not supported in Open Source yet
onTextInput: true, // not supported in Open Source yet
children: true,
+ autoGrow: true,
};
var notMultiline = {
@@ -120,6 +121,10 @@ var TextInput = React.createClass({
*/
autoCorrect: PropTypes.bool,
/**
+ * If true, and the input is multiline, the input's height will grow automatically. The default value is true.
+ */
+ autoGrow: PropTypes.bool,
+ /**
* If true, focuses the input on componentDidMount.
* The default value is false.
*/
diff --git a/node_modules/react-native/Libraries/Text/RCTTextView.h b/node_modules/react-native/Libraries/Text/RCTTextView.h
index c5012ec..f761e95 100644
--- a/node_modules/react-native/Libraries/Text/RCTTextView.h
+++ b/node_modules/react-native/Libraries/Text/RCTTextView.h
@@ -17,6 +17,7 @@
@interface RCTTextView : RCTView <UITextViewDelegate>
@property (nonatomic, assign) BOOL autoCorrect;
+@property (nonatomic, assign) BOOL autoGrow;
@property (nonatomic, assign) BOOL clearTextOnFocus;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) UIEdgeInsets contentInset;
diff --git a/node_modules/react-native/Libraries/Text/RCTTextView.m b/node_modules/react-native/Libraries/Text/RCTTextView.m
index 337e446..ad58636 100644
--- a/node_modules/react-native/Libraries/Text/RCTTextView.m
+++ b/node_modules/react-native/Libraries/Text/RCTTextView.m
@@ -18,6 +18,8 @@
{
RCTEventDispatcher *_eventDispatcher;
BOOL _jsRequestingFirstResponder;
+ BOOL _autoGrow;
+ float _origHeight;
NSString *_placeholder;
UITextView *_placeholderView;
UITextView *_textView;
@@ -29,6 +31,7 @@
RCTAssertParam(eventDispatcher);
if ((self = [super initWithFrame:CGRectZero])) {
+ _autoGrow = false;
_contentInset = UIEdgeInsetsZero;
_eventDispatcher = eventDispatcher;
_placeholderTextColor = [self defaultPlaceholderTextColor];
@@ -66,6 +69,10 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
_textView.textContainerInset = adjustedTextContainerInset;
_placeholderView.textContainerInset = adjustedTextContainerInset;
+
+ if (! _origHeight) {
+ _origHeight = self.frame.size.height;
+ }
}
- (void)updatePlaceholder
@@ -193,6 +200,11 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
return _textView.autocorrectionType == UITextAutocorrectionTypeYes;
}
+- (void)setAutoGrow:(BOOL)autoGrow
+{
+ _autoGrow = autoGrow;
+}
+
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
if (_selectTextOnFocus) {
@@ -218,6 +230,21 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (void)textViewDidChange:(UITextView *)textView
{
+ if (_autoGrow) {
+ _textView.scrollEnabled = NO;
+
+ [_textView sizeToFit];
+ CGRect frame = self.frame;
+
+ if (_textView.frame.size.height >= _origHeight) {
+ frame.size.height = _textView.frame.size.height;
+ } else {
+ frame.size.height = _origHeight;
+ }
+
+ self.frame = frame;
+ }
+
[self _setPlaceholderVisibility];
_nativeEventCount++;
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeChange
diff --git a/node_modules/react-native/Libraries/Text/RCTTextViewManager.m b/node_modules/react-native/Libraries/Text/RCTTextViewManager.m
index f47a106..b613a44 100644
--- a/node_modules/react-native/Libraries/Text/RCTTextViewManager.m
+++ b/node_modules/react-native/Libraries/Text/RCTTextViewManager.m
@@ -25,6 +25,7 @@ RCT_EXPORT_MODULE()
}
RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL)
+RCT_EXPORT_VIEW_PROPERTY(autoGrow, BOOL)
RCT_REMAP_VIEW_PROPERTY(editable, textView.editable, BOOL)
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment