Skip to content

Commit dc40eec

Browse files
committed
draft implementation
1 parent dc9b82b commit dc40eec

19 files changed

Lines changed: 1202 additions & 1258 deletions

File tree

packages/react-native/Libraries/Components/TextInput/RCTTextInputViewConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const RCTTextInputViewConfig = {
162162
onChangeSync: true,
163163
onKeyPressSync: true,
164164
}),
165+
disableKeyboardShortcuts: true,
165166
},
166167
};
167168

packages/react-native/Libraries/Components/TextInput/TextInput.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export interface DocumentSelectionState extends EventEmitter {
136136
* @see https://reactnative.dev/docs/textinput#props
137137
*/
138138
export interface TextInputIOSProps {
139+
disableKeyboardShortcuts?: boolean | undefined;
140+
139141
/**
140142
* enum('never', 'while-editing', 'unless-editing', 'always')
141143
* When the clear button should appear on the right side of the text view

packages/react-native/Libraries/Components/TextInput/TextInput.flow.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export type enterKeyHintType =
216216
type PasswordRules = string;
217217

218218
type IOSProps = $ReadOnly<{|
219+
disableKeyboardShortcuts?: ?boolean,
220+
219221
/**
220222
* When the clear button should appear on the right side of the text view.
221223
* This property is supported only for single-line TextInput component.

packages/react-native/Libraries/Components/TextInput/TextInput.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ export type enterKeyHintType =
260260
type PasswordRules = string;
261261

262262
type IOSProps = $ReadOnly<{|
263+
disableKeyboardShortcuts?: ?boolean,
264+
263265
/**
264266
* When the clear button should appear on the right side of the text view.
265267
* This property is supported only for single-line TextInput component.
@@ -1290,6 +1292,7 @@ function InternalTextInput(props: Props): React.Node {
12901292
selectionColor,
12911293
selectionHandleColor,
12921294
cursorColor,
1295+
disableKeyboardShortcuts,
12931296
...otherProps
12941297
} = props;
12951298

@@ -1597,6 +1600,8 @@ function InternalTextInput(props: Props): React.Node {
15971600
flattenedStyle.paddingVertical == null &&
15981601
flattenedStyle.paddingTop == null));
15991602

1603+
console.debug('[dev] disableKeyboardShortcuts 2', disableKeyboardShortcuts);
1604+
16001605
textInput = (
16011606
<RCTTextInputView
16021607
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
@@ -1625,6 +1630,7 @@ function InternalTextInput(props: Props): React.Node {
16251630
_style,
16261631
)}
16271632
text={text}
1633+
disableKeyboardShortcuts={disableKeyboardShortcuts}
16281634
/>
16291635
);
16301636
} else if (Platform.OS === 'android') {
@@ -1813,12 +1819,15 @@ const ExportedForwardRef: component(
18131819
inputMode,
18141820
showSoftInputOnFocus,
18151821
keyboardType,
1822+
disableKeyboardShortcuts,
18161823
...restProps
18171824
},
18181825
forwardedRef: ReactRefSetter<TextInputInstance>,
18191826
) {
1827+
console.debug('[dev] disableKeyboardShortcuts', disableKeyboardShortcuts);
18201828
return (
18211829
<InternalTextInput
1830+
disableKeyboardShortcuts={disableKeyboardShortcuts}
18221831
allowFontScaling={allowFontScaling}
18231832
rejectResponderTermination={rejectResponderTermination}
18241833
underlineColorAndroid={underlineColorAndroid}

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
5252
// Use `attributedText.string` instead.
5353
@property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;
5454

55+
@property (nonatomic, assign) BOOL disableKeyboardShortcuts;
56+
5557
@end
5658

5759
NS_ASSUME_NONNULL_END

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
5252
@property (nonatomic, strong) NSString *inputAccessoryViewButtonLabel;
5353
@property (nonatomic, assign) UIKeyboardType keyboardType;
5454
@property (nonatomic, assign) BOOL showSoftInputOnFocus;
55+
@property (nonatomic, assign) BOOL disableKeyboardShortcuts;
5556

5657
/**
5758
Sets selection intext input if both start and end are within range of the text input.

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,4 +814,36 @@ static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange,
814814
return YES;
815815
}
816816

817+
BOOL _isFirstRender = YES;
818+
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
819+
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
820+
821+
- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
822+
{
823+
// Log the call to this method
824+
NSLog(@"RCTBaseTextInputView setDisableKeyboardShortcuts called with value: %d", disableKeyboardShortcuts);
825+
NSLog(@"RCTBaseTextInputView isFirstRender: %d", _isFirstRender);
826+
827+
// Initialize the initial values only once
828+
if (_isFirstRender) {
829+
_isFirstRender = NO;
830+
// Capture initial values of leading and trailing button groups
831+
_initialValueLeadingBarButtonGroups = self.backedTextInputView.inputView.inputAssistantItem.leadingBarButtonGroups;
832+
_initialValueTrailingBarButtonGroups = self.backedTextInputView.inputView.inputAssistantItem.trailingBarButtonGroups;
833+
}
834+
835+
// Optionally, log the initial values for verification
836+
NSLog(@"Initial Leading Bar Button Groups: %@", _initialValueLeadingBarButtonGroups);
837+
NSLog(@"Initial Trailing Bar Button Groups: %@", _initialValueTrailingBarButtonGroups);
838+
839+
if (disableKeyboardShortcuts) {
840+
self.backedTextInputView.inputView.inputAssistantItem.leadingBarButtonGroups = @[];
841+
self.backedTextInputView.inputView.inputAssistantItem.trailingBarButtonGroups = @[];
842+
} else {
843+
// Restore the initial values
844+
self.backedTextInputView.inputView.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
845+
self.backedTextInputView.inputView.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
846+
}
847+
}
848+
817849
@end

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ @implementation RCTBaseTextInputViewManager {
6969

7070
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
7171

72+
RCT_EXPORT_VIEW_PROPERTY(disableKeyboardShortcuts, BOOL)
73+
7274
RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
7375
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
7476
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTDirectEventBlock)

packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
3434
@property (nonatomic, assign, readonly) CGFloat zoomScale;
3535
@property (nonatomic, assign, readonly) CGPoint contentOffset;
3636
@property (nonatomic, assign, readonly) UIEdgeInsets contentInset;
37+
@property (nonatomic, assign) BOOL disableKeyboardShortcuts;
3738

3839
@end
3940

packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,45 @@ - (void)setSecureTextEntry:(BOOL)secureTextEntry
115115
self.attributedText = originalText;
116116
}
117117

118+
- (BOOL)disableKeyboardShortcuts
119+
{
120+
// Log the call to this method
121+
NSLog(@"RCTUITextField setDisableKeyboardShortcuts called with value: %d", self.disableKeyboardShortcuts);
122+
123+
return self.disableKeyboardShortcuts;
124+
}
125+
126+
BOOL isFirstRender = YES;
127+
NSArray<UIBarButtonItemGroup *> *initialValueLeadingBarButtonGroups;
128+
NSArray<UIBarButtonItemGroup *> *initialValueTrailingBarButtonGroups;
129+
130+
- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
131+
{
132+
// Log the call to this method
133+
NSLog(@"RCTUITextField setDisableKeyboardShortcuts called with value: %d", disableKeyboardShortcuts);
134+
NSLog(@"RCTBaseTextInputView isFirstRender: %d", isFirstRender);;
135+
136+
// Initialize the initial values only once
137+
if (isFirstRender) {
138+
isFirstRender = NO;
139+
// Capture initial values of leading and trailing button groups
140+
initialValueLeadingBarButtonGroups = self.inputAssistantItem.leadingBarButtonGroups;
141+
initialValueTrailingBarButtonGroups = self.inputAssistantItem.trailingBarButtonGroups;
142+
}
143+
144+
NSLog(@"Initial Leading Bar Button Groups: %@", initialValueLeadingBarButtonGroups);
145+
NSLog(@"Initial Trailing Bar Button Groups: %@", initialValueTrailingBarButtonGroups);
146+
147+
if (disableKeyboardShortcuts) {
148+
self.inputAssistantItem.leadingBarButtonGroups = @[];
149+
self.inputAssistantItem.trailingBarButtonGroups = @[];
150+
} else {
151+
// Restore the initial values
152+
self.inputAssistantItem.leadingBarButtonGroups = initialValueLeadingBarButtonGroups;
153+
self.inputAssistantItem.trailingBarButtonGroups = initialValueTrailingBarButtonGroups;
154+
}
155+
}
156+
118157
#pragma mark - Placeholder
119158

120159
- (NSDictionary<NSAttributedStringKey, id> *)_placeholderTextAttributes

0 commit comments

Comments
 (0)