示例#1
0
        /// <summary>
        /// Registers a new root view.
        /// </summary>
        /// <param name="rootView">The root view instance.</param>
        /// <returns>The root view tag.</returns>
        /// <remarks>
        /// JavaScript can use the returned tag with to add or remove children
        /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>.
        /// </remarks>
        public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
        {
            var tag = _nextRootTag;

            _nextRootTag += RootViewTagIncrement;

            var width  = rootView.ActualWidth;
            var height = rootView.ActualHeight;

            var context = new ThemedReactContext(Context);

            _uiImplementation.RegisterRootView(rootView, tag, width, height, context);

            var resizeCount = 0;

            rootView.SetOnSizeChangedListener((sender, args) =>
            {
                var currentCount = ++resizeCount;
                var newWidth     = args.NewSize.Width;
                var newHeight    = args.NewSize.Height;

                Context.RunOnNativeModulesQueueThread(() =>
                {
                    if (currentCount == resizeCount)
                    {
                        Context.AssertOnNativeModulesQueueThread();
                        _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight);
                    }
                });
            });

            return(tag);
        }
 /// <summary>
 /// Adds a root view to the hierarchy.
 /// </summary>
 /// <param name="tag">The root view tag.</param>
 /// <param name="rootView">The root view.</param>
 /// <param name="themedRootContext">The React context.</param>
 public void AddRootView(
     int tag,
     SizeMonitoringCanvas rootView,
     ThemedReactContext themedRootContext)
 {
     _nativeViewHierarchyManager.AddRootView(tag, rootView, themedRootContext);
 }
示例#3
0
        /// <summary>
        /// Adds a root view to the hierarchy.
        /// </summary>
        /// <param name="tag">The root view tag.</param>
        /// <param name="rootView">The root view.</param>
        /// <param name="themedRootContext">The React context.</param>
        public void AddRootView(
            int tag,
            SizeMonitoringCanvas rootView,
            ThemedReactContext themedRootContext)
        {
            // This is called on layout manager thread

            // Extract dispatcher
            var rootViewDispatcher = rootView.Dispatcher;

            // _dispatcherToOperationQueueInfo contains a mapping of CoreDispatcher to <UIViewOperationQueueInstance, # of ReactRootView instances>.
            // Operation queue instances are created lazily whenever an "unknown" CoreDispatcher is detected. Each operation queue instance
            // works together with one dedicated NativeViewHierarchyManager and one ReactChoreographer.
            // One operation queue is the "main" one:
            // - is coupled with the CoreApplication.MainView dispatcher
            // - drives animations in ALL views
            QueueInstanceInfo queueInfo;

            if (!_dispatcherToOperationQueueInfo.TryGetValue(rootViewDispatcher, out queueInfo))
            {
                // Queue instance doesn't exist for this dispatcher, we need to create

                // Find the CoreApplicationView associated to the new CoreDispatcher
                CoreApplicationView foundView = CoreApplication.Views.First(v => v.Dispatcher == rootViewDispatcher);

                // Create new ReactChoreographer for this view/dispatcher. It will only be used for its DispatchUICallback services
                ReactChoreographer reactChoreographer = ReactChoreographer.CreateSecondaryInstance(foundView);

                queueInfo = new QueueInstanceInfo()
                {
                    queueInstance = new UIViewOperationQueueInstance(
                        _reactContext,
                        new NativeViewHierarchyManager(_viewManagerRegistry, rootViewDispatcher, OnViewsDropped),
                        reactChoreographer),
                    rootViewCount = 1
                };

                // Add new tuple to map
                _dispatcherToOperationQueueInfo.Add(rootViewDispatcher, queueInfo);

                if (_active)
                {
                    // Simulate an OnResume from the correct dispatcher thread
                    // (OnResume/OnSuspend/OnDestroy have this thread affinity, all other methods do enqueuings in a thread safe manner)
                    DispatcherHelpers.RunOnDispatcher(rootViewDispatcher, queueInfo.queueInstance.OnResume, true); // inlining allowed
                }
            }
            else
            {
                // Queue instance does exist.
                // Increment the count of root views. This is helpful for the case the count reaches 0 so we can cleanup the queue.
                queueInfo.rootViewCount++;
            }

            // Add tag
            _reactTagToOperationQueue.Add(tag, queueInfo.queueInstance);

            // Send forward
            queueInfo.queueInstance.AddRootView(tag, rootView, themedRootContext);
        }
 /// <summary>
 /// Adds a root view to the hierarchy.
 /// </summary>
 /// <param name="tag">The root view tag.</param>
 /// <param name="rootView">The root view.</param>
 /// <param name="themedRootContext">The React context.</param>
 public void AddRootView(
     int tag,
     SizeMonitoringCanvas rootView,
     ThemedReactContext themedRootContext)
 {
     DispatcherHelpers.AssertOnDispatcher();
     _nativeViewHierarchyManager.AddRootView(tag, rootView, themedRootContext);
 }
        /// <summary>
        /// Register the root view.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        /// <param name="tag">The view tag.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="context">The context.</param>
        public void RegisterRootView(
            SizeMonitoringCanvas rootView,
            int tag,
            double width,
            double height,
            ThemedReactContext context)
        {
            var rootCssNode = CreateRootShadowNode();
            rootCssNode.ReactTag = tag;
            rootCssNode.ThemedContext = context;
            rootCssNode.Width = (float)width;
            rootCssNode.Height = (float)height;
            _shadowNodeRegistry.AddRootNode(rootCssNode);

            // Register it with the NativeViewHierarchyManager.
            _operationsQueue.AddRootView(tag, rootView, context);
        }
        /// <summary>
        /// Register the root view.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        /// <param name="tag">The view tag.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="context">The context.</param>
        public void RegisterRootView(
            SizeMonitoringCanvas rootView,
            int tag,
            double width,
            double height,
            ThemedReactContext context)
        {
            var rootCssNode = CreateRootShadowNode();

            rootCssNode.ReactTag      = tag;
            rootCssNode.ThemedContext = context;
            rootCssNode.StyleWidth    = (float)width;
            rootCssNode.StyleHeight   = (float)height;
            _shadowNodeRegistry.AddRootNode(rootCssNode);

            // Register it with the NativeViewHierarchyManager.
            _operationsQueue.AddRootView(tag, rootView, context);
        }
