Esempio n. 1
0
        public ReactViewRender(ResourceUrl defaultStyleSheet, Func <IViewModule[]> initializePlugins, bool preloadWebView, bool enableDebugMode, Uri devServerUri = null)
        {
            UserCallingAssembly = WebView.GetUserCallingMethod().ReflectedType.Assembly;

            var urlParams = new string[] {
                new ResourceUrl(ResourcesAssembly).ToString(),
                enableDebugMode ? "1" : "0",
                ModulesObjectName,
                Listener.EventListenerObjName,
                ViewInitializedEventName,
                ViewDestroyedEventName,
                ViewLoadedEventName,
                ResourceUrl.CustomScheme + Uri.SchemeDelimiter + CustomResourceBaseUrl
            };

            var url = new ResourceUrl(ResourcesAssembly, ReactViewResources.Resources.DefaultUrl + "?" + string.Join("&", urlParams));

            // must useSharedDomain for the local storage to be shared
            WebView = new WebView(new ResourceUrl("about:blank"), useSharedDomain: true)
            {
                DisableBuiltinContextMenus = true,
                IsSecurityDisabled         = true,
                IgnoreMissingResources     = false,
                IsHistoryDisabled          = true
            };

            Loader = new LoaderModule(this);

            DefaultStyleSheet = defaultStyleSheet;
            PluginsFactory    = initializePlugins;
            EnableDebugMode   = enableDebugMode;
            DevServerUri      = devServerUri;

            GetOrCreateFrame(MainViewFrameName); // creates the main frame

            var loadedListener = WebView.AttachListener(ViewLoadedEventName);

            loadedListener.Handler   += OnViewLoaded;
            loadedListener.UIHandler += OnViewLoadedUIHandler;

            WebView.AttachListener(ViewInitializedEventName).Handler += OnViewInitialized;
            WebView.AttachListener(ViewDestroyedEventName).Handler   += OnViewDestroyed;

            WebView.Disposed += OnWebViewDisposed;
            WebView.JavascriptContextReleased += OnWebViewJavascriptContextReleased;
            WebView.BeforeResourceLoad        += OnWebViewBeforeResourceLoad;
            WebView.LoadFailed    += OnWebViewLoadFailed;
            WebView.FilesDragging += OnWebViewFilesDragging;
            WebView.TextDragging  += OnWebViewTextDragging;

            Content = WebView;

            // load url after event listeners have been attached
            WebView.LoadResource(url);

            if (preloadWebView)
            {
                WebView.InitializeBrowser();
            }
        }