Skip to content

Commit 8ace21f

Browse files
riteshshukla04react-native-bot
authored andcommitted
Fix: Setting maxLength to 0 in TextInput still allows typing on iOS (#52890)
Summary: Trying to fix #52860 ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS][FIXED] Setting maxLength to 0 in TextInput still allows typing on iOS Pull Request resolved: #52890 Test Plan: https://github.com/user-attachments/assets/56549e0f-6bbf-461e-815c-794abdee2018 Tested on Android too Rollback Plan: Reviewed By: cortinico Differential Revision: D80095701 Pulled By: cipolleschi fbshipit-source-id: 5e76f88798e32097e6a619c44ff6240b4f01fc6f
1 parent dffbfe6 commit 8ace21f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "RCTTextInputNativeCommands.h"
2323
#import "RCTTextInputUtils.h"
2424

25+
#import <limits>
2526
#import "RCTFabricComponentsPlugins.h"
2627

2728
/** Native iOS text field bottom keyboard offset amount */
@@ -447,7 +448,7 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
447448
}
448449
}
449450

450-
if (props.maxLength) {
451+
if (props.maxLength < std::numeric_limits<int>::max()) {
451452
NSInteger allowedLength = props.maxLength - _backedTextInputView.attributedText.string.length + range.length;
452453

453454
if (allowedLength > 0 && text.length > allowedLength) {

packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <react/renderer/components/view/ViewProps.h>
1414
#include <react/renderer/core/PropsParserContext.h>
1515
#include <react/renderer/graphics/Color.h>
16+
#include <limits>
1617
#include <string>
1718

1819
namespace facebook::react {
@@ -60,7 +61,7 @@ class BaseTextInputProps : public ViewProps, public BaseTextProps {
6061
// TODO: Rename to `tintColor` and make universal.
6162
SharedColor underlineColorAndroid{};
6263

63-
int maxLength{};
64+
int maxLength = std::numeric_limits<int>::max();
6465

6566
/*
6667
* "Private" (only used by TextInput.js) props

0 commit comments

Comments
 (0)