mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 17:45:59 +00:00
f0a3c56048
Summary: This adds support for a controlled `selection` prop on `TextInput` on iOS (Android PR coming soon). This is based on the work by ehd in #2668 which hasn't been updated for a while, kept the original commit and worked on fixing what was missing based on the feedback in the original PR. What I changed is: - Make the prop properly controlled by JS - Add a RCTTextSelection class to map the JS object into and the corresponding RCTConvert category - Make sure the selection change event is properly triggered when the input is focused - Cleanup setSelection - Changed TextInput to use function refs to appease the linter ** Test plan ** Tested using the TextInput selection example in UIExplorer on iOS. Also tested that it doesn't break Android. Closes https://github.com/facebook/react-native/pull/8958 Differential Revision: D3771229 Pulled By: javache fbshipit-source-id: b8ede46b97fb3faf3061bb2dac102160c4b20ce7
39 lines
883 B
Objective-C
39 lines
883 B
Objective-C
/**
|
|
* 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 "RCTTextSelection.h"
|
|
|
|
@implementation RCTTextSelection
|
|
|
|
- (instancetype)initWithStart:(NSInteger)start end:(NSInteger)end
|
|
{
|
|
if (self = [super init]) {
|
|
_start = start;
|
|
_end = end;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation RCTConvert (RCTTextSelection)
|
|
|
|
+ (RCTTextSelection *)RCTTextSelection:(id)json
|
|
{
|
|
if ([json isKindOfClass:[NSDictionary class]]) {
|
|
NSInteger start = [self NSInteger:json[@"start"]];
|
|
NSInteger end = [self NSInteger:json[@"end"]];
|
|
return [[RCTTextSelection alloc] initWithStart:start end:end];
|
|
}
|
|
|
|
return nil;
|
|
}
|
|
|
|
@end
|