示例#1
0
        private void SetupControl()
        {
            _navigationDelegate = new HybridWebViewNavigationDelegate(this);
            _contentController  = new WKUserContentController();
            _contentController.AddScriptMessageHandler(this, "invokeAction");
            _configuration = new WKWebViewConfiguration
            {
                UserContentController     = _contentController,
                AllowsInlineMediaPlayback = true
            };


            var wkWebView = new WKWebView(Frame, _configuration)
            {
                Opaque             = false,
                UIDelegate         = this,
                NavigationDelegate = _navigationDelegate,
            };


            HybridWebViewControl.CallbackAdded += OnCallbackAdded;

            SetNativeControl(wkWebView);
            SetUserAgent();
            OnControlChanged?.Invoke(this, wkWebView);
        }
示例#2
0
        private void SetupControl()
        {
            _navigationDelegate = new HybridWebViewNavigationDelegate(this);
            _contentController  = new WKUserContentController();
            _contentController.AddScriptMessageHandler(this, "invokeAction");

            _contentController.AddUserScript(new WKUserScript(
                                                 (NSString)HybridWebViewControl.InjectedFunction,
                                                 WKUserScriptInjectionTime.AtDocumentStart,
                                                 true));

            if (!string.IsNullOrEmpty(Element.InjectScript))
            {
                _contentController.AddUserScript(new WKUserScript(
                                                     (NSString)Element.InjectScript,
                                                     WKUserScriptInjectionTime.AtDocumentStart,
                                                     true));
            }

            _configuration = new WKWebViewConfiguration
            {
                UserContentController     = _contentController,
                AllowsInlineMediaPlayback = true
            };

            var wkWebView = new WKWebView(Frame, _configuration)
            {
                Opaque             = false,
                UIDelegate         = this,
                NavigationDelegate = _navigationDelegate,
            };

            HybridWebViewControl.CallbackAdded += OnCallbackAdded;

            SetNativeControl(wkWebView);
            SetUserAgent();
            OnControlChanged?.Invoke(this, wkWebView);
        }