99#import " EditMenuUtils.h"
1010
1111#import " ENRMFeatureFlags.h"
12- #import " ENRMUIKit.h"
1312
1413#if ENRICHED_MARKDOWN_MATH
1514#import " ENRMMathContainerView.h"
@@ -89,6 +88,7 @@ @implementation EnrichedMarkdown {
8988 BOOL _selectable;
9089 BOOL _enableLinkPreview;
9190 BOOL _streamingAnimation;
91+ ENRMTableStreamingMode _tableStreamingMode;
9292
9393 NSArray <NSString *> *_contextMenuItemTexts;
9494 NSArray <NSString *> *_contextMenuItemIcons;
@@ -123,6 +123,7 @@ - (instancetype)initWithFrame:(CGRect)frame
123123 _selectable = YES ;
124124 _enableLinkPreview = YES ;
125125 _streamingAnimation = NO ;
126+ _tableStreamingMode = ENRMTableStreamingModeHidden;
126127
127128 _fontScaleObserver = [[FontScaleObserver alloc ] init ];
128129 __weak EnrichedMarkdown *weakSelf = self;
@@ -185,7 +186,10 @@ - (void)configureSegmentViewRegistry
185186 return view;
186187 }
187188 updateView: ^(RCTUIView *view, ENRMRenderedSegment *segment) {
188- [(TableContainerView *)view applyTableNode: segment.tableSegment.tableNode];
189+ EnrichedMarkdown *strongSelf = weakSelf;
190+ if (strongSelf) {
191+ [strongSelf updateTableView: (TableContainerView *)view withSegment: segment.tableSegment];
192+ }
189193 }]];
190194
191195#if ENRICHED_MARKDOWN_MATH
@@ -347,10 +351,11 @@ - (void)renderMarkdownContent:(NSString *)markdownString
347351 CGFloat maxFontSizeMultiplier = _maxFontSizeMultiplier;
348352 BOOL allowTrailingMargin = _allowTrailingMargin;
349353 BOOL streamingAnimation = _streamingAnimation;
354+ ENRMTableStreamingMode tableStreamingMode = _tableStreamingMode;
350355
351356 dispatch_async (_renderQueue, ^{
352357 NSString *renderableMarkdown =
353- streamingAnimation ? ENRMRenderableMarkdownForStreaming (markdownString) : markdownString;
358+ streamingAnimation ? ENRMRenderableMarkdownForStreaming (markdownString, tableStreamingMode ) : markdownString;
354359 if (renderableMarkdown.length == 0 ) {
355360 dispatch_async (dispatch_get_main_queue (), ^{
356361 if (renderId == self->_currentRenderId ) {
@@ -405,7 +410,7 @@ - (void)renderMarkdownSynchronously:(NSString *)markdownString
405410 _blockAsyncRender = YES ;
406411 _cachedMarkdown = [markdownString copy ];
407412 NSString *renderableMarkdown =
408- _streamingAnimation ? ENRMRenderableMarkdownForStreaming (markdownString) : markdownString;
413+ _streamingAnimation ? ENRMRenderableMarkdownForStreaming (markdownString, _tableStreamingMode ) : markdownString;
409414 _renderedMarkdown = [renderableMarkdown copy ];
410415
411416 if (renderableMarkdown.length == 0 ) {
@@ -458,11 +463,6 @@ - (void)applyRenderedSegments:(NSArray *)renderedSegments renderedMarkdown:(NSSt
458463 [self computeSegmentLayoutForWidth: self .bounds.size.width applyFrames: YES ];
459464 [self layoutIfNeeded ];
460465 [self requestHeightUpdate ];
461- } else if (_streamingAnimation) {
462- CGSize measured = [self measureSize: self .bounds.size.width];
463- if (needsHeightUpdate (measured, self.bounds )) {
464- [self requestHeightUpdate ];
465- }
466466 } else {
467467 CGSize measured = [self measureSize: self .bounds.size.width];
468468 if (needsHeightUpdate (measured, self.bounds )) {
@@ -561,6 +561,39 @@ - (TableContainerView *)createTableViewForSegment:(ENRMTableSegment *)tableSegme
561561 return tableView;
562562}
563563
564+ - (void )updateTableView : (TableContainerView *)view withSegment : (ENRMTableSegment *)tableSegment
565+ {
566+ NSUInteger previousRowCount = view.rowCount ;
567+ [view applyTableNode: tableSegment.tableNode];
568+
569+ #if !TARGET_OS_OSX
570+ if (!_streamingAnimation || view.rowCount <= previousRowCount) {
571+ return ;
572+ }
573+
574+ // The grid container is inside the scroll view: TableContainerView > UIScrollView > gridContainer.
575+ // After applyTableNode:, cells are laid out sequentially — each row has colCount cell-background subviews.
576+ RCTUIView *scrollView = view.subviews .firstObject ;
577+ RCTUIView *gridContainer = scrollView.subviews .firstObject ;
578+ if (!gridContainer || gridContainer.subviews .count == 0 || view.rowCount == 0 ) {
579+ return ;
580+ }
581+
582+ NSUInteger colCount = gridContainer.subviews .count / view.rowCount ;
583+ if (colCount == 0 ) {
584+ return ;
585+ }
586+
587+ NSUInteger firstNewCellIndex = previousRowCount * colCount;
588+ NSArray <RCTUIView *> *subviews = gridContainer.subviews ;
589+ for (NSUInteger i = firstNewCellIndex; i < subviews.count ; i++) {
590+ RCTUIView *cellView = subviews[i];
591+ cellView.alpha = 0.0 ;
592+ [UIView animateWithDuration: 0.20 animations: ^{ cellView.alpha = 1.0 ; }];
593+ }
594+ #endif
595+ }
596+
564597#if ENRICHED_MARKDOWN_MATH
565598- (ENRMMathContainerView *)createMathViewForSegment : (ENRMMathSegment *)mathSegment
566599{
@@ -697,6 +730,15 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
697730 }
698731 }
699732
733+ BOOL streamingConfigChanged = NO ;
734+ if (newViewProps.streamingConfig .tableMode != oldViewProps.streamingConfig .tableMode ) {
735+ NSString *tableModeStr = [[NSString alloc ] initWithUTF8String: newViewProps.streamingConfig.tableMode.c_str ()];
736+ _tableStreamingMode = [tableModeStr isEqualToString: @" progressive" ] ? ENRMTableStreamingModeProgressive
737+ : ENRMTableStreamingModeHidden;
738+ streamingConfigChanged = YES ;
739+ _dirtyFlags |= ENRMDirtyForceHeight;
740+ }
741+
700742 if (ENRMContextMenuItemsChanged (oldViewProps.contextMenuItems , newViewProps.contextMenuItems )) {
701743 _contextMenuItemTexts = ENRMContextMenuTextsFromItems (newViewProps.contextMenuItems );
702744 _contextMenuItemIcons = ENRMContextMenuIconsFromItems (newViewProps.contextMenuItems );
@@ -722,7 +764,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
722764 }
723765
724766 if (markdownChanged || stylePropChanged || md4cFlagsChanged || allowTrailingMarginChanged ||
725- streamingAnimationChanged) {
767+ streamingAnimationChanged || streamingConfigChanged ) {
726768 NSString *markdownString = [[NSString alloc ] initWithUTF8String: newViewProps.markdown.c_str ()];
727769 [self renderMarkdownContent: markdownString];
728770 }
0 commit comments