mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Test brut
This commit is contained in:
		
							parent
							
								
									b4c43e6b96
								
							
						
					
					
						commit
						af591afcb7
					
				
					 1 changed files with 14 additions and 5 deletions
				
			
		|  | @ -5,6 +5,7 @@ using System.IO; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Net; | using System.Net; | ||||||
| using System.Text; | using System.Text; | ||||||
|  | using System.Threading.Tasks; | ||||||
| using AideDeJeu.iOS; | using AideDeJeu.iOS; | ||||||
| using AideDeJeu.Views; | using AideDeJeu.Views; | ||||||
| using Foundation; | using Foundation; | ||||||
|  | @ -17,21 +18,23 @@ namespace AideDeJeu.iOS | ||||||
| { | { | ||||||
|     public class PdfViewRenderer : ViewRenderer<PdfView, UIWebView> |     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); |             base.OnElementPropertyChanged(sender, e); | ||||||
| 
 | 
 | ||||||
|             if(e.PropertyName == "Uri") |             if(e.PropertyName == "Uri") | ||||||
|             { |             { | ||||||
|  |                 LoadPdfJS(); | ||||||
|                 var pdfView = Element as PdfView; |                 var pdfView = Element as PdfView; | ||||||
| 
 | 
 | ||||||
|                 if (pdfView?.Uri != null) |                 if (pdfView?.Uri != null) | ||||||
|                 { |                 { | ||||||
|  |                     await Task.Delay(1000); | ||||||
|                     LoadFile(pdfView.Uri); |                     LoadFile(pdfView.Uri); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         protected override void OnElementChanged(ElementChangedEventArgs<PdfView> e) |         protected override async void OnElementChanged(ElementChangedEventArgs<PdfView> e) | ||||||
|         { |         { | ||||||
|             base.OnElementChanged(e); |             base.OnElementChanged(e); | ||||||
| 
 | 
 | ||||||
|  | @ -45,10 +48,12 @@ namespace AideDeJeu.iOS | ||||||
|             } |             } | ||||||
|             if (e.NewElement != null) |             if (e.NewElement != null) | ||||||
|             { |             { | ||||||
|  |                 LoadPdfJS(); | ||||||
|                 var pdfView = Element as PdfView; |                 var pdfView = Element as PdfView; | ||||||
| 
 | 
 | ||||||
|                 if (pdfView?.Uri != null) |                 if (pdfView?.Uri != null) | ||||||
|                 { |                 { | ||||||
|  |                     await Task.Delay(1000); | ||||||
|                     LoadFile(pdfView.Uri); |                     LoadFile(pdfView.Uri); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | @ -57,11 +62,15 @@ namespace AideDeJeu.iOS | ||||||
|         void LoadFile(string fileName) |         void LoadFile(string fileName) | ||||||
|         { |         { | ||||||
|             string filePath = Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, string.Format("pdf/{0}", WebUtility.UrlEncode(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.LoadRequest(new NSUrlRequest(new NSUrl(filePath, false))); | ||||||
|             Control.ScalesPageToFit = true; |             //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 = 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))); |             //string filePath = Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, string.Format("pdf/{0}", WebUtility.UrlEncode(fileName))); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez