Skip to content

Commit c45e878

Browse files
committed
draft
1 parent 2a599fa commit c45e878

11 files changed

Lines changed: 172 additions & 173 deletions

File tree

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
* If `true`, disabled the native keyboard shortcuts.
141143
* @platform ios

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
* If `true`, disabled the native keyboard shortcuts.
221223
* @platform ios

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

Lines changed: 10 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
* If `true`, disabled the native keyboard shortcuts.
265267
* @platform ios
@@ -1290,6 +1292,7 @@ function InternalTextInput(props: Props): React.Node {
12901292
selectionColor,
12911293
selectionHandleColor,
12921294
cursorColor,
1295+
disableKeyboardShortcuts,
12931296
...otherProps
12941297
} = props;
12951298

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

1603+
console.debug('[dev] disableKeyboardShortcuts 2', disableKeyboardShortcuts);
1604+
console.debug('[dev] props.multiline', props.multiline);
1605+
16001606
textInput = (
16011607
<RCTTextInputView
16021608
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
16031609
ref={ref}
16041610
{...otherProps}
16051611
{...eventHandlers}
1612+
disableKeyboardShortcuts={disableKeyboardShortcuts}
16061613
accessibilityState={_accessibilityState}
16071614
accessible={accessible}
16081615
submitBehavior={submitBehavior}
@@ -1813,11 +1820,13 @@ const ExportedForwardRef: component(
18131820
inputMode,
18141821
showSoftInputOnFocus,
18151822
keyboardType,
1823+
disableKeyboardShortcuts,
18161824
...restProps
18171825
},
18181826
forwardedRef: ReactRefSetter<TextInputInstance>,
18191827
) {
18201828
console.debug('[dev] restProps', restProps);
1829+
console.debug('[dev] disableKeyboardShortcuts', disableKeyboardShortcuts);
18211830

18221831
return (
18231832
<InternalTextInput
@@ -1853,6 +1862,7 @@ const ExportedForwardRef: component(
18531862
autoCompleteWebToTextContentTypeMap[autoComplete]
18541863
: textContentType
18551864
}
1865+
disableKeyboardShortcuts={disableKeyboardShortcuts}
18561866
{...restProps}
18571867
forwardedRef={forwardedRef}
18581868
/>

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, readonly) UITextInputAssistantItem *inputAssistantItem;
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
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
5151
@property (nonatomic, copy) NSString *inputAccessoryViewID;
5252
@property (nonatomic, assign) UIKeyboardType keyboardType;
5353
@property (nonatomic, assign) BOOL showSoftInputOnFocus;
54+
@property (nonatomic, assign) BOOL disableKeyboardShortcuts;
5455

5556
/**
5657
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
@@ -350,12 +350,14 @@ - (void)setPasswordRules:(NSString *)descriptor
350350

351351
- (UIKeyboardType)keyboardType
352352
{
353+
NSLog(@"setKeyboardType called with value: %ld", self.backedTextInputView.keyboardType);
353354
return self.backedTextInputView.keyboardType;
354355
}
355356

356357
- (void)setKeyboardType:(UIKeyboardType)keyboardType
357358
{
358359
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;
360+
NSLog(@"setKeyboardType called with value: %ld", keyboardType);
359361
if (textInputView.keyboardType != keyboardType) {
360362
textInputView.keyboardType = keyboardType;
361363
// Without the call to reloadInputViews, the keyboard will not change until the textview field (the first responder)
@@ -637,6 +639,18 @@ - (void)didMoveToWindow
637639
[self.backedTextInputView reactFocusIfNeeded];
638640
}
639641

642+
NSLog(@"backedTextInputView: %@", self.backedTextInputView);
643+
644+
// Apply keyboard shortcuts setting when view becomes active
645+
if (_disableKeyboardShortcuts && self.backedTextInputView.isFirstResponder) {
646+
UITextInputAssistantItem *inputAssistantItem = self.backedTextInputView.inputAssistantItem;
647+
if (inputAssistantItem) {
648+
inputAssistantItem.leadingBarButtonGroups = @[];
649+
inputAssistantItem.trailingBarButtonGroups = @[];
650+
}
651+
[self.backedTextInputView reloadInputViews];
652+
}
653+
640654
_didMoveToWindow = YES;
641655
}
642656

@@ -801,4 +815,22 @@ static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange,
801815
return YES;
802816
}
803817

818+
- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts {
819+
_disableKeyboardShortcuts = disableKeyboardShortcuts;
820+
NSLog(@"setDisableKeyboardShortcuts called with value: %d", disableKeyboardShortcuts);
821+
822+
id<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
823+
NSLog(@"backedTextInputView: %@", backedTextInputView);
824+
825+
826+
if (disableKeyboardShortcuts) {
827+
UITextInputAssistantItem *inputAssistantItem = backedTextInputView.inputAssistantItem;
828+
if (inputAssistantItem) {
829+
inputAssistantItem.leadingBarButtonGroups = @[];
830+
inputAssistantItem.trailingBarButtonGroups = @[];
831+
}
832+
}
833+
834+
}
835+
804836
@end

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

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

9090
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
9191

92+
RCT_EXPORT_VIEW_PROPERTY(disableKeyboardShortcuts, BOOL)
93+
9294
RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
9395
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
9496
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTDirectEventBlock)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ BaseTextInputProps::BaseTextInputProps(
126126
rawProps,
127127
"multiline",
128128
sourceProps.multiline,
129+
{false})),
130+
disableKeyboardShortcuts(convertRawProp(
131+
context,
132+
rawProps,
133+
"disableKeyboardShortcuts",
134+
sourceProps.disableKeyboardShortcuts,
129135
{false})) {}
130136

131137
void BaseTextInputProps::setProp(
@@ -208,6 +214,7 @@ void BaseTextInputProps::setProp(
208214
RAW_SET_PROP_SWITCH_CASE_BASIC(readOnly);
209215
RAW_SET_PROP_SWITCH_CASE_BASIC(submitBehavior);
210216
RAW_SET_PROP_SWITCH_CASE_BASIC(multiline);
217+
RAW_SET_PROP_SWITCH_CASE_BASIC(disableKeyboardShortcuts);
211218
}
212219
}
213220

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class BaseTextInputProps : public ViewProps, public BaseTextProps {
7171
SubmitBehavior submitBehavior{SubmitBehavior::Default};
7272

7373
bool multiline{false};
74+
bool disableKeyboardShortcuts{};
7475

7576
SubmitBehavior getNonDefaultSubmitBehavior() const;
7677
};

packages/rn-tester/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
def pods(target_name, options = {})
3636
project 'RNTesterPods.xcodeproj'
3737

38-
fabric_enabled = true
38+
fabric_enabled = false
3939

4040
# Hermes is now enabled by default.
4141
# The following line will only disable Hermes if the USE_HERMES envvar is SET to a value other than 1 (e.g. USE_HERMES=0).

0 commit comments

Comments
 (0)