diff --git a/packages/rive/common.ts b/packages/rive/common.ts index 089d334..79c1d66 100644 --- a/packages/rive/common.ts +++ b/packages/rive/common.ts @@ -40,7 +40,7 @@ export class RiveEvents { static onPauseEvent = 'onPauseEvent'; static onLoopEndEvent = 'onLoopEndEvent'; static onStopEvent = 'onStopEvent'; - static stateChangedEvent = 'stageChangedEvent'; + static stateChangedEvent = 'stateChangedEvent'; static receivedInputEvent = 'receivedInputEvent'; static touchBeganEvent = 'touchBeganEvent'; static touchCancelledEvent = 'touchCancelledEvent'; diff --git a/packages/rive/index.android.ts b/packages/rive/index.android.ts index 4947fb1..61181d9 100644 --- a/packages/rive/index.android.ts +++ b/packages/rive/index.android.ts @@ -43,6 +43,15 @@ class Listener extends java.lang.Object implements app.rive.runtime.kotlin.contr notifyStateChanged(stateMachine: string, stateName: string): void { // this.owner.get()?.events.notifyEvent(RiveEvents.stateChangedEvent, { stateMachine, stateName }); + const owner = this.owner.get(); + if (owner) { + owner.events.notifyEvent(RiveEvents.stateChangedEvent, { stateMachine, stateName }); + owner.notify({ + eventName: 'stateChange', + object: owner, + detail: { stateMachine, stateName }, + }); + } } } @@ -250,6 +259,8 @@ export class RiveView extends RiveViewBase { // todo investigate. // this.listener = new Listener(new WeakRef(this)); //this.nativeViewProtected.getController().registerListener(this.listener); + this.listener = new Listener(new WeakRef(this)); + this.nativeViewProtected.getController().registerListener(this.listener); } } diff --git a/packages/rive/index.d.ts b/packages/rive/index.d.ts index 729b20e..b462fe7 100644 --- a/packages/rive/index.d.ts +++ b/packages/rive/index.d.ts @@ -65,4 +65,5 @@ export declare class RiveView extends View { triggerInput(name: string): void; triggerInputValue(name: string, value: string | boolean | number | null): void; + on(event: 'stateChange', callback: (ev: { object: RiveView; detail: { stateMachine: any; stateName: string } }) => void, thisArg?: any): void; } diff --git a/packages/rive/index.ios.ts b/packages/rive/index.ios.ts index 229b51b..7562130 100644 --- a/packages/rive/index.ios.ts +++ b/packages/rive/index.ios.ts @@ -174,11 +174,6 @@ export class RiveView extends RiveViewBase { if (this.ctrl) { this.ctrl.stop(); } - // if (Array.isArray(animationNames)) { - // this.nativeViewProtected.stop(this.buildList(animationNames), areStateMachines); - // } else if (typeof animationNames === 'string') { - // this.nativeViewProtected.stop(animationNames, areStateMachines); - // } } public pause(): void { @@ -365,6 +360,11 @@ class RiveStateMachineDelegateImpl extends NSObject implements RiveStateMachineD const owner = this._owner.deref(); if (owner) { owner.events.notifyEvent(RiveEvents.stateChangedEvent, { stateMachine, stateName }); + owner.notify({ + eventName: 'stateChange', + object: owner, + detail: { stateMachine, stateName }, + }); } } @@ -373,6 +373,11 @@ class RiveStateMachineDelegateImpl extends NSObject implements RiveStateMachineD const owner = this._owner.deref(); if (owner) { owner.events.notifyEvent(RiveEvents.receivedInputEvent, { stateMachine, input }); + // owner.notify({ + // eventName: 'receivedInput', + // object: owner, + // detail: { stateMachine, input } + // }); } }