Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

richtext addChild optimization #12928

Merged
merged 2 commits into from
Sep 28, 2022
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
1 change: 1 addition & 0 deletions cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const Alignment = [
export const ttfUtils = {
getAssemblerData () {
const sharedLabelData = Label._canvasPool.get();
sharedLabelData.canvas.width = sharedLabelData.canvas.height = 1;
return sharedLabelData;
},

Expand Down
12 changes: 1 addition & 11 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export class RichText extends Component {

public onLoad () {
this.node.on(NodeEventType.LAYER_CHANGED, this._applyLayer, this);
this.node.on(NodeEventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
}

public onEnable () {
Expand All @@ -502,11 +503,6 @@ export class RichText extends Component {
this._activateChildren(false);
}

public start () {
this._onTTFLoaded();
this.node.on(NodeEventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
}

public onRestore () {
if (!EDITOR) {
return;
Expand Down Expand Up @@ -1263,12 +1259,6 @@ export class RichText extends Component {
label.lineHeight = this._lineHeight;

label.updateRenderData(true);
// Todo: need update context size after this function call
// @ts-expect-error update assembler renderData for richText
const assembler = label._assembler;
if (assembler) {
assembler.updateRenderData(label);
}
}

protected _applyLayer () {
Expand Down