Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 7
0
 public LoaderModule(ReactViewRender viewRender)
 {
     ViewRender = viewRender;
 }
Ejemplo n.º 8
0
 public static void Initialize(ReactViewRender viewRender)
 {
     new NativeAPI(viewRender);
 }
Ejemplo n.º 9
0
 private NativeAPI(ReactViewRender viewRender)
 {
     ViewRender = viewRender;
     ViewRender.WebView.RegisterJavascriptObject(NativeObjectName, this);
 }