Coder Social home page Coder Social logo

Need to modify the HybridWebView configuration (BEFORE initializing) on iOS/MacCatalyst to fix known base WebView issue ... Any solution? about mauihybridwebview HOT 3 OPEN

eilon avatar eilon commented on September 15, 2024
Need to modify the HybridWebView configuration (BEFORE initializing) on iOS/MacCatalyst to fix known base WebView issue ... Any solution?

from mauihybridwebview.

Comments (3)

HelloooJoe avatar HelloooJoe commented on September 15, 2024 1

@Eilon Can you consider inviting other developers help maintain this repo that have contributed already? It seems like you're not giving this repo enough attention.

from mauihybridwebview.

Eilon avatar Eilon commented on September 15, 2024

@Eilon Can you consider inviting other developers help maintain this repo that have contributed already? It seems like you're not giving this repo enough attention.

I've been working on the official version here: #70

So for that reason my time hasn't been as focused here. Having said that, I'm certainly willing to work with people on features, fixes, and PRs within this repo for features that are good candidates to be in the official version.

from mauihybridwebview.

jonmdev avatar jonmdev commented on September 15, 2024

@Eilon Can you consider inviting other developers help maintain this repo that have contributed already? It seems like you're not giving this repo enough attention.

I've been working on the official version here: #70

So for that reason my time hasn't been as focused here. Having said that, I'm certainly willing to work with people on features, fixes, and PRs within this repo for features that are good candidates to be in the official version.

Congratulations on being officially included. Please keep in mind the issue reported in this thread, and if nothing else, please don't break this method without providing us an alternative.

Thanks again.

#if IOS || MACCATALYST

            HybridWebView.HybridWebViewHandler.PlatformViewFactory = (handler) => {
                
                var config = new WKWebViewConfiguration();
                //====================================================
                //CUSTOM CONFIG
                config.AllowsAirPlayForMediaPlayback = true;
                config.AllowsInlineMediaPlayback = true;
                config.AllowsPictureInPictureMediaPlayback = true;
                config.MediaTypesRequiringUserActionForPlayback = WebKit.WKAudiovisualMediaTypes.None;

                //simple enough can just redundancy this one:
                Action<Uri, string> MessageReceivedAction = delegate (Uri uri, string message) { // to replace https://github.com/Eilon/MauiHybridWebView/blob/3ca801076a1e3fbe3b8922b2429524df20def6a4/HybridWebView/Platforms/iOS/HybridWebViewHandler.iOS.cs#L40
                    ((HybridWebView.HybridWebView)handler.VirtualView).OnMessageReceived(message);
                };

                //https://stackoverflow.com/a/39076814/10305478
                object CreatePrivateClassInstance(string typeName, object[] parameters) {
                    Type type = AppDomain.CurrentDomain.GetAssemblies().
                             SelectMany(assembly => assembly.GetTypes()).FirstOrDefault(t => t.Name == typeName);
                    return type.GetConstructors()[0].Invoke(parameters);
                }

                IWKScriptMessageHandler webViewScriptMessageHandler = (IWKScriptMessageHandler)CreatePrivateClassInstance("WebViewScriptMessageHandler", [MessageReceivedAction]);
                config.UserContentController.AddScriptMessageHandler(webViewScriptMessageHandler, "webwindowinterop");

                IWKUrlSchemeHandler? wKUrlSchemeHandler = (IWKUrlSchemeHandler?)CreatePrivateClassInstance("SchemeHandler", [handler as HybridWebViewHandler]);
                config.SetUrlSchemeHandler(wKUrlSchemeHandler, urlScheme: "app");
                //============================================


                //default programming built in
                //config.UserContentController.AddScriptMessageHandler(new WebViewScriptMessageHandler(MessageReceived), "webwindowinterop");
                //config.SetUrlSchemeHandler(new SchemeHandler(this), urlScheme: "app");

                // Legacy Developer Extras setting.
                var enableWebDevTools = ((HybridWebView.HybridWebView)(handler as HybridWebViewHandler).VirtualView).EnableWebDevTools;
                config.Preferences.SetValueForKey(NSObject.FromObject(enableWebDevTools), new NSString("developerExtrasEnabled"));
                var platformView = new MauiWKWebView(RectangleF.Empty, handler as HybridWebViewHandler, config);

                if (OperatingSystem.IsMacCatalystVersionAtLeast(major: 13, minor: 3) ||
                    OperatingSystem.IsIOSVersionAtLeast(major: 16, minor: 4)) {
                    // Enable Developer Extras for Catalyst/iOS builds for 16.4+
                    platformView.SetValueForKey(NSObject.FromObject(enableWebDevTools), new NSString("inspectable"));
                }

                return platformView;
            };
#endif

from mauihybridwebview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.