Skip to content

Commit c14f233

Browse files
committed
Apply changes from PR#40
1 parent 98bee83 commit c14f233

File tree

13 files changed

+101
-0
lines changed

13 files changed

+101
-0
lines changed

Libraries/Components/TextInput/RCTTextInputViewConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const RCTTextInputViewConfig = {
150150
showSoftInputOnFocus: true,
151151
autoFocus: true,
152152
lineBreakStrategyIOS: true,
153+
smartInsertDelete: true,
153154
...ConditionallyIgnoredEventHandlers({
154155
onChange: true,
155156
onSelectionChange: true,

Libraries/Components/TextInput/TextInput.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ export interface TextInputIOSProps {
272272
* If false, scrolling of the text view will be disabled. The default value is true. Only works with multiline={true}
273273
*/
274274
scrollEnabled?: boolean | undefined;
275+
276+
/**
277+
* If `false`, the iOS system will not insert an extra space after a paste operation
278+
* neither delete one or two spaces after a cut or delete operation.
279+
*
280+
* The default value is `true`.
281+
*/
282+
smartInsertDelete?: boolean | undefined;
275283
}
276284

277285
/**

Libraries/Components/TextInput/TextInput.flow.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ type IOSProps = $ReadOnly<{|
325325
* @platform ios
326326
*/
327327
lineBreakStrategyIOS?: ?('none' | 'standard' | 'hangul-word' | 'push-out'),
328+
329+
/**
330+
* If `false`, the iOS system will not insert an extra space after a paste operation
331+
* neither delete one or two spaces after a cut or delete operation.
332+
*
333+
* The default value is `true`.
334+
*
335+
* @platform ios
336+
*/
337+
smartInsertDelete?: ?boolean,
328338
|}>;
329339

330340
type AndroidProps = $ReadOnly<{|

Libraries/Components/TextInput/TextInput.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ type IOSProps = $ReadOnly<{|
358358
* @platform ios
359359
*/
360360
lineBreakStrategyIOS?: ?('none' | 'standard' | 'hangul-word' | 'push-out'),
361+
362+
/**
363+
* If `false`, the iOS system will not insert an extra space after a paste operation
364+
* neither delete one or two spaces after a cut or delete operation.
365+
*
366+
* The default value is `true`.
367+
*
368+
* @platform ios
369+
*/
370+
smartInsertDelete?: ?boolean,
361371
|}>;
362372

363373
type AndroidProps = $ReadOnly<{|

Libraries/Text/RCTConvert+Text.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
1616
+ (UITextAutocorrectionType)UITextAutocorrectionType:(nullable id)json;
1717
+ (UITextSpellCheckingType)UITextSpellCheckingType:(nullable id)json;
1818
+ (RCTTextTransform)RCTTextTransform:(nullable id)json;
19+
+ (UITextSmartInsertDeleteType)UITextSmartInsertDeleteType:(nullable id)json;
1920

2021
@end
2122

Libraries/Text/RCTConvert+Text.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ + (UITextSpellCheckingType)UITextSpellCheckingType:(id)json
3434
RCTTextTransformUndefined,
3535
integerValue)
3636

37+
+ (UITextSmartInsertDeleteType)UITextSmartInsertDeleteType:(id)json
38+
{
39+
return json == nil ? UITextSmartInsertDeleteTypeDefault
40+
: [RCTConvert BOOL:json] ? UITextSmartInsertDeleteTypeYes
41+
: UITextSmartInsertDeleteTypeNo;
42+
}
43+
3744
@end

Libraries/Text/TextInput/RCTBaseTextInputViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ @implementation RCTBaseTextInputViewManager {
4747
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
4848
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
4949
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
50+
RCT_REMAP_VIEW_PROPERTY(smartInsertDelete, backedTextInputView.smartInsertDeleteType, UITextSmartInsertDeleteType)
5051
RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL)
5152
RCT_EXPORT_VIEW_PROPERTY(submitBehavior, NSString)
5253
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)

React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
185185
}
186186
}
187187

188+
/*
189+
* When updating component's props, we compare if the new value is different from the old one.
190+
* If it is different, we update the native view with the new value.
191+
*
192+
* `RCTUITextSmartInsertDeleteTypeFromOptionalBool` is used to convert the boolean value coming
193+
* from JS side to the appropriate `UITextSmartInsertDeleteType` value, that is required for
194+
* this `smartInsertDeleteType` attribute.
195+
*/
196+
if (newTextInputProps.traits.smartInsertDelete != oldTextInputProps.traits.smartInsertDelete) {
197+
if (@available(iOS 11.0, *)) {
198+
_backedTextInputView.smartInsertDeleteType =
199+
RCTUITextSmartInsertDeleteTypeFromOptionalBool(newTextInputProps.traits.smartInsertDelete);
200+
}
201+
}
202+
188203
// Traits `blurOnSubmit`, `clearTextOnFocus`, and `selectTextOnFocus` were omitted intentially here
189204
// because they are being checked on-demand.
190205

React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType)
4141
API_AVAILABLE(ios(12.0))
4242
UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(std::string const &passwordRules);
4343

44+
API_AVAILABLE(ios(11.0))
45+
UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional<bool> smartInsertDelete);
46+
4447
NS_ASSUME_NONNULL_END

React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void RCTCopyBackedTextInput(
4444
toTextInput.keyboardType = fromTextInput.keyboardType;
4545
toTextInput.textContentType = fromTextInput.textContentType;
4646

47+
if (@available(iOS 11.0, *)) {
48+
toTextInput.smartInsertDeleteType = fromTextInput.smartInsertDeleteType;
49+
}
50+
4751
if (@available(iOS 12.0, *)) {
4852
toTextInput.passwordRules = fromTextInput.passwordRules;
4953
}
@@ -232,3 +236,10 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType)
232236
{
233237
return [UITextInputPasswordRules passwordRulesWithDescriptor:RCTNSStringFromStringNilIfEmpty(passwordRules)];
234238
}
239+
240+
API_AVAILABLE(ios(11.0))
241+
UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional<bool> smartInsertDelete)
242+
{
243+
return smartInsertDelete.has_value() ? (*smartInsertDelete ? UITextSmartInsertDeleteTypeYes : UITextSmartInsertDeleteTypeNo)
244+
: UITextSmartInsertDeleteTypeDefault;
245+
}

0 commit comments

Comments
 (0)