mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix: Setting maxLength to 0 in TextInput still allows typing on iOS (#52890)
Summary: Trying to fix https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
568f59e5b1
commit
c5956da8c0
+2
-1
@@ -22,6 +22,7 @@
|
||||
#import "RCTTextInputNativeCommands.h"
|
||||
#import "RCTTextInputUtils.h"
|
||||
|
||||
#import <limits>
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
|
||||
/** Native iOS text field bottom keyboard offset amount */
|
||||
@@ -450,7 +451,7 @@ static NSSet<NSNumber *> *returnKeyTypesSet;
|
||||
}
|
||||
}
|
||||
|
||||
if (props.maxLength) {
|
||||
if (props.maxLength < std::numeric_limits<int>::max()) {
|
||||
NSInteger allowedLength = props.maxLength - _backedTextInputView.attributedText.string.length + range.length;
|
||||
|
||||
if (allowedLength > 0 && text.length > allowedLength) {
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
#include <react/renderer/components/view/ViewProps.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -60,7 +61,7 @@ class BaseTextInputProps : public ViewProps, public BaseTextProps {
|
||||
// TODO: Rename to `tintColor` and make universal.
|
||||
SharedColor underlineColorAndroid{};
|
||||
|
||||
int maxLength{};
|
||||
int maxLength = std::numeric_limits<int>::max();
|
||||
|
||||
/*
|
||||
* "Private" (only used by TextInput.js) props
|
||||
|
||||
Reference in New Issue
Block a user