-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make Animated Value persist its value after reattaching #87
Conversation
related: #85 |
@@ -94,7 +94,7 @@ export default class AnimatedNode { | |||
|
|||
__nativeInitialize() { | |||
if (!INITIALIZED_NODES.has(this.__nodeID)) { | |||
ReanimatedModule.createNode(this.__nodeID, this.__nodeConfig); | |||
ReanimatedModule.createNode(this.__nodeID, { ...this.__nodeConfig }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this destruction in order not to fleeze value field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good but I think it would be easier to use callback to get the value instead of introducing new event type. That is have a method:
ReanimatedModule.getValue(this.__nodeID, v => {
this.__nodeConfig.value = v;
});
@kmagiera |
@kmagiera Why use a callback instead of returning a promise? |
@osdnk looks like the blinking problem wasn't related to the problem @ckknight we can also use promise instead of callback, what I wanted to get rid is that special type of event that we expect to be sent when we call a method. Much cleaner pattern would be to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, can you think of an example we can add to test if this continue to work in the future
src/core/AnimatedValue.js
Outdated
@@ -3,6 +3,8 @@ import { set } from '../base'; | |||
import { val } from '../utils'; | |||
import { evaluateOnce } from '../derived/evaluateOnce'; | |||
import interpolate from '../derived/interpolate'; | |||
import ReanimatedModule from '../ReanimatedModule'; | |||
import ReanimatedEventEmitter from '../ReanimatedEventEmitter'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import cleanup
When value gets detached from all component it can be still kept in memory and attached to some other component at later time. But because we don't know when JS reference is dropped we need to delete native counterpart of the value when it gets detached. This has led to a situation in which the value was reinstantiated on the native site. In that case if the value has changed we expect it to persist that changes when it gets attached again. This wasn't happening and each time the value was instantiated we'd always use the initial value.
With this change we are solving that issue by querying the value right before we detach the native node and then we use that value to update config such that next time when it gets instantiated it uses updated value instead of the initial one.