Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN

#if !TARGET_OS_OSX // TODO(macOS GH#774)
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
@protocol RCTBackedTextInputViewProtocol <UITextInput>
#else // [TODO(macOS GH#774)
#else
@protocol RCTBackedTextInputViewProtocol
#endif // ]TODO(macOS GH#774)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
[self _setMultiline:newTextInputProps.traits.multiline];
}


#if !TARGET_OS_OSX // [TODO(macOS GH#774)
if (newTextInputProps.traits.autocapitalizationType != oldTextInputProps.traits.autocapitalizationType) {
_backedTextInputView.autocapitalizationType =
RCTUITextAutocapitalizationTypeFromAutocapitalizationType(newTextInputProps.traits.autocapitalizationType);
Expand All @@ -125,6 +127,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_backedTextInputView.autocorrectionType =
RCTUITextAutocorrectionTypeFromOptionalBool(newTextInputProps.traits.autoCorrect);
}
#endif // ]TODO(macOS GH#774)

if (newTextInputProps.traits.contextMenuHidden != oldTextInputProps.traits.contextMenuHidden) {
_backedTextInputView.contextMenuHidden = newTextInputProps.traits.contextMenuHidden;
Expand All @@ -139,6 +142,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_backedTextInputView.enablesReturnKeyAutomatically = newTextInputProps.traits.enablesReturnKeyAutomatically;
}

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
if (newTextInputProps.traits.keyboardAppearance != oldTextInputProps.traits.keyboardAppearance) {
_backedTextInputView.keyboardAppearance =
RCTUIKeyboardAppearanceFromKeyboardAppearance(newTextInputProps.traits.keyboardAppearance);
Expand All @@ -148,20 +152,24 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_backedTextInputView.spellCheckingType =
RCTUITextSpellCheckingTypeFromOptionalBool(newTextInputProps.traits.spellCheck);
}
#endif // ]TODO(macOS GH#774)

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

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
if (newTextInputProps.traits.clearButtonMode != oldTextInputProps.traits.clearButtonMode) {
_backedTextInputView.clearButtonMode =
RCTUITextFieldViewModeFromTextInputAccessoryVisibilityMode(newTextInputProps.traits.clearButtonMode);
}
#endif // ]TODO(macOS GH#774)

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

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
if (newTextInputProps.traits.secureTextEntry != oldTextInputProps.traits.secureTextEntry) {
_backedTextInputView.secureTextEntry = newTextInputProps.traits.secureTextEntry;
}
Expand All @@ -184,6 +192,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
RCTUITextInputPasswordRulesFromString(newTextInputProps.traits.passwordRules);
}
}
#endif // ]TODO(macOS GH#774)

// Traits `blurOnSubmit`, `clearTextOnFocus`, and `selectTextOnFocus` were omitted intentially here
// because they are being checked on-demand.
Expand All @@ -202,9 +211,11 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier()));
}

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
if (newTextInputProps.selectionColor != oldTextInputProps.selectionColor) {
_backedTextInputView.tintColor = RCTUIColorFromSharedColor(newTextInputProps.selectionColor);
}
#endif // ]TODO(macOS GH#774)

if (newTextInputProps.inputAccessoryViewID != oldTextInputProps.inputAccessoryViewID) {
_backedTextInputView.inputAccessoryViewID = RCTNSStringFromString(newTextInputProps.inputAccessoryViewID);
Expand Down Expand Up @@ -449,6 +460,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
[self _updateState];
}

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
UITextPosition *startPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
offset:start];
UITextPosition *endPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
Expand All @@ -458,6 +470,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
[_backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
}
#endif // ]TODO(macOS GH#774)
_comingFromJS = NO;
}

Expand All @@ -468,11 +481,14 @@ - (void)setDefaultInputAccessoryView
// InputAccessoryView component sets the inputAccessoryView when inputAccessoryViewID exists
if (_backedTextInputView.inputAccessoryViewID) {
if (_backedTextInputView.isFirstResponder) {
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
[_backedTextInputView reloadInputViews];
#endif
}
return;
}

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
UIKeyboardType keyboardType = _backedTextInputView.keyboardType;

// These keyboard types (all are number pads) don't have a "Done" button by default,
Expand Down Expand Up @@ -500,16 +516,21 @@ - (void)setDefaultInputAccessoryView
} else {
_backedTextInputView.inputAccessoryView = nil;
}
#endif // ]TODO(macOS GH#774)

if (_backedTextInputView.isFirstResponder) {
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
[_backedTextInputView reloadInputViews];
#endif // ]TODO(macOS GH#774)
}
}

- (void)handleInputAccessoryDoneButton
{
if ([self textInputShouldReturn]) {
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
[_backedTextInputView endEditing:YES];
#endif // ]TODO(macOS GH#774)
}
}

Expand Down Expand Up @@ -556,12 +577,17 @@ - (void)_updateState

