keycard-exit/patches/react-native+0.75.3.patch

78 lines
3.9 KiB
Diff
Raw Permalink Normal View History

2024-10-29 03:28:36 +00:00
diff --git a/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm b/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm
index 9dca6a5..2dd3cd1 100644
--- a/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm
+++ b/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm
@@ -72,36 +72,50 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
[_backedTextInputView.textInputDelegate textInputDidEndEditing];
}
-- (BOOL)textField:(__unused UITextField *)textField
- shouldChangeCharactersInRange:(NSRange)range
- replacementString:(NSString *)string
-{
- NSString *newText = [_backedTextInputView.textInputDelegate textInputShouldChangeText:string inRange:range];
+- (BOOL)textField:(__unused UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
+ // Step 1: Handle secureTextEntry to avoid text clearing
+ if (textField.isSecureTextEntry) {
+ // Setting the new text to avoid the text clearing issue
+ NSString *updatedString = [textField.text stringByReplacingCharactersInRange:range withString:string];
+ textField.text = updatedString;
+
+ // Step 2: Set the cursor at the right place
+ NSRange selectedRange = NSMakeRange(range.location + string.length, 0);
+ UITextPosition* from = [textField positionFromPosition:textField.beginningOfDocument offset:selectedRange.location];
+ UITextPosition* to = [textField positionFromPosition:from offset:selectedRange.length];
+ textField.selectedTextRange = [textField textRangeFromPosition:from toPosition:to];
+
+ // Step 3: Send an action to notify of the change
+ [textField sendActionsForControlEvents:UIControlEventEditingChanged];
+
+ return NO;
+ }
- if (newText == nil) {
- return NO;
- }
+ // Step 4: Handle regular text entry to support swipe gestures
+ NSString *newText = [_backedTextInputView.textInputDelegate textInputShouldChangeText:string inRange:range];
+ if (newText == nil) {
+ return NO;
+ }
- if ([newText isEqualToString:string]) {
- _textDidChangeIsComing = YES;
- return YES;
- }
+ if ([newText isEqualToString:string]) {
+ _textDidChangeIsComing = YES;
+ return YES;
+ }
- NSMutableAttributedString *attributedString = [_backedTextInputView.attributedText mutableCopy];
- [attributedString replaceCharactersInRange:range withString:newText];
- [_backedTextInputView setAttributedText:[attributedString copy]];
+ NSMutableAttributedString *attributedString = [_backedTextInputView.attributedText mutableCopy];
+ [attributedString replaceCharactersInRange:range withString:newText];
+ [_backedTextInputView setAttributedText:[attributedString copy]];
- // Setting selection to the end of the replaced text.
- UITextPosition *position = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
- offset:(range.location + newText.length)];
- [_backedTextInputView setSelectedTextRange:[_backedTextInputView textRangeFromPosition:position toPosition:position]
- notifyDelegate:YES];
+ // Setting selection to the end of the replaced text.
+ UITextPosition *position = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument offset:(range.location + newText.length)];
+ [_backedTextInputView setSelectedTextRange:[_backedTextInputView textRangeFromPosition:position toPosition:position] notifyDelegate:YES];
- [self textFieldDidChange];
+ [self textFieldDidChange];
- return NO;
+ return NO;
}
+
- (BOOL)textFieldShouldReturn:(__unused UITextField *)textField
{
// Ignore the value of whether we submitted; just make sure the submit event is called if necessary.