-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: collect orphaned AnimatedPropsRegistry entry on last animated view unmount #9730
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| 'use strict'; | ||
|
|
||
| import { scheduleOnRN, scheduleOnUI } from 'react-native-worklets'; | ||
|
|
||
| import { | ||
| unprocessColor, | ||
| unprocessColorsInProps, | ||
|
|
@@ -11,7 +13,6 @@ import { ReanimatedModule } from './ReanimatedModule'; | |
| const FLUSH_INTERVAL_MS = 500; | ||
|
|
||
| export const PropsRegistryGarbageCollector = { | ||
| viewsCount: 0, | ||
| viewsMap: new Map<number, IAnimatedComponentInternal>(), | ||
| intervalId: null as NodeJS.Timeout | null, | ||
|
|
||
|
|
@@ -25,17 +26,20 @@ export const PropsRegistryGarbageCollector = { | |
| return; | ||
| } | ||
| this.viewsMap.set(viewTag, component); | ||
| this.viewsCount++; | ||
| if (this.viewsCount === 1) { | ||
| if (this.viewsMap.size === 1) { | ||
| this.registerInterval(); | ||
| } | ||
| }, | ||
|
|
||
| unregisterView(viewTag: number) { | ||
| this.viewsMap.delete(viewTag); | ||
| this.viewsCount--; | ||
| if (this.viewsCount === 0) { | ||
| // `delete` returns false when the tag wasn't tracked (the nested-component | ||
| // case registerView skipped above); bail to keep the count symmetric. | ||
| if (!this.viewsMap.delete(viewTag)) { | ||
| return; | ||
| } | ||
| if (this.viewsMap.size === 0) { | ||
| this.unregisterInterval(); | ||
| scheduleOrphanedPropsCleanup(); | ||
| } | ||
| }, | ||
|
|
||
|
|
@@ -66,6 +70,25 @@ export const PropsRegistryGarbageCollector = { | |
| }, | ||
| }; | ||
|
|
||
| // The last animated view just unmounted, so the GC interval has stopped and no | ||
| // commit will drain the registry. An in-flight animation frame can still re-add | ||
| // the view's props; wait one UI frame for it to run, then clear the registry. | ||
| function scheduleOrphanedPropsCleanup() { | ||
| scheduleOnUI(() => { | ||
| 'worklet'; | ||
| requestAnimationFrame(() => { | ||
| 'worklet'; | ||
| scheduleOnRN(removeOrphanedProps); | ||
|
Comment on lines
+77
to
+81
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks a bit hacky (
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, what exactly are you trying to achieve here? Maybe you can just do |
||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function removeOrphanedProps() { | ||
| if (PropsRegistryGarbageCollector.viewsMap.size === 0) { | ||
| ReanimatedModule.removeOrphanedProps(); | ||
| } | ||
| } | ||
|
|
||
| function unprocessProps(props: StyleProps) { | ||
| unprocessColorsInProps(props); | ||
| unprocessBoxShadow(props); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.