Skip to content

Commit

Permalink
perf(ios): check whether the dirtyText behavior requires layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy authored and hippy-actions[bot] committed Aug 28, 2023
1 parent 36aaa91 commit 114d0d7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ - (BOOL)isCSSLeafNode {
}

- (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note {
[self dirtyText];
[self dirtyText:YES];
}

- (NSDictionary<NSString *, id> *)processUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks
Expand Down Expand Up @@ -310,7 +310,7 @@ - (void)applyConfirmedLayoutDirectionToSubviews:(hippy::Direction)confirmedLayou
return;
}
[super applyConfirmedLayoutDirectionToSubviews:confirmedLayoutDirection];
[self dirtyText];
[self dirtyText:YES];
}

- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(hippy::LayoutMeasureMode)widthMode {
Expand Down Expand Up @@ -366,28 +366,43 @@ - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(hippy::Lay
return textStorage;
}

- (void)dirtyText {
[super dirtyText];
- (void)dirtyText:(BOOL)needToDoLayout {
[super dirtyText:needToDoLayout];
_isTextDirty = YES;
_cachedTextStorage = nil;
auto domManager = self.domManager.lock();
auto weakDomManager = self.domManager;
if (domManager) {
__weak NativeRenderObjectView *weakSelf = self;
std::vector<std::function<void()>> ops_ = {[weakSelf, domManager](){
auto domNodeAction = [needToDoLayout, weakSelf, weakDomManager](){
@autoreleasepool {
NativeRenderObjectView *strongSelf = weakSelf;
if (strongSelf) {
int32_t componentTag = [[strongSelf componentTag] intValue];
auto domNode = domManager->GetNode(strongSelf.rootNode, componentTag);
if (domNode) {
domNode->GetLayoutNode()->MarkDirty();
domManager->DoLayout(strongSelf.rootNode);
domManager->EndBatch(strongSelf.rootNode);
if (!strongSelf) {
return;
}
auto strongDomManager = weakDomManager.lock();
if (!strongDomManager) {
return;
}
int32_t componentTag = [[strongSelf componentTag] intValue];
auto domNode = strongDomManager->GetNode(strongSelf.rootNode, componentTag);
if (domNode) {
domNode->GetLayoutNode()->MarkDirty();
if (needToDoLayout) {
strongDomManager->DoLayout(strongSelf.rootNode);
strongDomManager->EndBatch(strongSelf.rootNode);
}
}
}
}};
domManager->PostTask(hippy::dom::Scene(std::move(ops_)));
};
BOOL isJSTaskRunner = (domManager->GetTaskRunner() && footstone::TaskRunner::GetCurrentTaskRunner());
if (isJSTaskRunner) {
domNodeAction();
}
else {
std::vector<std::function<void()>> ops = {domNodeAction};
domManager->PostTask(hippy::dom::Scene(std::move(ops)));
}
}
}

Expand Down Expand Up @@ -707,7 +722,7 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps {
_textAlignSet = YES;
}
if (_needDirtyText) {
[self dirtyText];
[self dirtyText:NO];
_needDirtyText =NO;
}
}
Expand Down Expand Up @@ -952,7 +967,7 @@ - (void)setFontSizeMultiplier:(CGFloat)fontSizeMultiplier {
((NativeRenderObjectText *)child).fontSizeMultiplier = fontSizeMultiplier;
}
}
[self dirtyText];
[self dirtyText:NO];
}

- (void)setMinimumFontScale:(CGFloat)minimumFontScale {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ extern NSString *const NativeRenderShadowViewDiffTag;
- (void)dirtyPropagation:(NativeRenderUpdateLifecycle)type NS_REQUIRES_SUPER;
- (BOOL)isPropagationDirty:(NativeRenderUpdateLifecycle)dirtyType;

- (void)dirtyText NS_REQUIRES_SUPER;
- (void)dirtyText:(BOOL)needToDoLayout NS_REQUIRES_SUPER;
- (void)setTextComputed NS_REQUIRES_SUPER;
- (BOOL)isTextDirty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (BOOL)isPropagationDirty:(NativeRenderUpdateLifecycle)dirtyType {
return isDirty;
}

- (void)dirtyText {
- (void)dirtyText:(BOOL)needToDoLayout {
}

- (BOOL)isTextDirty {
Expand Down Expand Up @@ -225,7 +225,7 @@ - (void)insertNativeRenderSubview:(NativeRenderObjectView *)subview atIndex:(NSI
}
subview->_superview = self;
_didUpdateSubviews = YES;
[self dirtyText];
[self dirtyText:NO];
[self dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
}

Expand All @@ -237,7 +237,7 @@ - (void)moveNativeRenderSubview:(id<NativeRenderComponentProtocol>)subview toInd
}

- (void)removeNativeRenderSubview:(NativeRenderObjectView *)subview {
[subview dirtyText];
[subview dirtyText:NO];
[subview dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
_didUpdateSubviews = YES;
subview->_superview = nil;
Expand Down

0 comments on commit 114d0d7

Please sign in to comment.