maui: [regression/8.0.3] [iOS] [SDK 17] Touch events are not working on WebView when a PDF is displayed.
Description
With iOS Sdk 17 / XCode 15, the WebView on iOS doesn’t respond to any touch events (no zoom or scroll is possible) with PDF file. Works fine with any other html content.
Steps to Reproduce
- Create a new Maui App
- Add a web view control under a Grid Element to the Xaml
<Grid>
<WebView Grid.Row="0" x:Name="WebView"
Source="https://www.africau.edu/images/default/sample.pdf">
</WebView>
</Grid>
- Launch the App on iOS (16 or 17)
Actual: PDF file is rendered but no touch events are working on WebView (No scroll, no Zoom).
Expected: Should be able to zoom or scroll.
Notes:
- Rendering a webpage works fine without any issue (e.g. www.bing.com)
- This worked fine before updating to Microsoft.iOS SDK / XCode 15 for SDK 17
- Tested on .Net Maui Workload (8.0.0-rc.2.9511, 8.0.0-rc.2.9530) and both are impacted.
Link to public reproduction project repository
No response
Version with bug
8.0.0-rc.2.9511
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.0-rc.2.9373
Affected platforms
iOS
Affected platform versions
iOS (All versions)
Did you find any workaround?
No 😦
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (6 by maintainers)
I can confirm that it is fixed in 8.060 nightly build.
A slightly more involved solution, but I ended up resolving this by creating a custom control that implements PDFView from PDFKit instead of using WkWebView for iOS.
This solution provides an equal user experience and allows you to leverage the other features of PDFKit if needed.
This repo by @vitalii-vov has a great example on how you can implement this: https://github.com/vitalii-vov/Maui.PDFView/blob/master/Maui.PDFView/Platforms/iOS/PdfViewHandler.cs
For the Android implementation of this control, I used a WebView with pdf.js by Mozilla.
This blog outlines how you can implement pdf.js in Xamarin.Forms: https://medium.com/medialesson/show-pdf-files-in-your-xamarin-android-app-3718148de1c0
These steps can be adapted to use .NET MAUI handlers fairly simply.
I didn’t need to implement this control for Mac or Windows but imagine PDFKit would work the same for Mac and a similar WebView solution would work for Windows.
For more info on creating custom controls from scratch see Create a custom control using handlers.
Hello @last-Programmer ,
i created a ViewHandler for iOS: Here is the Code:
`using CoreGraphics; using Foundation; using Microsoft.Maui.Handlers; using PlentycoMaui.Logger; using UIKit; using WebKit;
namespace PlentycoMaui.iOS;
public class PdfViewHandler : ViewHandler<IPdfView, WKWebView> { private static readonly PropertyMapper<IPdfView, PdfViewHandler> PfgViewMapper = new(ViewMapper); private WKWebView _wkWebView; private UIButton _closeButton; private const int ButtonSize = 50; public PdfViewHandler() : base(PfgViewMapper) { }
}`