Skip to content

Commit 98d45d4

Browse files
authored
UWP issue when no document is passed. (#114)
As a response to https://github.com/PSPDFKit/react-native/issues/112 an issue was found when not passing document from JS. I believe this should be an optional feature therefore this PR fixes this. No document will attempt to load by default if document is not present. In addition to this, some library alignment were made and copyrights updated.
1 parent d2c6fee commit 98d45d4

File tree

7 files changed

+55
-30
lines changed

7 files changed

+55
-30
lines changed

samples/Catalog/windows/Catalog/Catalog.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@
234234
<Name>PSPDFKit for UWP</Name>
235235
</SDKReference>
236236
</ItemGroup>
237-
<ItemGroup>
238-
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
239-
<Version>6.1.5</Version>
240-
</PackageReference>
241-
</ItemGroup>
242237
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
243238
<VisualStudioVersion>14.0</VisualStudioVersion>
244239
</PropertyGroup>
@@ -254,4 +249,4 @@
254249
<Target Name="AfterBuild">
255250
</Target>
256251
-->
257-
</Project>
252+
</Project>

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:ui="using:PSPDFKit.UI">
66

7-
<ui:PdfView License="{StaticResource PSPDFKitLicense}" Name="PDFView"/>
7+
<ui:PdfView License="{StaticResource PSPDFKitLicense}" Name="PDFView" InitializationCompletedHandler="PDFView_InitializationCompletedHandlerAsync"/>
88
</Page>

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
using System;
1+
//
2+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
10+
using System;
211
using System.Threading.Tasks;
312
using PSPDFKit.Document;
413
using PSPDFKit.UI;
514
using Windows.Storage;
615
using Windows.UI.Popups;
716
using Windows.UI.Xaml.Controls;
817

9-
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
10-
1118
namespace ReactNativePSPDFKit
1219
{
1320
public sealed partial class PDFViewPage : Page
1421
{
15-
private ViewState _viewStateCache = new ViewState();
22+
private readonly ViewState _viewStateCache = new ViewState();
1623
private StorageFile _fileToOpen = null;
1724
private bool _pdfViewInitialised = false;
1825

1926
public PDFViewPage()
2027
{
2128
InitializeComponent();
22-
23-
PDFView.InitializationCompletedHandler += PDFView_InitializationCompletedHandlerAsync;
2429
}
2530

2631
/// <summary>
@@ -31,11 +36,12 @@ internal async Task OpenFileAsync(StorageFile file)
3136
{
3237
_fileToOpen = file;
3338

39+
// If the PdfView is already initialised we can show the new document.
3440
if(_pdfViewInitialised)
3541
{
3642
try
3743
{
38-
await PDFView.Controller.ShowDocumentAsync(DocumentSource.CreateFromStorageFile(file));
44+
await PDFView.Controller.ShowDocumentWithViewStateAsync(DocumentSource.CreateFromStorageFile(file), _viewStateCache);
3945
}
4046
catch (Exception e)
4147
{
@@ -50,6 +56,7 @@ internal async Task SetPageIndexAsync(int index)
5056
{
5157
_viewStateCache.CurrentPageIndex = index;
5258

59+
// If the PdfView is already initialised we can change the page index.
5360
if (_pdfViewInitialised)
5461
{
5562
await PDFView.Controller.SetCurrentPageIndexAsync(index);
@@ -63,9 +70,13 @@ internal void SetShowToolbar(bool showToolbar)
6370
PDFView.ShowToolbar = showToolbar;
6471
}
6572

66-
private async void PDFView_InitializationCompletedHandlerAsync(PdfView sender, PSPDFKit.Pdf.Document args)
73+
private async void PDFView_InitializationCompletedHandlerAsync(PdfView sender, PSPDFKit.Pdf.Document document)
6774
{
68-
await PDFView.Controller.ShowDocumentWithViewStateAsync(DocumentSource.CreateFromStorageFile(_fileToOpen), _viewStateCache);
75+
// If we already have a file to open lets proceed with that here.
76+
if (_fileToOpen != null)
77+
{
78+
await PDFView.Controller.ShowDocumentWithViewStateAsync(DocumentSource.CreateFromStorageFile(_fileToOpen), _viewStateCache);
79+
}
6980
_pdfViewInitialised = true;
7081
}
7182
}

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitModule.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
using PSPDFKit.Document;
2-
using PSPDFKit.UI;
1+
//
2+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
310
using ReactNative.Bridge;
411
using System;
512
using System.Collections.Generic;
@@ -13,7 +20,7 @@ namespace ReactNativePSPDFKit
1320
/// </summary>
1421
class PSPDFKitModule : ReactContextNativeModuleBase
1522
{
16-
private PSPDFKitViewManger _pspdfKitViewManger;
23+
private readonly PSPDFKitViewManger _pspdfKitViewManger;
1724
private string VERSION_KEY = "versionString";
1825

1926
public PSPDFKitModule(ReactContext reactContext, PSPDFKitViewManger pspdfKitViewManger) : base(reactContext)

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitPackage.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
using PSPDFKit;
2-
using PSPDFKit.Pdf;
3-
using PSPDFKit.UI;
1+
//
2+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
410
using ReactNative.Bridge;
511
using ReactNative.Modules.Core;
612
using ReactNative.UIManager;
@@ -17,7 +23,7 @@ namespace ReactNativePSPDFKit
1723
/// </summary>
1824
public class PSPDFKitPackage : IReactPackage
1925
{
20-
private PSPDFKitViewManger _pspdfkitViewManger = new PSPDFKitViewManger();
26+
private readonly PSPDFKitViewManger _pspdfkitViewManger = new PSPDFKitViewManger();
2127

2228
/// <summary>
2329
/// Creates the PSPDFKitModule native modules to register with the react

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
using System;
1+
//
2+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
10+
using System;
211
using System.Threading.Tasks;
3-
using PSPDFKit;
4-
using PSPDFKit.Document;
5-
using PSPDFKit.UI;
612
using ReactNative.UIManager;
713
using ReactNative.UIManager.Annotations;
814
using Windows.Storage;

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/ReactNativePSPDFKit.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@
115115
</ItemGroup>
116116
<ItemGroup>
117117
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
118-
<Version>6.1.5</Version>
118+
<Version>6.0.8</Version>
119119
</PackageReference>
120120
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
121-
<Version>3.0.0</Version>
121+
<Version>4.0.0</Version>
122122
</PackageReference>
123123
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
124124
<Version>2.0.0</Version>
@@ -158,4 +158,4 @@
158158
<Target Name="AfterBuild">
159159
</Target>
160160
-->
161-
</Project>
161+
</Project>

0 commit comments

Comments
 (0)