RCTMultilineTextInputView.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTMultilineTextInputView.h>
  8. #import <React/RCTUtils.h>
  9. #import <React/RCTUITextView.h>
  10. @implementation RCTMultilineTextInputView
  11. {
  12. RCTUITextView *_backedTextInputView;
  13. }
  14. - (instancetype)initWithBridge:(RCTBridge *)bridge
  15. {
  16. if (self = [super initWithBridge:bridge]) {
  17. // `blurOnSubmit` defaults to `false` for <TextInput multiline={true}> by design.
  18. self.blurOnSubmit = NO;
  19. _backedTextInputView = [[RCTUITextView alloc] initWithFrame:self.bounds];
  20. _backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  21. _backedTextInputView.textInputDelegate = self;
  22. [self addSubview:_backedTextInputView];
  23. }
  24. return self;
  25. }
  26. - (id<RCTBackedTextInputViewProtocol>)backedTextInputView
  27. {
  28. return _backedTextInputView;
  29. }
  30. #pragma mark - UIScrollViewDelegate
  31. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  32. {
  33. RCTDirectEventBlock onScroll = self.onScroll;
  34. if (onScroll) {
  35. CGPoint contentOffset = scrollView.contentOffset;
  36. CGSize contentSize = scrollView.contentSize;
  37. CGSize size = scrollView.bounds.size;
  38. UIEdgeInsets contentInset = scrollView.contentInset;
  39. onScroll(@{
  40. @"contentOffset": @{
  41. @"x": @(contentOffset.x),
  42. @"y": @(contentOffset.y)
  43. },
  44. @"contentInset": @{
  45. @"top": @(contentInset.top),
  46. @"left": @(contentInset.left),
  47. @"bottom": @(contentInset.bottom),
  48. @"right": @(contentInset.right)
  49. },
  50. @"contentSize": @{
  51. @"width": @(contentSize.width),
  52. @"height": @(contentSize.height)
  53. },
  54. @"layoutMeasurement": @{
  55. @"width": @(size.width),
  56. @"height": @(size.height)
  57. },
  58. @"zoomScale": @(scrollView.zoomScale ?: 1),
  59. });
  60. }
  61. }
  62. @end