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
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ class EnrichedTextInputViewManager :
// NO-OP iOS only prop
}

@ReactProp(name = "bouncesVertically")
override fun setBouncesVertically(
view: EnrichedTextInputView?,
value: Boolean,
) {
// NO-OP iOS only prop
}

override fun setContextMenuItems(
view: EnrichedTextInputView?,
value: ReadableArray?,
Expand Down
18 changes: 18 additions & 0 deletions ios/EnrichedTextInputView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ - (void)updateProps:(Props::Shared const &)props
[textView setScrollEnabled:newViewProps.scrollEnabled];
}

BOOL textViewBouncesVertically;

if (@available(iOS 17.4, *)) {
textViewBouncesVertically = textView.bouncesVertically;
} else {
textViewBouncesVertically = textView.bounces;
}

if (newViewProps.bouncesVertically != oldViewProps.bouncesVertically ||
textViewBouncesVertically != newViewProps.bouncesVertically) {
if (@available(iOS 17.4, *)) {
textView.bouncesVertically = newViewProps.bouncesVertically;
} else {
textView.bounces = newViewProps.bouncesVertically;
}
}
Comment on lines +227 to +242

if (newViewProps.contentInsets != oldViewProps.contentInsets) {
_customContentInsets = toUIEdgeInsets(newViewProps.contentInsets);
textView.textContainerInset = _layoutInsets + newViewProps.contentInsets;
Expand Down Expand Up @@ -1274,6 +1291,7 @@ - (void)anyTextMayHaveBeenModified {

// update active styles as well
[self tryUpdatingActiveStyles];

if (!textView.scrollEnabled) {
[textView setNeedsLayout];
}
Expand Down
96 changes: 65 additions & 31 deletions ios/inputTextView/InputTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ static inline BOOL CGSizeAlmostEqual(CGSize firstSize, CGSize secondSize,
fabs(firstSize.height - secondSize.height) < epsilon;
}

@interface InputTextView ()
- (void)notifySizeDidChangeForContentSize:(CGSize)contentSize;
- (CGFloat)placeholderSingleLineHeightForWidth:(CGFloat)width;
@end

@implementation InputTextView {
UILabel *_placeholderView;
CGSize _lastCommittedSize;
NSAttributedString *_lastMeasuredString;
};

- (instancetype)initWithFrame:(CGRect)frame {
Expand All @@ -31,7 +35,6 @@ - (instancetype)initWithFrame:(CGRect)frame {
self.scrollsToTop = NO;
self.alwaysBounceVertical = YES;
_lastCommittedSize = CGSizeZero;
_lastMeasuredString = [[NSAttributedString alloc] initWithString:@""];
}
return self;
}
Expand Down Expand Up @@ -117,41 +120,19 @@ - (void)layoutSubviews {
CGRect textFrame = UIEdgeInsetsInsetRect(self.bounds, combinedInsets);

CGFloat placeholderHeight =
[_placeholderView sizeThatFits:textFrame.size].height;
[self placeholderSingleLineHeightForWidth:textFrame.size.width];
textFrame.size.height = MIN(placeholderHeight, textFrame.size.height);

_placeholderView.frame = textFrame;

CGSize newSize;

if (self.scrollEnabled) {
CGRect usedRect =
[self.layoutManager usedRectForTextContainer:self.textContainer];
newSize = usedRect.size;
} else {
if ([_lastMeasuredString isEqualToAttributedString:self.textStorage]) {
return;
}
_lastMeasuredString = [self.textStorage copy];

if (!self.scrollEnabled || !_placeholderView.hidden) {
CGFloat maxWidth = self.bounds.size.width;
UIEdgeInsets savedInset = self.textContainerInset;
CGFloat savedLinePadding = self.textContainer.lineFragmentPadding;

CGSize fitSize = [self sizeThatFits:CGSizeMake(maxWidth, CGFLOAT_MAX)];

CGFloat height = fitSize.height - savedLinePadding * 2 - savedInset.top -
savedInset.bottom;

newSize = CGSizeMake(maxWidth, height);
}

if (CGSizeAlmostEqual(newSize, _lastCommittedSize, 0.5)) {
return;
if (maxWidth > 0) {
CGSize fittingSize =
[self sizeThatFits:CGSizeMake(maxWidth, CGFLOAT_MAX)];
[self notifySizeDidChangeForContentSize:fittingSize];
}
}

_lastCommittedSize = newSize;
[self.layoutDelegate sizeDidChange:newSize];
}

- (void)setContentInset:(UIEdgeInsets)contentInset {
Expand All @@ -174,4 +155,57 @@ - (void)scrollSelectionToVisibleWithInsets:(UIEdgeInsets)insets {
[self scrollRectToVisible:caretRect animated:YES];
}

- (void)setContentSize:(CGSize)contentSize {
[super setContentSize:contentSize];

[self notifySizeDidChangeForContentSize:contentSize];
}

- (void)notifySizeDidChangeForContentSize:(CGSize)contentSize {
UIEdgeInsets contentInsets = self.adjustedContentInset;

UIEdgeInsets combinedInsets =
UIEdgeInsetsMake(self.textContainerInset.top + contentInsets.top,
self.textContainerInset.left + contentInsets.left,
self.textContainerInset.bottom + contentInsets.bottom,
self.textContainerInset.right + contentInsets.right);
CGFloat height = MAX(0.0, ceil(contentSize.height - combinedInsets.top -
combinedInsets.bottom));
CGFloat width = MAX(0.0, ceil(contentSize.width - combinedInsets.left -
combinedInsets.right));
if (!_placeholderView.hidden) {
CGFloat placeholderMaxWidth = width > 0 ? width
: self.bounds.size.width -
combinedInsets.left -
combinedInsets.right;
if (placeholderMaxWidth > 0) {
height = MAX(
height,
ceil([self placeholderSingleLineHeightForWidth:placeholderMaxWidth]));
}
}
CGSize newSize = CGSizeMake(width, height);

if (CGSizeAlmostEqual(newSize, _lastCommittedSize, 0.5)) {
return;
}

_lastCommittedSize = newSize;
[self.layoutDelegate sizeDidChange:newSize];
}

- (CGFloat)placeholderSingleLineHeightForWidth:(CGFloat)width {
if (width <= 0 || _placeholderView.attributedText.length == 0) {
return 0;
}

NSInteger numberOfLines = _placeholderView.numberOfLines;
_placeholderView.numberOfLines = 1;
CGFloat height =
[_placeholderView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;
_placeholderView.numberOfLines = numberOfLines;

return height;
Comment on lines +202 to +208
}

@end
16 changes: 4 additions & 12 deletions ios/internals/EnrichedTextInputViewShadowNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import <EnrichedTextInputView.h>
#import <React/RCTShadowView+Layout.h>
#import <react/utils/ManagedObjectWrapper.h>
Comment on lines 3 to 5
#import <yoga/Yoga.h>

namespace facebook::react {

Expand All @@ -15,10 +14,9 @@
const auto nextSize = state.getContentSize();

if (_prevContentSize != nextSize) {
YGNodeMarkDirty(&yogaNode_);
_prevContentSize = nextSize;
dirtyLayout();
}

_prevContentSize = nextSize;
}

id EnrichedTextInputViewShadowNode::setupMockTextInputView_() const {
Expand All @@ -41,14 +39,8 @@
static_cast<const EnrichedTextInputViewShadowNode &>(source)
.getStateData();

const auto &newState = getStateData();

const auto &oldSize = oldState.getContentSize();
const auto &newSize = newState.getContentSize();

if (newSize != oldSize) {
YGNodeMarkDirty(&yogaNode_);
}
_prevContentSize = oldState.getContentSize();
dirtyLayoutIfNeeded();
}

EnrichedTextInputViewShadowNode::EnrichedTextInputViewShadowNode(
Expand Down
2 changes: 2 additions & 0 deletions lib/module/EnrichedReanimatedTextInput.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/module/EnrichedReanimatedTextInput.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/module/EnrichedTextInput.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading