mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-07 02:08:34 +08:00
Add TextInput controlled selection prop on iOS
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
This commit is contained in:
committed by
Facebook Github Bot 5
parent
c40fee9405
commit
f0a3c56048
28
Libraries/Text/RCTTextSelection.h
Normal file
28
Libraries/Text/RCTTextSelection.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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 "RCTConvert.h"
|
||||
|
||||
/**
|
||||
* Object containing information about a TextInput's selection.
|
||||
*/
|
||||
@interface RCTTextSelection : NSObject
|
||||
|
||||
@property (nonatomic, assign, readonly) NSInteger start;
|
||||
@property (nonatomic, assign, readonly) NSInteger end;
|
||||
|
||||
- (instancetype)initWithStart:(NSInteger)start end:(NSInteger)end;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTConvert (RCTTextSelection)
|
||||
|
||||
+ (RCTTextSelection *)RCTTextSelection:(id)json;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user