Пример #1
0
        /// <summary>
        /// Invoked by React when the props change for a node with the
        /// given tag.
        /// </summary>
        /// <param name="tag">The view tag.</param>
        /// <param name="className">The view class name.</param>
        /// <param name="props">The props.</param>
        public void UpdateView(int tag, string className, JObject props)
        {
            var viewManager = _viewManagers.Get(className);
            var cssNode     = _shadowNodeRegistry.GetNode(tag);

            if (cssNode == null)
            {
                throw new InvalidOperationException($"Trying to update view with invalid tag '{tag}'.");
            }

            if (props != null)
            {
                cssNode.UpdateProps(props);
                HandleUpdateView(cssNode, className, props);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a view with the given tag and class name.
        /// </summary>
        /// <param name="themedContext">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="className">The class name.</param>
        /// <param name="initialProps">The initial props.</param>
        public void CreateView(ThemedReactContext themedContext, int tag, string className, JObject initialProps)
        {
            AssertOnCorrectDispatcher();
            using (Tracer.Trace(Tracer.TRACE_TAG_REACT_VIEW, "NativeViewHierarcyManager.CreateView")
                   .With("tag", tag)
                   .With("className", className)
                   .Start())
            {
                var viewManager = _viewManagers.Get(className);
                var view        = viewManager.CreateView(themedContext);
                _tagsToViews.Add(tag, view);
                _tagsToViewManagers.Add(tag, viewManager);

                ViewExtensions.SetTag(view, tag);
                ViewExtensions.SetReactContext(view, themedContext);

#if WINDOWS_UWP
                if (view is UIElement element)
                {
                    AccessibilityHelper.OnViewInstanceCreated(element);
                }
#endif

                if (initialProps != null)
                {
                    viewManager.UpdateProps(view, initialProps);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Invoked by React when the properties change for a node with the
        /// given tag.
        /// </summary>
        /// <param name="tag">The view tag.</param>
        /// <param name="className">The view class name.</param>
        /// <param name="props">The properties.</param>
        public void UpdateView(int tag, string className, JObject props)
        {
            var viewManager = _viewManagers.Get(className);
            var cssNode     = _shadowNodeRegistry.GetNode(tag);

            if (cssNode == null)
            {
                throw new InvalidOperationException(
                          Invariant($"Trying to update view with invalid tag '{tag}'."));
            }

            if (props != null)
            {
                var styles = new ReactStylesDiffMap(props);
                cssNode.UpdateProperties(styles);
                HandleUpdateView(cssNode, className, styles);
            }
        }
        /// <summary>
        /// Creates a view with the given tag and class name.
        /// </summary>
        /// <param name="themedContext">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="className">The class name.</param>
        /// <param name="initialProperties">The properties.</param>
        public void CreateView(ThemedReactContext themedContext, int tag, string className, ReactStylesDiffMap initialProperties)
        {
            DispatcherHelpers.AssertOnDispatcher();
            using (Tracer.Trace(Tracer.TRACE_TAG_REACT_VIEW, "NativeViewHierarcyManager.CreateView")
                   .With("tag", tag)
                   .With("className", className))
            {
                var viewManager = _viewManagers.Get(className);
                var view        = viewManager.CreateView(themedContext, _jsResponderHandler);
                _tagsToViews.Add(tag, view);
                _tagsToViewManagers.Add(tag, viewManager);

                // Uses an extension method and `Tag` property on
                // FrameworkElement to store the tag of the view.
                view.SetTag(tag);
                view.SetReactContext(themedContext);

                if (initialProperties != null)
                {
                    viewManager.UpdateProperties(view, initialProperties);
                }
            }
        }