1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Test brut

This commit is contained in:
Yan Maniez 2019-05-13 18:18:15 +02:00
parent b4c43e6b96
commit af591afcb7

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using AideDeJeu.iOS;
using AideDeJeu.Views;
using Foundation;
@ -17,21 +18,23 @@ namespace AideDeJeu.iOS
{
public class PdfViewRenderer : ViewRenderer<PdfView, UIWebView>
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
protected override async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == "Uri")
{
LoadPdfJS();
var pdfView = Element as PdfView;
if (pdfView?.Uri != null)
{
await Task.Delay(1000);
LoadFile(pdfView.Uri);
}
}
}
protected override void OnElementChanged(ElementChangedEventArgs<PdfView> e)
protected override async void OnElementChanged(ElementChangedEventArgs<PdfView> e)
{
base.OnElementChanged(e);
@ -45,10 +48,12 @@ namespace AideDeJeu.iOS
}
if (e.NewElement != null)
{
LoadPdfJS();
var pdfView = Element as PdfView;
if (pdfView?.Uri != null)
{
await Task.Delay(1000);
LoadFile(pdfView.Uri);
}
}
@ -57,11 +62,15 @@ namespace AideDeJeu.iOS
void LoadFile(string fileName)
{
string filePath = Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, string.Format("pdf/{0}", WebUtility.UrlEncode(fileName)));
Control.LoadRequest(new NSUrlRequest(new NSUrl(filePath, false)));
Control.ScalesPageToFit = true;
//Control.LoadRequest(new NSUrlRequest(new NSUrl(filePath, false)));
//Control.ScalesPageToFit = true;
var bytes = File.ReadAllBytes(filePath);
Control.EvaluateJavascript($"PDFViewerApplication.open(new Uint8Array({bytes}))");
}
void LoadPdfJS(string fileName)
void LoadPdfJS()
{
string filePath = NSBundle.MainBundle.ResourceUrl.Append("pdfjs/web/viewer.html", false).Path;
//string filePath = Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, string.Format("pdf/{0}", WebUtility.UrlEncode(fileName)));