示例#1
0
        protected ReactView(IViewModule mainModule)
        {
            View = CreateReactViewInstance(Factory);

            View.Host  = this;
            MainModule = mainModule;
            // bind main module (this is needed so that the plugins are available right away)
            View.BindComponent(mainModule);

            ExtraInitialize();
        }
示例#2
0
        protected ReactView(IViewModule mainModule)
        {
            View = CreateReactViewInstance(Factory);
            SetResourceReference(StyleProperty, typeof(ReactView)); // force styles to be inherited, must be called after view is created otherwise view might be null

            View.Host  = this;
            MainModule = mainModule;
            // bind main module (this is needed so that the plugins are available right away)
            View.BindComponent(mainModule);

            IsVisibleChanged += OnIsVisibleChanged;

            Content = View;

            FocusManager.SetIsFocusScope(this, true);
            FocusManager.SetFocusedElement(this, View.FocusableElement);
        }
示例#3
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());
        }
示例#4
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());
        }
示例#5
0
 public static void Initialize(ReactViewRender viewRender, Func <string, object, Func <Func <object>, object>, bool, bool> registerWebJavaScriptObject = null, Action <string> unregisterWebJavaScriptObject = null)
 {
     new NativeAPI(viewRender, registerWebJavaScriptObject);
 }
示例#6
0
 private NativeAPI(ReactViewRender viewRender, Func <string, object, Func <Func <object>, object>, bool, bool> registerWebJavaScriptObject = null)
 {
     ViewRender = viewRender;
     ViewRender.WebView.RegisterJavascriptObject(NativeObjectName, this);
     registerWebJavaScriptObject(NativeObjectName, this, null, false);
 }
示例#7
0
 public LoaderModule(ReactViewRender viewRender)
 {
     ViewRender = viewRender;
 }
示例#8
0
 public static void Initialize(ReactViewRender viewRender)
 {
     new NativeAPI(viewRender);
 }
示例#9
0
 private NativeAPI(ReactViewRender viewRender)
 {
     ViewRender = viewRender;
     ViewRender.WebView.RegisterJavascriptObject(NativeObjectName, this);
 }