Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dc9b82b
Revert "fix(iOS): unify prefetchImageWithMetadata's signature in JS a…
rezkiy37 Nov 18, 2024
dc40eec
draft implementation
rezkiy37 Nov 18, 2024
7fad1ea
support both arch
rezkiy37 Nov 19, 2024
7f622ed
support multiline
rezkiy37 Nov 19, 2024
1f8aa92
prettify
rezkiy37 Nov 19, 2024
7389209
Revert "support multiline"
rezkiy37 Nov 19, 2024
46e3910
Revert "prettify"
rezkiy37 Nov 19, 2024
fd33efd
Revert "Revert "support multiline""
rezkiy37 Nov 19, 2024
daf99b8
fix duplicated methods
rezkiy37 Nov 19, 2024
c95694a
add playground text input cases
rezkiy37 Nov 19, 2024
af04bfe
improve JS side
rezkiy37 Nov 19, 2024
b774937
prettify and clean
rezkiy37 Nov 19, 2024
712d65d
clean Podfile
rezkiy37 Nov 19, 2024
75b03f9
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Nov 19, 2024
c6a3e9d
revert lock files
rezkiy37 Nov 19, 2024
5628edb
revert lock files
rezkiy37 Nov 19, 2024
d06e0e2
revert lock files
rezkiy37 Nov 19, 2024
1345ecf
add more test cases
rezkiy37 Nov 19, 2024
5041880
add native default values
rezkiy37 Nov 19, 2024
75c39a6
clean console logs
rezkiy37 Nov 19, 2024
210ba70
unique value for each input instance
rezkiy37 Nov 19, 2024
7608350
do not redefine
rezkiy37 Nov 19, 2024
b1f7bdf
clean console logs
rezkiy37 Nov 19, 2024
60e0ea3
add examples
rezkiy37 Nov 19, 2024
a064331
clear playground
rezkiy37 Nov 19, 2024
aa3fbca
store values privately for new arch
rezkiy37 Nov 20, 2024
374a7b5
store values privately for old arch
rezkiy37 Nov 20, 2024
358bff7
move method
rezkiy37 Nov 20, 2024
5f194a8
add platform ios description
rezkiy37 Nov 20, 2024
fd0e5fe
move examples upper
rezkiy37 Nov 20, 2024
35fcdc3
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Dec 9, 2024
5d583c5
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Dec 12, 2024
2bfefaf
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Dec 17, 2024
a9cdc5a
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Dec 19, 2024
9e22ee0
update public api snapshot
rezkiy37 Dec 19, 2024
ba91a00
Merge branch 'main' of https://github.com/facebook/react-native into …
rezkiy37 Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const RCTTextInputViewConfig = {
onChangeSync: true,
onKeyPressSync: true,
}),
disableKeyboardShortcuts: true,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ export interface DocumentSelectionState extends EventEmitter {
* @see https://reactnative.dev/docs/textinput#props
*/
export interface TextInputIOSProps {
/**
* If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
*/
disableKeyboardShortcuts?: boolean | undefined;

/**
* enum('never', 'while-editing', 'unless-editing', 'always')
* When the clear button should appear on the right side of the text view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ export type enterKeyHintType =
type PasswordRules = string;

type IOSProps = $ReadOnly<{|
/**
* If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
* @platform ios
*/
disableKeyboardShortcuts?: ?boolean,

/**
* When the clear button should appear on the right side of the text view.
* This property is supported only for single-line TextInput component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ export type enterKeyHintType =
type PasswordRules = string;

type IOSProps = $ReadOnly<{|
/**
* If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
* @platform ios
*/
disableKeyboardShortcuts?: ?boolean,

/**
* When the clear button should appear on the right side of the text view.
* This property is supported only for single-line TextInput component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, nullable) NSString *inputAccessoryViewID;
@property (nonatomic, strong, nullable) NSString *inputAccessoryViewButtonLabel;

@property (nonatomic, assign) BOOL disableKeyboardShortcuts;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ @implementation RCTUITextView {
UITextView *_detachedTextView;
RCTBackedTextViewDelegateAdapter *_textInputDelegateAdapter;
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
}

static UIFont *defaultPlaceholderFont(void)
Expand Down Expand Up @@ -52,6 +54,8 @@ - (instancetype)initWithFrame:(CGRect)frame
self.textContainer.lineFragmentPadding = 0;
self.scrollsToTop = NO;
self.scrollEnabled = YES;
_initialValueLeadingBarButtonGroups = nil;
_initialValueTrailingBarButtonGroups = nil;
}

return self;
Expand Down Expand Up @@ -132,6 +136,25 @@ - (void)textDidChange
[self _invalidatePlaceholderVisibility];
}

- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
{
// Initialize the initial values only once
if (_initialValueLeadingBarButtonGroups == nil) {
// Capture initial values of leading and trailing button groups
_initialValueLeadingBarButtonGroups = self.inputAssistantItem.leadingBarButtonGroups;
_initialValueTrailingBarButtonGroups = self.inputAssistantItem.trailingBarButtonGroups;
}

if (disableKeyboardShortcuts) {
self.inputAssistantItem.leadingBarButtonGroups = @[];
self.inputAssistantItem.trailingBarButtonGroups = @[];
} else {
// Restore the initial values
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
}
}

#pragma mark - Overrides

- (void)setFont:(UIFont *)font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
// Use `attributedText.string` instead.
@property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;

@property (nonatomic, assign) BOOL disableKeyboardShortcuts;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ @implementation RCTBaseTextInputView {
BOOL _hasInputAccessoryView;
NSString *_Nullable _predictedText;
BOOL _didMoveToWindow;
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
}

- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
Expand Down Expand Up @@ -65,6 +67,8 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_bridge = bridge;
_eventDispatcher = bridge.eventDispatcher;
[self initializeReturnKeyType];
_initialValueLeadingBarButtonGroups = nil;
_initialValueTrailingBarButtonGroups = nil;
}

return self;
Expand Down Expand Up @@ -394,6 +398,25 @@ - (void)setInputAccessoryViewButtonLabel:(NSString *)inputAccessoryViewButtonLab
self.backedTextInputView.inputAccessoryViewButtonLabel = inputAccessoryViewButtonLabel;
}

- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
{
// Initialize the initial values only once
if (_initialValueLeadingBarButtonGroups == nil) {
// Capture initial values of leading and trailing button groups
_initialValueLeadingBarButtonGroups = self.backedTextInputView.inputAssistantItem.leadingBarButtonGroups;
_initialValueTrailingBarButtonGroups = self.backedTextInputView.inputAssistantItem.trailingBarButtonGroups;
}

if (disableKeyboardShortcuts) {
self.backedTextInputView.inputAssistantItem.leadingBarButtonGroups = @[];
self.backedTextInputView.inputAssistantItem.trailingBarButtonGroups = @[];
}else {
// Restore the initial values
self.backedTextInputView.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
self.backedTextInputView.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
}
}

#pragma mark - RCTBackedTextInputDelegate

- (BOOL)textInputShouldBeginEditing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ @implementation RCTBaseTextInputViewManager {

RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)

RCT_EXPORT_VIEW_PROPERTY(disableKeyboardShortcuts, BOOL)

RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTDirectEventBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, readonly) CGFloat zoomScale;
@property (nonatomic, assign, readonly) CGPoint contentOffset;
@property (nonatomic, assign, readonly) UIEdgeInsets contentInset;
@property (nonatomic, assign) BOOL disableKeyboardShortcuts;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@implementation RCTUITextField {
RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter;
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
}

- (instancetype)initWithFrame:(CGRect)frame
Expand All @@ -27,6 +29,8 @@ - (instancetype)initWithFrame:(CGRect)frame

_textInputDelegateAdapter = [[RCTBackedTextFieldDelegateAdapter alloc] initWithTextField:self];
_scrollEnabled = YES;
_initialValueLeadingBarButtonGroups = nil;
_initialValueTrailingBarButtonGroups = nil;
}

return self;
Expand Down Expand Up @@ -115,6 +119,25 @@ - (void)setSecureTextEntry:(BOOL)secureTextEntry
self.attributedText = originalText;
}

- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
{
// Initialize the initial values only once
if (_initialValueLeadingBarButtonGroups == nil) {
// Capture initial values of leading and trailing button groups
_initialValueLeadingBarButtonGroups = self.inputAssistantItem.leadingBarButtonGroups;
_initialValueTrailingBarButtonGroups = self.inputAssistantItem.trailingBarButtonGroups;
}

if (disableKeyboardShortcuts) {
self.inputAssistantItem.leadingBarButtonGroups = @[];
self.inputAssistantItem.trailingBarButtonGroups = @[];
} else {
// Restore the initial values
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
}
}

#pragma mark - Placeholder

- (NSDictionary<NSAttributedStringKey, id> *)_placeholderTextAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,7 @@ export type enterKeyHintType =
| \\"send\\";
type PasswordRules = string;
type IOSProps = $ReadOnly<{|
disableKeyboardShortcuts?: ?boolean,
clearButtonMode?: ?(\\"never\\" | \\"while-editing\\" | \\"unless-editing\\" | \\"always\\"),
clearTextOnFocus?: ?boolean,
dataDetectorTypes?:
Expand Down Expand Up @@ -3379,6 +3380,7 @@ export type enterKeyHintType =
| \\"enter\\";
type PasswordRules = string;
type IOSProps = $ReadOnly<{|
disableKeyboardShortcuts?: ?boolean,
clearButtonMode?: ?(\\"never\\" | \\"while-editing\\" | \\"unless-editing\\" | \\"always\\"),
clearTextOnFocus?: ?boolean,
dataDetectorTypes?:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_backedTextInputView.inputAccessoryViewButtonLabel =
RCTNSStringFromString(newTextInputProps.inputAccessoryViewButtonLabel);
}

if (newTextInputProps.disableKeyboardShortcuts != oldTextInputProps.disableKeyboardShortcuts) {
_backedTextInputView.disableKeyboardShortcuts = newTextInputProps.disableKeyboardShortcuts;
}

[super updateProps:props oldProps:oldProps];

[self setDefaultInputAccessoryView];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void RCTCopyBackedTextInput(
toTextInput.textContentType = fromTextInput.textContentType;
toTextInput.smartInsertDeleteType = fromTextInput.smartInsertDeleteType;
toTextInput.passwordRules = fromTextInput.passwordRules;
toTextInput.disableKeyboardShortcuts = fromTextInput.disableKeyboardShortcuts;

[toTextInput setSelectedTextRange:fromTextInput.selectedTextRange notifyDelegate:NO];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ BaseTextInputProps::BaseTextInputProps(
rawProps,
"multiline",
sourceProps.multiline,
{false})),
disableKeyboardShortcuts(convertRawProp(
context,
rawProps,
"disableKeyboardShortcuts",
sourceProps.disableKeyboardShortcuts,
{false})) {}

void BaseTextInputProps::setProp(
Expand Down Expand Up @@ -208,6 +214,7 @@ void BaseTextInputProps::setProp(
RAW_SET_PROP_SWITCH_CASE_BASIC(readOnly);
RAW_SET_PROP_SWITCH_CASE_BASIC(submitBehavior);
RAW_SET_PROP_SWITCH_CASE_BASIC(multiline);
RAW_SET_PROP_SWITCH_CASE_BASIC(disableKeyboardShortcuts);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class BaseTextInputProps : public ViewProps, public BaseTextProps {
SubmitBehavior submitBehavior{SubmitBehavior::Default};

bool multiline{false};

bool disableKeyboardShortcuts{false};
};

} // namespace facebook::react
73 changes: 73 additions & 0 deletions packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,73 @@ const TextInputWithFocusButton = () => {
);
};

function KeyboardShortcutsExample() {
return (
<View>
<Text
style={{
marginBottom: 4,
}}>
Single line:
</Text>

<ExampleTextInput
style={{
marginBottom: 4,
}}
placeholder="Default"
/>

<ExampleTextInput
style={{
marginBottom: 4,
}}
placeholder="Disable keyboard shortcuts"
disableKeyboardShortcuts
/>

<ExampleTextInput
style={{
marginBottom: 4,
}}
placeholder="Hidden keyboard with suggestions"
showSoftInputOnFocus={false}
/>

<ExampleTextInput
style={{
marginBottom: 4,
}}
placeholder="Hidden keyboard without suggestions"
disableKeyboardShortcuts
autoCorrect={false}
spellCheck={false}
showSoftInputOnFocus={false}
/>

<Text
style={{
marginBottom: 4,
}}>
Multiline:
</Text>

<ExampleTextInput
style={styles.multiline}
multiline
placeholder="default"
/>

<ExampleTextInput
style={styles.multiline}
multiline
placeholder="Disable keyboard shortcuts"
disableKeyboardShortcuts
/>
</View>
);
}

const styles = StyleSheet.create({
multiline: {
height: 50,
Expand Down Expand Up @@ -938,6 +1005,12 @@ const textInputExamples: Array<RNTesterModuleExample> = [
return <TextInputWithFocusButton />;
},
},
{
title: 'Keyboard shortcuts',
render: function (): React.Node {
return <KeyboardShortcutsExample />;
},
},
{
title: 'Line Break Mode',
render: function (): React.Node {
Expand Down