Ejemplo n.º 1
0
        private static ReactViewRender CreateReactViewInstance(ReactViewFactory factory)
        {
            ReactViewRender InnerCreateView()
            {
                var view = new ReactViewRender(factory.DefaultStyleSheet, () => factory.InitializePlugins(), factory.EnableViewPreload, factory.EnableDebugMode, factory.DevServerURI);

                if (factory.ShowDeveloperTools)
                {
                    view.ShowDeveloperTools();
                }

                return(view);
            }

            if (factory.EnableViewPreload)
            {
                var factoryType = factory.GetType();
                // check if we have a view cached for the current factory
                if (CachedViews.TryGetValue(factoryType, out var cachedView))
                {
                    CachedViews.Remove(factoryType);
                }

                // create a new view in the background and put it in the cache
                Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => {
                    if (!CachedViews.ContainsKey(factoryType) && !Dispatcher.CurrentDispatcher.HasShutdownStarted)
                    {
                        CachedViews.Add(factoryType, InnerCreateView());
                    }
                }), DispatcherPriority.Background);

                if (cachedView != null)
                {
                    return(cachedView);
                }
            }

            return(InnerCreateView());
        }
Ejemplo n.º 2
0
        private static ReactViewRender CreateReactViewInstance(ReactViewFactory factory)
        {
            ReactViewRender InnerCreateView()
            {
                var view = new ReactViewRender(factory.DefaultStyleSheet, () => factory.InitializePlugins(), factory.EnableViewPreload, factory.MaxNativeMethodsParallelCalls, factory.EnableDebugMode, factory.DevServerURI, factory.RegisterWebJavaScriptObject, factory.UnregisterWebJavaScriptObject, factory.ExecuteWebScriptFunctionWithSerializedParams);

                if (factory.ShowDeveloperTools)
                {
                    view.ShowDeveloperTools();
                }
                return(view);
            }

            if (factory.EnableViewPreload)
            {
                var factoryType = factory.GetType();
                // check if we have a view cached for the current factory
                if (CachedViews.TryGetValue(factoryType, out var cachedView))
                {
                    CachedViews.Remove(factoryType);
                }

                // create a new view in the background and put it in the cache
                AsyncExecuteInUI(() => {
                    if (!CachedViews.ContainsKey(factoryType))
                    {
                        CachedViews.Add(factoryType, InnerCreateView());
                    }
                }, lowPriority: true);

                if (cachedView != null)
                {
                    return(cachedView);
                }
            }

            return(InnerCreateView());
        }