Skip to content
Open
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 @@ -13,6 +13,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)renderMarkdownSynchronously:(NSString *)markdownString;
- (BOOL)hasRenderedMarkdown:(NSString *)markdown;
- (BOOL)hasRenderedWithStyleFingerprint:(size_t)fingerprint;

/// Size last committed by Fabric via `updateLayoutMetrics:`, readable from
/// any thread without blocking (issue #550: the shadow-node measure path must
/// never wait on the main thread, and reading `bounds` off-main is unsafe).
/// Backed by a single lock-free atomic, so the pair can't tear. Returns
/// CGSizeZero until the first layout is committed.
- (CGSize)lastCommittedLayoutSize;
@end

NS_ASSUME_NONNULL_END
Expand Down
11 changes: 10 additions & 1 deletion packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ContextMenuUtils.h"
#import "ENRMAccessibilityLabels.h"
#import "ENRMAsyncRenderCoordinator.h"
#import "ENRMAtomicSize.h"
#import "ENRMImageAttachment.h"
#import "ENRMMarkdownParser.h"
#import "ENRMTailFadeInAnimator.h"
Expand Down Expand Up @@ -67,7 +68,6 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {

static char kENRMSegmentFadeAnimatorKey;


@interface EnrichedMarkdown () <RCTEnrichedMarkdownViewProtocol, UITextViewDelegate, ENRMImageLayoutObserver>
+ (ENRMMd4cFlags *)flagsFromProps:(const EnrichedMarkdownMd4cFlagsStruct &)props;
- (void)emitLinkPress:(NSString *)url;
Expand Down Expand Up @@ -119,6 +119,8 @@ @implementation EnrichedMarkdown {

ENRMWritingDirectionMode _writingDirectionMode;
NSWritingDirection _resolvedLayoutDirection;

ENRMAtomicSize _lastCommittedSize;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down Expand Up @@ -367,6 +369,11 @@ - (CGSize)measureSize:(CGFloat)maxWidth
return CGSizeMake(measuredWidth, measuredHeight);
}

- (CGSize)lastCommittedLayoutSize
{
return _lastCommittedSize.load();
}

- (BOOL)hasRenderedMarkdown:(NSString *)markdown
{
return _renderedMarkdown != nil && [_renderedMarkdown isEqualToString:markdown];
Expand Down Expand Up @@ -410,6 +417,8 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
{
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];

_lastCommittedSize.store(CGSizeMake(layoutMetrics.frame.size.width, layoutMetrics.frame.size.height));

NSWritingDirection resolved = _resolvedLayoutDirection;
if (layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
resolved = NSWritingDirectionRightToLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)renderMarkdownSynchronously:(NSString *)markdownString;
- (BOOL)hasRenderedMarkdown:(NSString *)markdown;
- (BOOL)hasRenderedWithStyleFingerprint:(size_t)fingerprint;

/// Size last committed by Fabric via `updateLayoutMetrics:`, readable from
/// any thread without blocking (issue #550: the shadow-node measure path must
/// never wait on the main thread, and reading `bounds` off-main is unsafe).
/// Backed by a single lock-free atomic, so the pair can't tear. Returns
/// CGSizeZero until the first layout is committed.
- (CGSize)lastCommittedLayoutSize;
@end

NS_ASSUME_NONNULL_END
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "ContextMenuUtils.h"
#import "ENRMAccessibilityLabels.h"
#import "ENRMAsyncRenderCoordinator.h"
#import "ENRMAtomicSize.h"
#import "ENRMContextMenuTextView+macOS.h"
#import "ENRMImageAttachment.h"
#import "ENRMMarkdownParser.h"
Expand Down Expand Up @@ -112,6 +113,8 @@ @implementation EnrichedMarkdownText {
NSWritingDirection _resolvedLayoutDirection;

ENRMDirtyFlags _dirtyFlags;

ENRMAtomicSize _lastCommittedSize;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down Expand Up @@ -142,6 +145,11 @@ - (CGSize)measureSize:(CGFloat)maxWidth
return size;
}

- (CGSize)lastCommittedLayoutSize
{
return _lastCommittedSize.load();
}

- (BOOL)hasRenderedMarkdown:(NSString *)markdown
{
return _renderedMarkdown != nil && [_renderedMarkdown isEqualToString:markdown];
Expand Down Expand Up @@ -170,6 +178,8 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
{
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];

_lastCommittedSize.store(CGSizeMake(layoutMetrics.frame.size.width, layoutMetrics.frame.size.height));

NSWritingDirection resolved = _resolvedLayoutDirection;
if (layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
resolved = NSWritingDirectionRightToLeft;
Expand Down
Loading
Loading