From 8311919fcf65ae732a46be0dedab91d7b949645e Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Sun, 12 May 2019 13:33:56 +0200 Subject: [PATCH] =?UTF-8?q?PdfView=20iOS=20=C3=A0=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj | 1 + AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs diff --git a/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj b/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj index 61cc15d8..b5baf4c2 100644 --- a/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj +++ b/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj @@ -105,6 +105,7 @@ + Always diff --git a/AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs b/AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs new file mode 100644 index 00000000..46edfb50 --- /dev/null +++ b/AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using AideDeJeu.Views; +using Foundation; +using UIKit; +using Xamarin.Forms.Platform.iOS; + +namespace AideDeJeu.iOS +{ + public class PdfViewRenderer : ViewRenderer + { + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + + if(e.PropertyName == "Uri") + { + var pdfView = Element as PdfView; + + if (pdfView?.Uri != null) + { + LoadFile(pdfView.Uri); + } + } + } + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + if (Control == null) + { + SetNativeControl(new UIWebView()); + } + if (e.OldElement != null) + { + // Cleanup + } + if (e.NewElement != null) + { + var pdfView = Element as PdfView; + + if (pdfView?.Uri != null) + { + LoadFile(pdfView.Uri); + } + } + } + + void LoadFile(string fileName) + { + string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), string.Format("pdf/{0}", WebUtility.UrlEncode(fileName))); + Control.LoadRequest(new NSUrlRequest(new NSUrl(filePath, false))); + Control.ScalesPageToFit = true; + } + } +} \ No newline at end of file