2015-03-23 13:28:42 -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.
|
|
|
|
*/
|
2015-02-19 20:10:52 -08:00
|
|
|
|
|
|
|
#import "RCTTextFieldManager.h"
|
|
|
|
|
2016-11-23 07:47:52 -08:00
|
|
|
#import <React/RCTBridge.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 "RCTShadowTextField.h"
|
2017-01-30 15:36:57 -08:00
|
|
|
#import "RCTTextField.h"
|
2017-05-29 15:56:47 -07:00
|
|
|
#import "RCTUITextField.h"
|
2015-08-06 09:53:20 -07:00
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
@implementation RCTTextFieldManager
|
|
|
|
|
2015-04-08 05:42:43 -07:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2017-03-13 13:31:35 -07:00
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [RCTShadowTextField new];
|
|
|
|
}
|
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
2017-05-29 15:56:38 -07:00
|
|
|
return [[RCTTextField alloc] initWithBridge:self.bridge];
|
2015-11-04 21:01:49 -08:00
|
|
|
}
|
|
|
|
|
2017-05-29 15:56:47 -07:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(caretHidden, textField.caretHidden, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(autoCorrect, textField.autocorrectionType, UITextAutocorrectionType)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(spellCheck, textField.spellCheckingType, UITextSpellCheckingType)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(editable, textField.enabled, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(placeholder, textField.placeholder, NSString)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, textField.placeholderColor, UIColor)
|
2016-08-25 17:18:05 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
|
2015-03-25 21:29:28 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
|
2015-07-21 12:37:24 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
|
2017-05-29 15:56:47 -07:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, textField.clearButtonMode, UITextFieldViewMode)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(clearTextOnFocus, textField.clearsOnBeginEditing, BOOL)
|
2015-04-14 17:51:28 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
|
2015-11-04 21:01:49 -08:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
|
2017-05-29 15:56:47 -07:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(keyboardType, textField.keyboardType, UIKeyboardType)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, textField.keyboardAppearance, UIKeyboardAppearance)
|
2015-11-14 09:41:59 -08:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
2017-05-29 15:56:47 -07:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(returnKeyType, textField.returnKeyType, UIReturnKeyType)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, textField.enablesReturnKeyAutomatically, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, textField.secureTextEntry, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(password, textField.secureTextEntry, BOOL) // backwards compatibility
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(color, textField.textColor, UIColor)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textField.autocapitalizationType, UITextAutocapitalizationType)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(textAlign, textField.textAlignment, NSTextAlignment)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(selectionColor, textField.tintColor, UIColor)
|
2016-08-05 12:29:21 -07:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextField)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2017-05-29 15:56:47 -07:00
|
|
|
view.textField.font = [RCTFont updateFont:view.textField.font withSize:json ?: @(defaultView.textField.font.pointSize)];
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2015-06-15 07:53:45 -07:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, NSString, __unused RCTTextField)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2017-05-29 15:56:47 -07:00
|
|
|
view.textField.font = [RCTFont updateFont:view.textField.font withWeight:json]; // defaults to normal
|
2015-03-25 16:22:59 -07:00
|
|
|
}
|
2015-06-15 07:53:45 -07:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSString, __unused RCTTextField)
|
2015-03-25 16:22:59 -07:00
|
|
|
{
|
2017-05-29 15:56:47 -07:00
|
|
|
view.textField.font = [RCTFont updateFont:view.textField.font withStyle:json]; // defaults to normal
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2015-03-25 21:29:28 -07:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTTextField)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2017-05-29 15:56:47 -07:00
|
|
|
view.textField.font = [RCTFont updateFont:view.textField.font withFamily:json ?: defaultView.textField.font.familyName];
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2015-07-21 12:37:24 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2015-03-01 15:33:55 -08:00
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
NSNumber *reactTag = shadowView.reactTag;
|
2017-05-29 15:56:42 -07:00
|
|
|
UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets;
|
|
|
|
UIEdgeInsets borderAsInsets = shadowView.borderAsInsets;
|
2015-11-14 10:25:00 -08:00
|
|
|
return ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTTextField *> *viewRegistry) {
|
2017-05-29 15:56:42 -07:00
|
|
|
RCTTextField *textField = viewRegistry[reactTag];
|
|
|
|
textField.reactPaddingInsets = paddingAsInsets;
|
|
|
|
textField.reactBorderInsets = borderAsInsets;
|
2015-03-01 15:33:55 -08:00
|
|
|
};
|
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
|
|
|
@end
|