- (AttributedString::Range)_selectionRange
{
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
UITextRange *selectedTextRange = _backedTextInputView.selectedTextRange;
NSInteger start = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument
toPosition:selectedTextRange.start];
NSInteger end = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument
toPosition:selectedTextRange.end];
return AttributedString::Range{(int)start, (int)(end - start)};
#else
// [Fabric] Placeholder till we implement selection in Fabric
return AttributedString::Range({0, 1});
#endif // ]TODO(macOS GH#774)
}

- (void)_restoreTextSelection
Expand All @@ -570,18 +596,21 @@ - (void)_restoreTextSelection
if (!selection.has_value()) {
return;
}
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
auto start = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
offset:selection->start];
auto end = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument offset:selection->end];
auto range = [_backedTextInputView textRangeFromPosition:start toPosition:end];
[_backedTextInputView setSelectedTextRange:range notifyDelegate:YES];
#endif // ]TODO(macOS GH#774)
}

- (void)_setAttributedString:(NSAttributedString *)attributedString
{
if ([self _textOf:attributedString equals:_backedTextInputView.attributedText]) {
return;
}
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
UITextRange *selectedRange = _backedTextInputView.selectedTextRange;
NSInteger oldTextLength = _backedTextInputView.attributedText.string.length;
_backedTextInputView.attributedText = attributedString;
Expand All @@ -598,6 +627,7 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
}
[self _restoreTextSelection];
_lastStringStateWasUpdatedWith = attributedString;
#endif // ]TODO(macOS GH#774)
}

- (void)_setMultiline:(BOOL)multiline
Expand Down Expand Up @@ -631,15 +661,19 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe
}
}];

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
BOOL shouldFallbackToBareTextComparison =
[_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] ||
_backedTextInputView.markedTextRange || _backedTextInputView.isSecureTextEntry || fontHasBeenUpdatedBySystem;

if (shouldFallbackToBareTextComparison) {
return ([newText.string isEqualToString:oldText.string]);
} else {
#endif // ]TODO(macOS GH#774)
return ([newText isEqualToAttributedString:oldText]);
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
}
#endif // ]TODO(macOS GH#774)
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void RCTCopyBackedTextInput(
RCTUIView<RCTBackedTextInputViewProtocol> *fromTextInput,
RCTUIView<RCTBackedTextInputViewProtocol> *toTextInput); // TODO(macOS GH#774)

#if !TARGET_OS_OSX // TODO(macOS GH#774)
UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional<bool> autoCorrect);

UITextAutocapitalizationType RCTUITextAutocapitalizationTypeFromAutocapitalizationType(
Expand All @@ -40,5 +41,6 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType)

API_AVAILABLE(ios(12.0))
UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(std::string const &passwordRules);
#endif // ]TODO(macOS GH#774)

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,29 @@ void RCTCopyBackedTextInput(
toTextInput.placeholder = fromTextInput.placeholder;
toTextInput.placeholderColor = fromTextInput.placeholderColor;
toTextInput.textContainerInset = fromTextInput.textContainerInset;
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
toTextInput.inputAccessoryView = fromTextInput.inputAccessoryView;
#endif // ]TODO(macOS GH#774)
toTextInput.textInputDelegate = fromTextInput.textInputDelegate;
toTextInput.placeholderColor = fromTextInput.placeholderColor;
toTextInput.defaultTextAttributes = fromTextInput.defaultTextAttributes;
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
toTextInput.autocapitalizationType = fromTextInput.autocapitalizationType;
toTextInput.autocorrectionType = fromTextInput.autocorrectionType;
#endif // ]TODO(macOS GH#774)
toTextInput.contextMenuHidden = fromTextInput.contextMenuHidden;
toTextInput.editable = fromTextInput.editable;
toTextInput.enablesReturnKeyAutomatically = fromTextInput.enablesReturnKeyAutomatically;
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
toTextInput.keyboardAppearance = fromTextInput.keyboardAppearance;
toTextInput.spellCheckingType = fromTextInput.spellCheckingType;
#endif // ]TODO(macOS GH#774)
toTextInput.caretHidden = fromTextInput.caretHidden;
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
toTextInput.clearButtonMode = fromTextInput.clearButtonMode;
#endif // ]TODO(macOS GH#774)
toTextInput.scrollEnabled = fromTextInput.scrollEnabled;
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
toTextInput.secureTextEntry = fromTextInput.secureTextEntry;
toTextInput.keyboardType = fromTextInput.keyboardType;
toTextInput.textContentType = fromTextInput.textContentType;
Expand All @@ -49,8 +58,10 @@ void RCTCopyBackedTextInput(
}

[toTextInput setSelectedTextRange:fromTextInput.selectedTextRange notifyDelegate:NO];
#endif // ]TODO(macOS GH#774)
}

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional<bool> autoCorrect)
{
return autoCorrect.has_value() ? (*autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo)
Expand Down Expand Up @@ -232,3 +243,4 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType)
{
return [UITextInputPasswordRules passwordRulesWithDescriptor:RCTNSStringFromStringNilIfEmpty(passwordRules)];
}
#endif // ]TODO(macOS GH#774)