Skip to content

Commit

Permalink
[v3.8.5] Fix NodeEventType.ACTIVE_CHANGED logic was not synchronized …
Browse files Browse the repository at this point in the history
…to native.

Unit Tests only run on web platform, I forgot to change node.jsb.ts.

Previous PR: #17141
  • Loading branch information
dumganhar committed Dec 17, 2024
1 parent 2e4a9d5 commit 91838b1
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 91838b1

Please sign in to comment.