2015-04-29 08:29:00 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTTextViewManager.h"
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTFont.h>
|
2017-05-08 06:54:51 +00:00
|
|
|
#import <React/RCTShadowView+Layout.h>
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTShadowView.h>
|
|
|
|
|
2016-11-23 13:41:07 +00:00
|
|
|
#import "RCTConvert+Text.h"
|
2017-03-13 20:31:35 +00:00
|
|
|
#import "RCTShadowTextView.h"
|
2016-12-19 14:26:07 +00:00
|
|
|
#import "RCTTextView.h"
|
2015-04-29 08:29:00 +00:00
|
|
|
|
|
|
|
@implementation RCTTextViewManager
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2017-03-13 20:31:35 +00:00
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [RCTShadowTextView new];
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
2017-03-20 07:00:18 +00:00
|
|
|
return [[RCTTextView alloc] initWithBridge:self.bridge];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textView.autocapitalizationType, UITextAutocapitalizationType)
|
2016-11-23 13:41:07 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
|
2016-11-25 12:20:21 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(spellCheck, spellCheckingType, UITextSpellCheckingType)
|
2015-12-02 15:11:20 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
|
2015-04-29 22:55:36 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)
|
2016-02-07 20:37:17 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(textAlign, textView.textAlignment, NSTextAlignment)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(editable, textView.editable, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, textView.enablesReturnKeyAutomatically, BOOL)
|
2015-04-29 22:55:36 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(keyboardType, textView.keyboardType, UIKeyboardType)
|
2015-11-11 13:31:18 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, textView.keyboardAppearance, UIKeyboardAppearance)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
|
2016-05-25 13:07:35 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
2016-07-07 15:44:59 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
|
2015-11-14 17:41:59 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
2016-11-22 19:52:18 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
|
2016-06-24 13:28:38 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)
|
2015-04-29 22:55:36 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(returnKeyType, textView.returnKeyType, UIReturnKeyType)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, textView.secureTextEntry, BOOL)
|
2016-02-03 13:48:31 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(selectionColor, tintColor, UIColor)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
|
2016-08-26 00:18:05 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
|
2015-11-24 22:26:14 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
|
2016-08-05 19:29:21 +00:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextView)
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
2016-08-05 19:29:19 +00:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, NSString, __unused RCTTextView)
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withWeight:json]; // defaults to normal
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
2016-08-05 19:29:19 +00:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSString, __unused RCTTextView)
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withStyle:json]; // defaults to normal
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTTextView)
|
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withFamily:json ?: defaultView.font.familyName];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
2015-07-21 19:37:24 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
|
2016-12-19 14:26:07 +00:00
|
|
|
|
|
|
|
#if !TARGET_OS_TV
|
2016-07-31 21:20:13 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, textView.dataDetectorTypes, UIDataDetectorTypes)
|
2016-12-19 14:26:07 +00:00
|
|
|
#endif
|
2015-04-29 08:29:00 +00:00
|
|
|
|
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
NSNumber *reactTag = shadowView.reactTag;
|
2017-05-29 22:56:46 +00:00
|
|
|
UIEdgeInsets borderAsInsets = shadowView.borderAsInsets;
|
|
|
|
UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets;
|
2015-11-14 18:25:00 +00:00
|
|
|
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTTextView *> *viewRegistry) {
|
2017-05-29 22:56:46 +00:00
|
|
|
viewRegistry[reactTag].reactBorderInsets = borderAsInsets;
|
|
|
|
viewRegistry[reactTag].reactPaddingInsets = paddingAsInsets;
|
2015-04-29 08:29:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|