Ejemplo n.º 1
0
        /// <summary>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void DetachRootView(ReactRootView rootView)
        {
            Log.Info(ReactConstants.Tag, "[ReactInstanceManager] Enter DetachRootView ");
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher();

            if (_attachedRootViews.Remove(rootView))
            {
                var currentReactContext = _currentReactContext;
                if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                {
                    DetachViewFromInstance(rootView, currentReactContext.ReactInstance);
                }
            }

            // release 'RootView'
            Log.Info(ReactConstants.Tag, $"Time to release RootView, but its children count = {rootView.GetChildrenCount()} ThreadID={Thread.CurrentThread.ManagedThreadId}");

            // TODO: TO BE FIXXED
            // When 'Teminate', operation for 'remove' won't be execute, so,
            // if rootView want to be unrealized, firstly, its children must
            // be removed, otherwise, it will coredump ...
            rootView.RemoveViewInfo();
            rootView.Unrealize();

            Log.Info(ReactConstants.Tag, "[ReactInstanceManager] Exit DetachRootView ");
        }