Skip to content

Commit 7d54107

Browse files
authored
fix(ios): preserve contentView frame on input window attach (#178)
1 parent 046036f commit 7d54107

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

ios/input/EnrichedMarkdownInput.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ - (void)didMoveToWindow
333333
[super didMoveToWindow];
334334

335335
if (self.window) {
336-
ENRMRefreshTextViewAfterWindowAttach(_textView, self.bounds);
336+
// Don't override the contentView frame set by RCTViewComponentView.
337+
ENRMRefreshTextViewLayout(_textView);
337338

338339
[self applyFormatting];
339340
[self updatePlaceholderVisibility];

ios/utils/ENRMUIKit.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,16 @@ static inline ENRMTextLayoutResult ENRMMeasureTextLayout(ENRMPlatformTextView *t
298298
#define ENRMSetNeedsDisplay(view) [(view) setNeedsDisplay:YES]
299299
#endif
300300

301-
/// Refreshes a text view's layout and display after it is attached to a window.
302-
/// On iOS, resets contentOffset to zero (NSTextView has no scroll position).
303-
/// Sets the frame and text container to the given bounds, invalidates layout for
304-
/// any existing content, then triggers a redraw.
305-
static inline void ENRMRefreshTextViewAfterWindowAttach(ENRMPlatformTextView *textView, CGRect bounds)
301+
/// Invalidates the text container, re-lays out any existing content, and
302+
/// triggers a redraw. On iOS also resets contentOffset to zero.
303+
/// Does NOT touch the text view's frame — callers that need to reposition
304+
/// the view should set the frame themselves before calling this.
305+
static inline void ENRMRefreshTextViewLayout(ENRMPlatformTextView *textView)
306306
{
307307
#if !TARGET_OS_OSX
308308
textView.contentOffset = CGPointZero;
309309
#endif
310-
textView.frame = bounds;
311-
textView.textContainer.size = CGSizeMake(bounds.size.width, CGFLOAT_MAX);
310+
textView.textContainer.size = CGSizeMake(textView.bounds.size.width, CGFLOAT_MAX);
312311
NSUInteger textLength = ENRMGetAttributedText(textView).length;
313312
if (textLength > 0) {
314313
[textView.layoutManager invalidateLayoutForCharacterRange:NSMakeRange(0, textLength) actualCharacterRange:NULL];
@@ -317,6 +316,15 @@ static inline void ENRMRefreshTextViewAfterWindowAttach(ENRMPlatformTextView *te
317316
ENRMSetNeedsDisplay(textView);
318317
}
319318

319+
/// Refreshes a text view's layout and display after it is attached to a window.
320+
/// Sets the frame and text container to the given bounds, invalidates layout for
321+
/// any existing content, then triggers a redraw.
322+
static inline void ENRMRefreshTextViewAfterWindowAttach(ENRMPlatformTextView *textView, CGRect bounds)
323+
{
324+
textView.frame = bounds;
325+
ENRMRefreshTextViewLayout(textView);
326+
}
327+
320328
/// Cross-platform text deselection: UITextView uses selectedTextRange (nullable);
321329
/// NSTextView uses selectedRange (length-based).
322330
static inline void ENRMClearSelection(ENRMPlatformTextView *textView)

0 commit comments

Comments
 (0)