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.
## Motivation
I found it pretty fancy to write `nativeEvent` (or some field of `nativeEvent`) as a function which is evaluating on each event's frame.
## Changes
Because it must be done fully natively I do not relate `nativeEvent` function with any View but use list of `AlwaysNodes` instead, which may seems to be similar to `Animated.Code` and behave conceptually in the same way.
On executing code it performs "evalution" which fill required (by function) fields of `nativeEvent` by `Animated.Value`s and connect it to `AlwaysNode`. I decided to use `Proxy` to manage it, but it is not supported currently by Android because of anscient version of JSC, which is going to be replaced soon (kindly ping @pmlocek), so I have done some kind of case-specic polyfill.
merge firstly: https://github.com/kmagiera/react-native-gesture-handler/pull/287
This PR adds an implementation of Interactable.View to examples folder. The implementation is pretty feature full with the exception of alertAreas that I haven't had time yet to work on.
If there's expo used or debugger enabled RNR's `debug` node is supposed to show messages in console/terminal.
RNR should should logs only in `__DEV__` mode
+ Patch createAnimatedComponent using Set with dodgy instances from ebd0e94aab (😍)
+ Revert previously added workarounds that's been there to fix problem with animated node objects being frozen as a result of sending them over the bridge
I noticed this error when porting this code to RN implementation. Sometimes the flag is called `_refHasChanged` and sometimes `_refHasChanges` which causes it to stay true forever if set.
Edit: Actually the fact that it stays true forever hid a bug, `setNativeView` needs to always be called in `componentDidUpdate` because it is possible that `_propsAnimated` changed and the new instance does not have the view set. In this case we need to call it even if the ref did not change. `setNativeView` already no-ops if the ref is the same so no need to do any checks.
On iOS the behavior of running node updates was unpredictable for the case when new view has been attached. In such a case if it was required to run some updates (e.g. view has a transform that links to another nodes that require updates) we may ended up only running these in the next frame. The reason was that we'd use CADisplayLink to schedule animation callback but since we already run on UI thread the callback would only run in the next frame. As a result the view would first render with default params (e.g. no transform), then on the next frame the transform would update to the initial values. This was causing the view to flash with unexpected props applied for a single frame and only then be placed as expected.
In this change we force trigger onAnimationFrame callback if we suspect module operations (e.g. connect node to view) have requested updates. It does not matter if they didn't, as worse case we would run update loop twice. In that case the queues should be empty and when we run it for the second time there should be no additional computation being made.
This fix is not necessary on Android where we use ReactChoreographer. The reason is that choreographer has several buckets of callbacks that can be enqueued. We use `CallbackType.NATIVE_ANIMATED_MODULE` bucket which always runs after `DISPATCH_UI` which is used to run all module operations. So if operation requests an update the animation callback will run in the same frame in which it's been requested.
## Motivation
Logic of evaluation was strictly connected with views but it should not be like because some logic could be abstracted from views
## Changes
Add `Animated.Code` which behaves like view, but indeed is not related to any layout.
After start/stop API landed we started evaluating graph of nodes in topological order. In order for that to work we needed to create a stack of final node to be evaluated and run it in particular order. What might happen during evaluation is that some new nodes can be marked as updated (e.g. we use set node to update a value in a different nodes subtree). In such a case we want to update views that newly marked node may have impact on.
Here we also changed Android to use ArrayList instead of SparseArray for the list of updated nodes. This is to make it consistent with iOS implementation where we use a regular list too. In practice it won't happen too often that a view is added to a queue several times. Even if that happens, we still will evaluate the node at most once per frame.