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