2015-04-29 08:29:00 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-04-29 08:29:00 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-20 03:48:22 +00:00
|
|
|
#import "RCTMultilineTextInputView.h"
|
2015-04-29 08:29:00 +00:00
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTUtils.h>
|
|
|
|
|
2017-03-20 07:00:23 +00:00
|
|
|
#import "RCTUITextView.h"
|
2015-11-02 17:13:41 +00:00
|
|
|
|
2017-12-20 03:48:22 +00:00
|
|
|
@implementation RCTMultilineTextInputView
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2018-01-24 07:17:57 +00:00
|
|
|
RCTUITextView *_backedTextInputView;
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 07:00:18 +00:00
|
|
|
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2017-06-27 23:05:05 +00:00
|
|
|
if (self = [super initWithBridge:bridge]) {
|
2017-07-18 21:33:35 +00:00
|
|
|
// `blurOnSubmit` defaults to `false` for <TextInput multiline={true}> by design.
|
2018-01-24 07:17:57 +00:00
|
|
|
self.blurOnSubmit = NO;
|
2015-04-29 08:29:00 +00:00
|
|
|
|
2018-01-24 07:17:57 +00:00
|
|
|
_backedTextInputView = [[RCTUITextView alloc] initWithFrame:self.bounds];
|
|
|
|
_backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
_backedTextInputView.backgroundColor = [UIColor clearColor];
|
|
|
|
_backedTextInputView.textColor = [UIColor blackColor];
|
2017-03-20 07:00:18 +00:00
|
|
|
// This line actually removes 5pt (default value) left and right padding in UITextView.
|
2018-01-24 07:17:57 +00:00
|
|
|
_backedTextInputView.textContainer.lineFragmentPadding = 0;
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2018-01-24 07:17:57 +00:00
|
|
|
_backedTextInputView.scrollsToTop = NO;
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2018-01-24 07:17:57 +00:00
|
|
|
_backedTextInputView.scrollEnabled = YES;
|
|
|
|
_backedTextInputView.textInputDelegate = self;
|
2017-07-18 21:33:31 +00:00
|
|
|
|
2018-01-24 07:17:57 +00:00
|
|
|
[self addSubview:_backedTextInputView];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
2018-01-24 07:17:57 +00:00
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-06-27 23:05:04 +00:00
|
|
|
- (id<RCTBackedTextInputViewProtocol>)backedTextInputView
|
|
|
|
{
|
2018-01-24 07:17:57 +00:00
|
|
|
return _backedTextInputView;
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 00:43:24 +00:00
|
|
|
#pragma mark - UIScrollViewDelegate
|
|
|
|
|
2016-11-22 19:52:18 +00:00
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
|
|
|
{
|
2018-01-24 07:17:57 +00:00
|
|
|
RCTDirectEventBlock onScroll = self.onScroll;
|
|
|
|
|
|
|
|
if (onScroll) {
|
2017-03-20 07:00:17 +00:00
|
|
|
CGPoint contentOffset = scrollView.contentOffset;
|
|
|
|
CGSize contentSize = scrollView.contentSize;
|
|
|
|
CGSize size = scrollView.bounds.size;
|
|
|
|
UIEdgeInsets contentInset = scrollView.contentInset;
|
|
|
|
|
2018-01-24 07:17:57 +00:00
|
|
|
onScroll(@{
|
2016-11-22 19:52:18 +00:00
|
|
|
@"contentOffset": @{
|
2017-03-20 07:00:17 +00:00
|
|
|
@"x": @(contentOffset.x),
|
|
|
|
@"y": @(contentOffset.y)
|
2016-11-22 19:52:18 +00:00
|
|
|
},
|
|
|
|
@"contentInset": @{
|
2017-03-20 07:00:17 +00:00
|
|
|
@"top": @(contentInset.top),
|
|
|
|
@"left": @(contentInset.left),
|
|
|
|
@"bottom": @(contentInset.bottom),
|
|
|
|
@"right": @(contentInset.right)
|
2016-11-22 19:52:18 +00:00
|
|
|
},
|
|
|
|
@"contentSize": @{
|
2017-03-20 07:00:17 +00:00
|
|
|
@"width": @(contentSize.width),
|
|
|
|
@"height": @(contentSize.height)
|
2016-11-22 19:52:18 +00:00
|
|
|
},
|
|
|
|
@"layoutMeasurement": @{
|
2017-03-20 07:00:17 +00:00
|
|
|
@"width": @(size.width),
|
|
|
|
@"height": @(size.height)
|
2016-11-22 19:52:18 +00:00
|
|
|
},
|
2017-03-20 07:00:17 +00:00
|
|
|
@"zoomScale": @(scrollView.zoomScale ?: 1),
|
2016-11-22 19:52:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
@end
|