示例#7
0
        /// <summary>
        /// Registers a new root view.
        /// </summary>
        /// <param name="rootView">The root view instance.</param>
        /// <returns>The root view tag.</returns>
        /// <remarks>
        /// JavaScript can use the returned tag with to add or remove children
        /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>.
        /// </remarks>
        public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
        {
            var tag = _nextRootTag;

            _nextRootTag += RootViewTagIncrement;

            //var width = rootView.ActualWidth;
            //var height = rootView.ActualHeight;

            var geometry = rootView.Geometry;
            var width    = geometry.Width;
            var height   = geometry.Height;

            RNTracer.Write(Common.ReactConstants.Tag, "RootView : " + width + " * " + height);

            var context = new ThemedReactContext(Context);

            _uiImplementation.RegisterRootView(rootView, tag, width, height, context);

            var resizeCount = 0;

            rootView.SetOnSizeChangedListener((sender, args) =>
            {
                var currentCount = ++resizeCount;

                /*
                 * var newWidth = args.NewSize.Width;
                 * var newHeight = args.NewSize.Height;
                 *
                 * Context.RunOnNativeModulesQueueThread(() =>
                 * {
                 *  if (currentCount == resizeCount)
                 *  {
                 *      Context.AssertOnNativeModulesQueueThread();
                 *      _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight, _eventDispatcher);
                 *  }
                 * });
                 */
            });

            return(tag);
        }
 /// <summary>
 /// Adds a root view with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="view">The root view.</param>
 /// <param name="themedContext">The themed context.</param>
 public void AddRootView(int tag, SizeMonitoringCanvas view, ThemedReactContext themedContext)
 {
     AddRootViewParent(tag, view, themedContext);
 }
 /// <summary>
 /// Adds a root view with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="view">The root view.</param>
 /// <param name="themedContext">The themed context.</param>
 public void AddRootView(int tag, SizeMonitoringCanvas view, ThemedReactContext themedContext)
 {
     AddRootViewParent(tag, view, themedContext);
 }
        /// <summary>
        /// Registers a new root view.
        /// </summary>
        /// <param name="rootView">The root view instance.</param>
        /// <returns>The root view tag.</returns>
        /// <remarks>
        /// JavaScript can use the returned tag with to add or remove children 
        /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>.
        /// </remarks>
        public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
        {
            var tag = _nextRootTag;
            _nextRootTag += RootViewTagIncrement;

            var width = rootView.ActualWidth;
            var height = rootView.ActualHeight;

            var context = new ThemedReactContext(Context);
            _uiImplementation.RegisterRootView(rootView, tag, width, height, context);

            var resizeCount = 0;

            rootView.SetOnSizeChangedListener((sender, args) =>
            {
                var currentCount = ++resizeCount;
                var newWidth = args.NewSize.Width;
                var newHeight = args.NewSize.Height;

                Context.RunOnNativeModulesQueueThread(() =>
                {
                    if (currentCount == resizeCount)
                    {
                        Context.AssertOnNativeModulesQueueThread();
                        _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight, _eventDispatcher);
                    }
                });
            });

            return tag;
        }