mirror of
https://github.com/status-im/react-native.git
synced 2025-01-23 16:00:37 +00:00
610412385b
Summary: On iOS, it is not possible to select a range of text using a `Text` component (see #13938). Because of how the `Text` component is implemented on iOS, this will not work without a complete re-write. On Android however, this is not an issue. As the `TextInput` component has evolved, it can more or less be used as a drop-in replacement on iOS by setting `multiline={true}` and `editable={false}`. Except for one detail: the text input field has scrolling activated and it's not possible to turn off. (See #1391 and #15962). This pull request addresses that issue, simply by exposing the `scrollEnabled` property: ``` <TextInput multiline editable={false} scrollEnabled={false} /> ``` 1. Create a multiline `TextInput` component, with the attributes presented above. 2. Run on iOS 3. The `TextInput` field should not be able to scroll facebook/react-native-website#367 [IOS] [FEATURE] [TextInput] - Made it possible to turn off scrolling on a multiline TextInput component Pull Request resolved: https://github.com/facebook/react-native/pull/19330 Differential Revision: D9235061 Pulled By: hramos fbshipit-source-id: 99d278004fc236b47dde7e61d74c71e8a3b9d170
127 lines
4.7 KiB
Objective-C
127 lines
4.7 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTBaseTextInputViewManager.h"
|
|
|
|
#import <React/RCTAccessibilityManager.h>
|
|
#import <React/RCTBridge.h>
|
|
#import <React/RCTConvert.h>
|
|
#import <React/RCTFont.h>
|
|
#import <React/RCTShadowView+Layout.h>
|
|
#import <React/RCTShadowView.h>
|
|
#import <React/RCTUIManager.h>
|
|
#import <React/RCTUIManagerUtils.h>
|
|
#import <React/RCTUIManagerObserverCoordinator.h>
|
|
|
|
#import "RCTBaseTextInputShadowView.h"
|
|
#import "RCTBaseTextInputView.h"
|
|
#import "RCTConvert+Text.h"
|
|
|
|
@interface RCTBaseTextInputViewManager () <RCTUIManagerObserver>
|
|
|
|
@end
|
|
|
|
@implementation RCTBaseTextInputViewManager
|
|
{
|
|
NSHashTable<RCTBaseTextInputShadowView *> *_shadowViews;
|
|
}
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
#pragma mark - Unified <TextInput> properties
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
|
|
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
|
|
RCT_REMAP_VIEW_PROPERTY(contextMenuHidden, backedTextInputView.contextMenuHidden, BOOL)
|
|
RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL)
|
|
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL)
|
|
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance)
|
|
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
|
|
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
|
|
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
|
|
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
|
|
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
|
|
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
|
|
RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL)
|
|
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
|
|
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
|
|
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
|
|
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
|
|
RCT_EXPORT_VIEW_PROPERTY(inputAccessoryViewID, NSString)
|
|
RCT_EXPORT_VIEW_PROPERTY(textContentType, NSString)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
|
|
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
|
|
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
|
|
|
|
|
|
- (RCTShadowView *)shadowView
|
|
{
|
|
RCTBaseTextInputShadowView *shadowView = [[RCTBaseTextInputShadowView alloc] initWithBridge:self.bridge];
|
|
shadowView.textAttributes.fontSizeMultiplier = self.bridge.accessibilityManager.multiplier;
|
|
[_shadowViews addObject:shadowView];
|
|
return shadowView;
|
|
}
|
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
|
{
|
|
[super setBridge:bridge];
|
|
|
|
_shadowViews = [NSHashTable weakObjectsHashTable];
|
|
|
|
[bridge.uiManager.observerCoordinator addObserver:self];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(handleDidUpdateMultiplierNotification)
|
|
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
|
|
object:bridge.accessibilityManager];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
#pragma mark - RCTUIManagerObserver
|
|
|
|
- (void)uiManagerWillPerformMounting:(__unused RCTUIManager *)uiManager
|
|
{
|
|
for (RCTBaseTextInputShadowView *shadowView in _shadowViews) {
|
|
[shadowView uiManagerWillPerformMounting];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Font Size Multiplier
|
|
|
|
- (void)handleDidUpdateMultiplierNotification
|
|
{
|
|
CGFloat fontSizeMultiplier = self.bridge.accessibilityManager.multiplier;
|
|
|
|
NSHashTable<RCTBaseTextInputShadowView *> *shadowViews = _shadowViews;
|
|
RCTExecuteOnUIManagerQueue(^{
|
|
for (RCTBaseTextInputShadowView *shadowView in shadowViews) {
|
|
shadowView.textAttributes.fontSizeMultiplier = fontSizeMultiplier;
|
|
[shadowView dirtyLayout];
|
|
}
|
|
|
|
[self.bridge.uiManager setNeedsLayout];
|
|
});
|
|
}
|
|
|
|
@end
|