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

[v3.8.5] Fix NodeEventType.ACTIVE_CHANGED logic was not synchronized to native. #18048

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
21 changes: 21 additions & 0 deletions cocos/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const TRANSFORMBIT_TRS = TransformBit.TRS;

const nodeProto: any = jsb.Node.prototype;
export const TRANSFORM_ON = 1 << 0;
const ACTIVE_ON = 1 << 1;
const Destroying = CCObject.Flags.Destroying;

// TODO: `_setTempFloatArray` is only implemented on Native platforms. @dumganhar
Expand Down Expand Up @@ -262,6 +263,9 @@ nodeProto.on = function (type, callback, target, useCapture: any = false) {
this._registeredNodeEventTypeMask |= REGISTERED_EVENT_MASK_TRANSFORM_CHANGED;
}
break;
case NodeEventType.ACTIVE_CHANGED:
this._eventMask |= ACTIVE_ON;
break;
case NodeEventType.PARENT_CHANGED:
if (!(this._registeredNodeEventTypeMask & REGISTERED_EVENT_MASK_PARENT_CHANGED)) {
this._registerOnParentChanged();
Expand Down Expand Up @@ -308,6 +312,9 @@ nodeProto.off = function (type: string, callback?, target?, useCapture = false)
case NodeEventType.TRANSFORM_CHANGED:
this._eventMask &= ~TRANSFORM_ON;
break;
case NodeEventType.ACTIVE_CHANGED:
this._eventMask &= ~ACTIVE_ON;
break;
default:
break;
}
Expand Down Expand Up @@ -336,6 +343,10 @@ nodeProto.targetOff = function (target: string | unknown) {
if ((this._eventMask & TRANSFORM_ON) && !this._eventProcessor.hasEventListener(NodeEventType.TRANSFORM_CHANGED)) {
this._eventMask &= ~TRANSFORM_ON;
}

if ((this._eventMask & ACTIVE_ON) && !this._eventProcessor.hasEventListener(NodeEventType.ACTIVE_CHANGED)) {
this._eventMask &= ~ACTIVE_ON;
}
};

nodeProto.pauseSystemEvents = function pauseSystemEvents(recursive: boolean): void {
Expand Down Expand Up @@ -500,6 +511,10 @@ nodeProto._onActivateNode = function (shouldActiveNow) {
};

nodeProto._onPostActivated = function (active: boolean) {
if (this._eventMask & ACTIVE_ON) {
this.emit(NodeEventType.ACTIVE_CHANGED, this, active);
}

this._eventProcessor.setEnabled(active);
if (active) {
// in case transform updated during deactivated period
Expand Down Expand Up @@ -1263,6 +1278,12 @@ nodeProto._onActiveNode = function (shouldActiveNow: boolean) {
};

nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) {
if (this._eventMask & ACTIVE_ON) {
if (!this._activeInHierarchy) {
this.emit(NodeEventType.ACTIVE_CHANGED, this, false);
}
}

this.hasChangedFlags = TRANSFORMBIT_TRS;
const children = this._children;
const len = children.length;
Expand Down
Loading