/// <summary> /// Binds the specified component to the main frame. /// </summary> /// <param name="component"></param> public void BindComponent(IViewModule component) { lock (SyncRoot) { var frame = GetOrCreateFrame(FrameInfo.MainViewFrameName); BindComponentToFrame(component, frame); } }
/// <summary> /// Unregisters a .net object available on the js context. /// </summary> /// <param name="module"></param> /// <param name="frameName"></param> private void UnregisterNativeObject(IViewModule module, FrameInfo frame) { var nativeObjectName = module.GetNativeObjectFullName(frame.Name); WebView.UnregisterJavascriptObject(nativeObjectName); unregisterWebJavaScriptObject(nativeObjectName); }
/// <summary> /// Registers a .net object to be available on the js context. /// </summary> /// <param name="module"></param> /// <param name="frameName"></param> /// <param name="forceNativeSyncCalls"></param> private void RegisterNativeObject(IViewModule module, FrameInfo frame) { var nativeObjectName = module.GetNativeObjectFullName(frame.Name); WebView.RegisterJavascriptObject(nativeObjectName, module.CreateNativeObject(), interceptCall: CallNativeMethod, executeCallsInUI: false); registerWebJavaScriptObject(nativeObjectName, module.CreateNativeObject(), /*interceptCall*/ CallNativeMethod, /*executeCallsInUI*/ false); }
public void LoadComponent(IViewModule component) { this.component = component; if (pageLoaded) { InternalLoadComponent(); } }
/// <summary> /// Load the specified component into the main frame. /// </summary> /// <param name="component"></param> public void LoadComponent(IViewModule component) { lock (SyncRoot) { var frame = GetOrCreateFrame(FrameInfo.MainViewFrameName); frame.IsComponentReadyToLoad = true; TryLoadComponent(frame); } }
private static string SerializeComponent(IViewModule component) { var nativeObjectMethodsMap = component.Events .Select(g => new KeyValuePair <string, object>(g, JavascriptSerializer.Undefined)) .Concat(component.PropertiesValues) .OrderBy(p => p.Key) .Select(p => new KeyValuePair <string, object>(JavascriptSerializer.GetJavascriptName(p.Key), p.Value)); return(JavascriptSerializer.Serialize(nativeObjectMethodsMap, o => JavascriptSerializer.Serialize(o))); }
public T EvaluateMethod <T>(IViewModule module, string methodCall, params object[] args) { if (webView == null) { return(default(T)); } var method = FormatMethodInvocation(module, methodCall); return(webView.EvaluateScriptFunctionWithSerializedParams <T>(method, args)); }
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(); }
public void ExecuteMethod(IViewModule module, string methodCall, params object[] args) { if (webView != null) { var method = FormatMethodInvocation(module, methodCall); webView.ExecuteScriptFunctionWithSerializedParams(method, args); } else { PendingExecutions.Enqueue(Tuple.Create(module, methodCall, args)); } }
/// <summary> /// Adds the specified view instance and binds it to the frame. /// </summary> /// <param name="frameName"></param> /// <returns>True if the view was bound to the frame. False if the frame already as a component bound.</returns> public bool AddChildView(IViewModule childView, string frameName) { lock (SyncRoot) { var frame = GetOrCreateFrame(frameName); if (frame.Component == null) { BindComponentToFrame(childView, frame); return(true); } return(false); } }
void IChildViewHost.LoadComponent(string frameName, IViewModule component) { lock (SyncRoot) { var frame = GetOrCreateFrame(frameName); if (frame.Component == null) { // component not bound yet? bind it BindComponentToFrame(component, frame); } frame.IsComponentReadyToLoad = true; TryLoadComponent(frame); } }
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); }
/// <summary> /// Loads the specified react component into the specified frame /// </summary> /// <param name="component"></param> /// <param name="frameName"></param> public void LoadComponent(IViewModule component, string frameName, bool hasStyleSheet, bool hasPlugins) { var mainSource = ViewRender.ToFullUrl(NormalizeUrl(component.MainJsSource)); var dependencySources = component.DependencyJsSources.Select(s => ViewRender.ToFullUrl(NormalizeUrl(s))).ToArray(); var cssSources = component.CssSources.Select(s => ViewRender.ToFullUrl(NormalizeUrl(s))).ToArray(); var nativeObjectMethodsMap = component.Events.Select(g => new KeyValuePair <string, object>(g, JavascriptSerializer.Undefined)) .Concat(component.PropertiesValues) .OrderBy(p => p.Key) .Select(p => new KeyValuePair <string, object>(JavascriptSerializer.GetJavascriptName(p.Key), p.Value)); var componentSerialization = JavascriptSerializer.Serialize(nativeObjectMethodsMap); var componentHash = ComputeHash(componentSerialization); // loadComponent arguments: // // componentName: string, // componentNativeObjectName: string, // componentSource: string, // dependencySources: string[], // cssSources: string[], // maxPreRenderedCacheEntries: number, // hasStyleSheet: boolean, // hasPlugins: boolean, // componentNativeObject: Dictionary<any>, // frameName: string // componentHash: string var loadArgs = new[] { JavascriptSerializer.Serialize(component.Name), JavascriptSerializer.Serialize(component.GetNativeObjectFullName(frameName)), JavascriptSerializer.Serialize(mainSource), JavascriptSerializer.Serialize(dependencySources), JavascriptSerializer.Serialize(cssSources), JavascriptSerializer.Serialize(ReactView.PreloadedCacheEntriesSize), JavascriptSerializer.Serialize(hasStyleSheet), JavascriptSerializer.Serialize(hasPlugins), componentSerialization, JavascriptSerializer.Serialize(frameName), JavascriptSerializer.Serialize(componentHash), }; ExecuteLoaderFunction("loadComponent", loadArgs); }
/// <summary> /// Loads the specified react component into the specified frame /// </summary> public void LoadComponent(IViewModule component, string frameName, bool hasStyleSheet, bool hasPlugins) { var mainSource = ViewRender.ToFullUrl(NormalizeUrl(component.MainJsSource)); var dependencySources = component.DependencyJsSources.Select(s => ViewRender.ToFullUrl(NormalizeUrl(s))).ToArray(); var cssSources = component.CssSources.Select(s => ViewRender.ToFullUrl(NormalizeUrl(s))).ToArray(); var componentSerialization = SerializeComponent(component); var componentHash = ComputeHash(componentSerialization); // loadComponent arguments: // // componentName: string, // componentNativeObjectName: string, // componentSource: string, // dependencySources: string[], // cssSources: string[], // maxPreRenderedCacheEntries: number, // hasStyleSheet: boolean, // hasPlugins: boolean, // componentNativeObject: Dictionary<any>, // frameName: string // componentHash: string var loadArgs = new[] { JavascriptSerializer.Serialize(component.Name), JavascriptSerializer.Serialize(component.GetNativeObjectFullName(frameName)), JavascriptSerializer.Serialize(mainSource), JavascriptSerializer.Serialize(dependencySources), JavascriptSerializer.Serialize(cssSources), JavascriptSerializer.Serialize(ReactView.PreloadedCacheEntriesSize), JavascriptSerializer.Serialize(hasStyleSheet), JavascriptSerializer.Serialize(hasPlugins), componentSerialization, JavascriptSerializer.Serialize(frameName), JavascriptSerializer.Serialize(componentHash), }; ExecuteLoaderFunction("loadComponent", loadArgs); }
public static string GetNativeObjectFullName(this IViewModule module, string frameName) { return("$" + (frameName == FrameInfo.MainViewFrameName ? frameName : frameName + "$") + module.NativeObjectName); }
/// <summary> /// Unregisters a .net object available on the js context. /// </summary> /// <param name="module"></param> /// <param name="frameName"></param> private void UnregisterNativeObject(IViewModule module, string frameName) { WebView.UnregisterJavascriptObject(module.GetNativeObjectFullName(frameName)); }
public T EvaluateMethod <T>(IViewModule module, string methodCall, params object[] args) { return(webView.EvaluateScriptFunctionWithSerializedParams <T>(ModulesObjectName + "." + module.Name + "." + methodCall, args)); }
public void ExecuteMethod(IViewModule module, string methodCall, params object[] args) { webView.ExecuteScriptFunctionWithSerializedParams(ModulesObjectName + "." + module.Name + "." + methodCall, args); }
public FrameInfo(string name) { Name = name; Plugins = new IViewModule[0]; ExecutionEngine = new ExecutionEngine(); }
public ViewModuleData(IViewModule viewModule, GameObject gameObject = null) { m_gameObject = gameObject; m_viewModule = viewModule; }
/// <summary> /// Registers a .net object to be available on the js context. /// </summary> /// <param name="module"></param> /// <param name="frameName"></param> private void RegisterNativeObject(IViewModule module, string frameName) { WebView.RegisterJavascriptObject(module.GetNativeObjectFullName(frameName), module.CreateNativeObject(), interceptCall: CallNativeMethod, executeCallsInUI: false); }
public T EvaluateMethod <T>(IViewModule module, string methodCall, params object[] args) => EvaluateMethodAsync <T>(module, methodCall, args).Result;
private string FormatMethodInvocation(IViewModule module, string methodCall) { return(ModulesObjectName + "(\"" + frameName + "\",\"" + id + "\",\"" + module.Name + "\")." + methodCall); }
/// <summary> /// Binds the coponent to the specified frame. /// </summary> /// <param name="component"></param> /// <param name="frame"></param> private void BindComponentToFrame(IViewModule component, FrameInfo frame) { frame.Component = component; component.Bind(frame, this); }
public Task <T> EvaluateMethodAsync <T>(IViewModule module, string methodCall, params object[] args) { if (webView == null) { return(Task.FromResult <T>(default));
public ExtendedReactView(IViewModule mainModule) : base(mainModule) { Settings.StylePreferenceChanged += OnStylePreferenceChanged; }