예제 #1
0
 /// <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);
     }
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
 public void LoadComponent(IViewModule component)
 {
     this.component = component;
     if (pageLoaded)
     {
         InternalLoadComponent();
     }
 }
예제 #5
0
 /// <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);
     }
 }
예제 #6
0
            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)));
            }
예제 #7
0
        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));
        }
예제 #8
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();
        }
예제 #9
0
 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));
     }
 }
예제 #10
0
 /// <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);
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
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);
        }
예제 #13
0
            /// <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);
            }
예제 #14
0
            /// <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);
            }
예제 #15
0
 public static string GetNativeObjectFullName(this IViewModule module, string frameName)
 {
     return("$" + (frameName == FrameInfo.MainViewFrameName ? frameName : frameName + "$") + module.NativeObjectName);
 }
예제 #16
0
 /// <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));
 }
예제 #17
0
 public T EvaluateMethod <T>(IViewModule module, string methodCall, params object[] args)
 {
     return(webView.EvaluateScriptFunctionWithSerializedParams <T>(ModulesObjectName + "." + module.Name + "." + methodCall, args));
 }
예제 #18
0
 public void ExecuteMethod(IViewModule module, string methodCall, params object[] args)
 {
     webView.ExecuteScriptFunctionWithSerializedParams(ModulesObjectName + "." + module.Name + "." + methodCall, args);
 }
예제 #19
0
 public FrameInfo(string name)
 {
     Name            = name;
     Plugins         = new IViewModule[0];
     ExecutionEngine = new ExecutionEngine();
 }
예제 #20
0
 public ViewModuleData(IViewModule viewModule, GameObject gameObject = null)
 {
     m_gameObject = gameObject;
     m_viewModule = viewModule;
 }
예제 #21
0
 /// <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);
 }
예제 #22
0
 public T EvaluateMethod <T>(IViewModule module, string methodCall, params object[] args) => EvaluateMethodAsync <T>(module, methodCall, args).Result;
예제 #23
0
 private string FormatMethodInvocation(IViewModule module, string methodCall)
 {
     return(ModulesObjectName + "(\"" + frameName + "\",\"" + id + "\",\"" + module.Name + "\")." + methodCall);
 }
예제 #24
0
 /// <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);
 }
예제 #25
0
 public Task <T> EvaluateMethodAsync <T>(IViewModule module, string methodCall, params object[] args)
 {
     if (webView == null)
     {
         return(Task.FromResult <T>(default));
예제 #26
0
 public ExtendedReactView(IViewModule mainModule) : base(mainModule)
 {
     Settings.StylePreferenceChanged += OnStylePreferenceChanged;
 }