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(); } }
public ReactViewRender(ResourceUrl defaultStyleSheet, Func <IViewModule[]> initializePlugins, bool preloadWebView, int maxNativeMethodsParallelCalls, bool enableDebugMode, Uri devServerUri = null, Func <string, object, Func <Func <object>, object>, bool, bool> registerWebJavaScriptObject = null, Action <string> unregisterWebJavaScriptObject = null, Action <string, object[]> executeWebScriptFunctionWithSerializedParams = null) { UserCallingAssembly = GetUserCallingMethod().ReflectedType.Assembly; this.registerWebJavaScriptObject = registerWebJavaScriptObject; this.unregisterWebJavaScriptObject = unregisterWebJavaScriptObject; this.executeWebScriptFunctionWithSerializedParams = executeWebScriptFunctionWithSerializedParams; // must useSharedDomain for the local storage to be shared WebView = new ExtendedWebView(useSharedDomain: true) { DisableBuiltinContextMenus = true, IsSecurityDisabled = true, IgnoreMissingResources = false, IsHistoryDisabled = true, MaxNativeMethodsParallelCalls = maxNativeMethodsParallelCalls }; NativeAPI.Initialize(this, registerWebJavaScriptObject, unregisterWebJavaScriptObject); Loader = new LoaderModule(this); DefaultStyleSheet = defaultStyleSheet; PluginsFactory = initializePlugins; EnableDebugMode = enableDebugMode; DevServerUri = devServerUri; GetOrCreateFrame(FrameInfo.MainViewFrameName); // creates the main frame WebView.Disposed += Dispose; WebView.BeforeNavigate += OnWebViewBeforeNavigate; WebView.BeforeResourceLoad += OnWebViewBeforeResourceLoad; WebView.LoadFailed += OnWebViewLoadFailed; WebView.FilesDragging += fileNames => FilesDragging?.Invoke(fileNames); WebView.TextDragging += textContent => TextDragging?.Invoke(textContent); WebView.KeyPressed += OnWebViewKeyPressed; ExtraInitialize(); var urlParams = new string[] { new ResourceUrl(ResourcesAssembly).ToString(), enableDebugMode ? "true" : "false", ExecutionEngine.ModulesObjectName, NativeAPI.NativeObjectName, ResourceUrl.CustomScheme + Uri.SchemeDelimiter + CustomResourceBaseUrl }; WebView.LoadResource(new ResourceUrl(ResourcesAssembly, ReactViewResources.Resources.DefaultUrl + "?" + string.Join("&", urlParams))); if (preloadWebView) { PreloadWebView(); } EditCommands = new EditCommands(WebView); }