Exemple #1
0
        public void RestoreDefaultValues()
        {
            foreach (var entry in _propMap)
            {
                _propMap[entry.Key] = null;
            }

            _uiImplementation.SynchronouslyUpdateViewOnDispatcherThread(
                _connectedViewTag,
                _diffMap);
        }
        public void UpdateView(UIImplementation uiImplementation)
        {
            if (ConnectedViewTag == -1)
            {
                throw new InvalidOperationException("Node has not been attached to a view.");
            }

            var propsMap = new JObject();

            foreach (var entry in _propMapping)
            {
                var node      = _manager.GetNodeById(entry.Value);
                var styleNode = node as StyleAnimatedNode;
                var valueNode = default(ValueAnimatedNode);
                if (styleNode != null)
                {
                    styleNode.CollectViewUpdates(propsMap);
                }
                else if ((valueNode = node as ValueAnimatedNode) != null)
                {
                    propsMap.Add(entry.Key, valueNode.Value);
                }
                else
                {
                    throw new InvalidOperationException(
                              Invariant($"Unsupported type of node used in property node '{node.GetType()}'."));
                }
            }

            // TODO: Reuse propsMap and stylesDiffMap objects - note that in
            // subsequent animation steps for a given node most of the time
            // will be creating the same set of props (just with different
            // values). We can take advantage on that and optimize the way we
            // allocate property maps (we also know that updating view props
            // doesn't retain a reference to the styles object).
            var updated = uiImplementation.SynchronouslyUpdateViewOnDispatcherThread(
                ConnectedViewTag,
                new ReactStylesDiffMap(propsMap));

            if (!updated)
            {
                Tracer.Error(ReactConstants.Tag, "Native animation workaround, frame lost as result of race condition.", null);
            }
        }