xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

WebView Navigating event never fired on IOS #15599

Open Entretoize opened 2 years ago

Entretoize commented 2 years ago

Description

I created a hybrid renderer like that:

[assembly: ExportRenderer(typeof(CustomWebView), typeof(HybridWebViewRenderer))]
namespace ClotureSiadForms.iOS.Renderer
{
    public class HybridWebViewRenderer : WkWebViewRenderer, IWKScriptMessageHandler
    {
...

With that CustomWebView class:

    public class CustomWebView : WebView
    {
        public string js="";
        public CustomWebView()
        {
            base.Navigating+= WebViewNavigating; //also tried from xaml
        }
        public void WebViewNavigating(object sender, WebNavigatingEventArgs args)
        {
            if (args.Url.StartsWith("tel:"))
            {
                var tel = args.Url.Split(':')[1];
                args.Cancel = true;

                Xamarin.Essentials.PhoneDialer.Open(tel);
            }
        }
    }

Steps to Reproduce

  1. Create a hybrid renderer for IOS
  2. Add a Navigating event callback
  3. Navigate to any webpage

Expected Behavior

The WebViewNavigating method should be called on each navigation change

Actual Behavior

WebViewNavigating is never called on IOS

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Community 2022 Version 17.3.6 VisualStudio.17.Release/17.3.6+32929.385 Microsoft .NET Framework Version 4.8.04084 Installed Version: Community Visual C++ 2022 00482-90000-00000-AA849 Microsoft Visual C++ 2022 ASP.NET and Web Tools 17.3.376.3011 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.3.376.3011 Azure App Service Tools v3.0.0 C# Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Cookiecutter 17.0.22179.3 Provides tools for finding, instantiating and customizing templates in cookiecutter format. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.3.20 (3f4cb00) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.3.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ NVIDIA CUDA 11.6 Wizards 11.6 Wizards to create new NVIDIA CUDA projects and source files. NVIDIA Nsight Visual Studio Edition 2022.1.1.22006 NVIDIA Nsight Visual Studio Edition provides tools for GPGPU and graphics development. Copyright © NVIDIA 2010 - 2022. •Direct3D® and DirectX® are registered trademarks of Microsoft Corporation in the United States and/or other countries. •Microsoft Detours is used under the Professional license (http://research.microsoft.com/en-us/projects/detours/). •Gardens Point Parser Generator Copyright 2005 Queensland University of Technology (QUT). All rights reserved. •Icons from Axialis Software used under the licensing terms found here: www.axialis.com •NLog Copyright © 2004-2006 Jaroslaw Kowalski (jaak@jkowalski.net) •zlib and libpng used under the zlib/libpnc license (http://opensource.org/licenses/Zlib) •Breakpad Copyright ©2006, Google Inc. All rights reserved. •The OpenGL Extension Wrangler Library Copyright ©2008-2016, Nigel Stewart (nigels@users.sourceforge.net), Copyright ©2002-2008, Milan Ikits (milan.ikits@ieee.org), Copyright ©2002-2008, Marcelo E. Magallon (mmagallo@debian.org), Copyright ©2002, Lev Povalahev. All rights reserved. •LIBSSH2 Copyright ©2004-2007 Sara Golemon (sarag@libssh2.org), Copyright ©2005,2006 Mikhail Gusarov (dottedmag@dottedmag.net),Copyright ©2006-2007 The Written Word, Inc.,Copyright ©2007 Eli Fant (elifantu@mail.ru),Copyright ©2009-2014 Daniel Stenberg., Copyright ©2008, 2009 Simon Josefsson. All rights reserved. •Protobuf Copyright ©2014, Google Inc. All rights reserved. •xxHASH Library Copyright ©2012-2014, Yann Collet. All rights reserved. •FMT Copyright ©2012 - 2016, Victor Zverovich •Font Awesome Copyright 2018 Fonticons, Inc. •ELF Definitions Copyright (c) 2010 Joseph Koshy, All rights reserved. Warning: This computer program is protected by copyright law and international treaties. Unauthorized reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under the law. NVIDIA Nsight Visual Studio Edition - CUDA support 2022.1.1.22006 NVIDIA Nsight Visual Studio Edition - CUDA support provides tools for CUDA development and debugging. Python - Django support 17.0.22179.3 Provides templates and integration for the Django web framework. Python - Profiling support 17.0.22179.3 Profiling support for Python projects. Python - VC Project Support 17.0.21344.1 Provides support for launching C++ projects with Python debugging enabled. Python with Pylance 17.0.22179.3 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers. Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387 Provides languages services for ASP.NET Core Razor. Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory. Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory. TypeScript Tools 17.0.10701.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078 Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. Visual Studio Tools for Unity 17.3.0.0 Visual Studio Tools for Unity VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info Xamarin 17.3.0.308 (d17-3@56b9f7e) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.3.0.217 (remotes/origin/d17-3@b81db1dcc0) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.2.28 (9b3d244) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63) Xamarin.Android Reference Assemblies and MSBuild support. Mono: dffa5ab Java.Interop: xamarin/java.interop/d17-3@7716ae53 SQLite: xamarin/sqlite/3.38.5@df4deab Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6 Xamarin.iOS and Xamarin.Mac SDK 16.0.0.75 (e4f48bed7) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Reproduction Link

https://linkall.pro/bin/ClotureSiadForms-master.zip

IvanMi773 commented 1 year ago

@Entretoize Do you have some workaround? Struggling with the same thing

Entretoize commented 1 year ago

No, never found sorry...

vp1512 commented 1 year ago

@Entretoize @IvanMi773

Did you find any workaround? I am also struggling with the same thing.

dasunmax89 commented 1 year ago

You have to handle wkWebView.NavigationDelegate = new ExtendedNavigatioDelegate(); in renderer commenting out also will pass to default handler