Skip to content

Commit 7915370

Browse files
committed
fix: db property listener disposing
1 parent fbf2ed1 commit 7915370

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

src/Rive.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ export class RiveNativeEventEmitter {
6565
addListener<T>(
6666
path: string,
6767
propertyType: PropertyType,
68+
reactTag: number | null,
6869
callback: (value: T) => void
6970
) {
70-
const reactTag = findNodeHandle(this.riveRef.current);
71+
// const reactTag = findNodeHandle(this.riveRef.current);
7172
if (!reactTag) {
7273
console.warn(
7374
'[Rive] RiveRef viewTag is null. Cannot register property listener.'
@@ -113,9 +114,9 @@ export class RiveNativeEventEmitter {
113114
removeListener<T>(
114115
path: string,
115116
propertyType: PropertyType,
117+
reactTag: number | null,
116118
callback: (value: T) => void
117119
) {
118-
const reactTag = findNodeHandle(this.riveRef.current);
119120
if (!reactTag) {
120121
console.warn(
121122
'[Rive] RiveRef viewTag is null. Cannot unregister property listener.'
@@ -136,21 +137,6 @@ export class RiveNativeEventEmitter {
136137
}
137138
}
138139
}
139-
140-
removeListeners() {
141-
// Unregister all native listeners
142-
Object.keys(this.nativeSubscriptions).forEach((key) => {
143-
this.nativeSubscriptions[key]?.remove();
144-
delete this.nativeSubscriptions[key];
145-
delete this.callbacks[key];
146-
});
147-
// Unregister all callbacks
148-
Object.keys(this.callbacks).forEach((key) => {
149-
this.callbacks[key] = [];
150-
});
151-
this.nativeSubscriptions = {};
152-
this.callbacks = {};
153-
}
154140
}
155141

156142
export function useRive(): [(node: RiveRef) => void, RiveRef | null] {
@@ -242,24 +228,31 @@ function useRivePropertyListener<T>(
242228
useEffect(() => {
243229
const listener = riveRef?.internalNativeEmitter?.();
244230
if (!listener) return () => {};
245-
231+
const reactTag = findNodeHandle(riveRef.viewTag());
246232
if (propertyType === PropertyType.Color) {
247233
listener.addListener<number>(
248234
path,
249235
propertyType,
236+
reactTag,
250237
listenerCallbackWithColor
251238
);
252239
return () => {
253240
listener.removeListener<number>(
254241
path,
255242
propertyType,
243+
reactTag,
256244
listenerCallbackWithColor
257245
);
258246
};
259247
} else {
260-
listener.addListener<T>(path, propertyType, listenerCallback);
248+
listener.addListener<T>(path, propertyType, reactTag, listenerCallback);
261249
return () => {
262-
listener.removeListener<T>(path, propertyType, listenerCallback);
250+
listener.removeListener<T>(
251+
path,
252+
propertyType,
253+
reactTag,
254+
listenerCallback
255+
);
263256
};
264257
}
265258
}, [

0 commit comments

Comments
 (0)