mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Back out "Animated: Defer onAnimatedValueUpdate on Attach + Native" (#48731)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48731 Original commit changeset: 2089100a773e Original Phabricator Diff: D68236594 changelog: [internal] please read summary in D68268701 Reviewed By: yungsters Differential Revision: D68268698 fbshipit-source-id: f122336209c4a5ec480d7a6a37224391eb1d2311
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0511e2e49a
commit
b059050c87
@@ -85,7 +85,6 @@ function _executeAsAnimatedBatch(id: string, operation: () => void) {
|
||||
* See https://reactnative.dev/docs/animatedvalue
|
||||
*/
|
||||
export default class AnimatedValue extends AnimatedWithChildren {
|
||||
#attached: boolean = false;
|
||||
#updateSubscription: ?EventSubscription = null;
|
||||
|
||||
_value: number;
|
||||
@@ -108,8 +107,14 @@ export default class AnimatedValue extends AnimatedWithChildren {
|
||||
}
|
||||
|
||||
__attach(): void {
|
||||
this.#attached = true;
|
||||
this.#ensureUpdateSubscriptionExists();
|
||||
if (this.__isNative) {
|
||||
// NOTE: In theory, we should only need to call this when any listeners
|
||||
// are added. However, there is a global `onUserDrivenAnimationEnded`
|
||||
// listener that relies on `onAnimatedValueUpdate` having fired to update
|
||||
// the values in JavaScript. If that listener is removed, this could be
|
||||
// re-optimized.
|
||||
this.#ensureUpdateSubscriptionExists();
|
||||
}
|
||||
}
|
||||
|
||||
__detach(): void {
|
||||
@@ -121,7 +126,6 @@ export default class AnimatedValue extends AnimatedWithChildren {
|
||||
}
|
||||
this.stopAnimation();
|
||||
super.__detach();
|
||||
this.#attached = false;
|
||||
}
|
||||
|
||||
__getValue(): number {
|
||||
@@ -133,22 +137,10 @@ export default class AnimatedValue extends AnimatedWithChildren {
|
||||
this.#ensureUpdateSubscriptionExists();
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: In theory, we should only need to call this when any listeners
|
||||
* are added. However, there is a global `onUserDrivenAnimationEnded`
|
||||
* listener that relies on `onAnimatedValueUpdate` having fired to update
|
||||
* the values in JavaScript. If that listener is removed, this could be
|
||||
* re-optimized.
|
||||
*/
|
||||
#ensureUpdateSubscriptionExists(): void {
|
||||
if (this.#updateSubscription != null) {
|
||||
return;
|
||||
}
|
||||
// The order in which `__attach` and `__makeNative` are called is not
|
||||
// deterministic, and we only want to do this when both have occurred.
|
||||
if (!this.#attached || !this.__isNative) {
|
||||
return;
|
||||
}
|
||||
const nativeTag = this.__getNativeTag();
|
||||
NativeAnimatedAPI.startListeningToAnimatedNodeValue(nativeTag);
|
||||
const subscription: EventSubscription =
|
||||
|
||||
Reference in New Issue
Block a user