Skip to content

Commit 903694a

Browse files
authored
Windows SDK update. (#67)
This PR holds the migration changes that come in windows SDK 1.1. Some small changes were need to ensure windows does not use prop-types in the library. For now this is not supported and I'd expect an updated version of react-native-windows to being support for it.
1 parent 598550d commit 903694a

File tree

10 files changed

+238
-202
lines changed

10 files changed

+238
-202
lines changed

index.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
2+
//
3+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
4+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
5+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
6+
// This notice may not be removed from this file.
7+
//
8+
9+
import PropTypes from "prop-types";
10+
import React from "react";
11+
import {
12+
requireNativeComponent,
13+
Platform,
14+
findNodeHandle,
15+
UIManager
16+
} from "react-native";
17+
18+
class PSPDFKitView extends React.Component {
19+
render() {
20+
if (Platform.OS === "ios" || Platform.OS === "android") {
21+
const onCloseButtonPressedHandler = this.props.onCloseButtonPressed
22+
? event => {
23+
this.props.onCloseButtonPressed(event.nativeEvent);
24+
}
25+
: null;
26+
return (
27+
<RCTPSPDFKitView
28+
ref="pdfView"
29+
{...this.props}
30+
onCloseButtonPressed={onCloseButtonPressedHandler}
31+
onStateChanged={this._onStateChanged}
32+
/>
33+
);
34+
} else {
35+
return null;
36+
}
37+
}
38+
39+
_onStateChanged = event => {
40+
if (this.props.onStateChanged) {
41+
this.props.onStateChanged(event.nativeEvent);
42+
}
43+
};
44+
45+
/**
46+
* Enters the annotation creation mode, showing the annotation creation toolbar.
47+
*
48+
* @platform android
49+
*/
50+
enterAnnotationCreationMode = function () {
51+
UIManager.dispatchViewManagerCommand(
52+
findNodeHandle(this.refs.pdfView),
53+
UIManager.RCTPSPDFKitView.Commands.enterAnnotationCreationMode,
54+
[]
55+
);
56+
};
57+
58+
/**
59+
* Exits the currently active mode, hiding all toolbars.
60+
*
61+
* @platform android
62+
*/
63+
exitCurrentlyActiveMode = function () {
64+
UIManager.dispatchViewManagerCommand(
65+
findNodeHandle(this.refs.pdfView),
66+
UIManager.RCTPSPDFKitView.Commands.exitCurrentlyActiveMode,
67+
[]
68+
);
69+
};
70+
}
71+
72+
PSPDFKitView.propTypes = {
73+
/**
74+
* Path to the PDF file that should be displayed.
75+
*/
76+
document: PropTypes.string,
77+
/**
78+
* Configuration object, to customize the appearance and behavior of PSPDFKit.
79+
* See https://pspdfkit.com/guides/ios/current/getting-started/pspdfconfiguration/ for more information.
80+
*
81+
* Note: On iOS, set `useParentNavigationBar` to `true`, to use the parent navigation bar instead of creating its own,
82+
* if the view is already contained in a navigation controller (like when using NavigatorIOS, react-native-navigation, ...).
83+
*/
84+
configuration: PropTypes.object,
85+
/**
86+
* Page index of the document that will be shown.
87+
*/
88+
pageIndex: PropTypes.number,
89+
/**
90+
* Controls wheter a navigation bar is created and shown or not. Defaults to showing a navigation bar (false).
91+
*
92+
* @platform ios
93+
*/
94+
hideNavigationBar: PropTypes.bool,
95+
/**
96+
* Whether the close button should be shown in the navigation bar. Disabled by default.
97+
* Will call `onCloseButtonPressed` if it was provided, when tapped.
98+
* If `onCloseButtonPressed` was not provided, PSPDFKitView will be automatically dismissed.
99+
*
100+
* @platform ios
101+
*/
102+
showCloseButton: PropTypes.bool,
103+
/**
104+
* Callback that is called when the user tapped the close button.
105+
* If you provide this function, you need to handle dismissal yourself.
106+
* If you don't provide this function, PSPDFKitView will be automatically dismissed.
107+
*
108+
* @platform ios
109+
*/
110+
onCloseButtonPressed: PropTypes.func,
111+
/**
112+
* Callback that is called when the state of the PSPDFKitView changes.
113+
* Returns an object with the following structure:
114+
* {
115+
* documentLoaded: bool,
116+
* currentPageIndex: int,
117+
* pageCount: int,
118+
* annotationCreationActive: bool,
119+
* annotationEditingActive: bool,
120+
* textSelectionActive: bool,
121+
* formEditingActive: bool,
122+
* }
123+
*
124+
* @platform android
125+
*/
126+
onStateChanged: PropTypes.func,
127+
128+
/**
129+
* fragmentTag: A tag used to identify a single PdfFragment in the view hierarchy.
130+
* This needs to be unique in the view hierarchy.
131+
*
132+
* @platform android
133+
*/
134+
fragmentTag: PropTypes.string
135+
};
136+
137+
if (Platform.OS === "ios" || Platform.OS === "android") {
138+
var RCTPSPDFKitView = requireNativeComponent(
139+
"RCTPSPDFKitView",
140+
PSPDFKitView,
141+
{
142+
nativeOnly: {
143+
testID: true,
144+
accessibilityComponentType: true,
145+
renderToHardwareTextureAndroid: true,
146+
accessibilityLabel: true,
147+
accessibilityLiveRegion: true,
148+
importantForAccessibility: true,
149+
onLayout: true,
150+
nativeID: true
151+
}
152+
}
153+
);
154+
module.exports = PSPDFKitView;
155+
}

index.windows.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
2+
//
3+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
4+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
5+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
6+
// This notice may not be removed from this file.
7+
//
8+
import { requireNativeComponent } from "react-native";
9+
10+
module.exports = requireNativeComponent("ReactPSPDFKitView", null);

js/index.js

Lines changed: 0 additions & 157 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"email": "[email protected]"
1414
},
1515
"license": "SEE LICENSE IN LICENSE",
16-
"main": "js/index.js",
1716
"repository": {
1817
"type": "git",
1918
"url": "https://github.com/PSPDFKit/react-native.git"

samples/Catalog/windows/Catalog/Catalog.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
225225
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
226226
</SDKReference>
227-
<SDKReference Include="PSPDFKitSDK, Version=1.0">
227+
<SDKReference Include="PSPDFKitSDK, Version=1.0.2">
228228
<Name>PSPDFKit for UWP</Name>
229229
</SDKReference>
230230
</ItemGroup>
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using PSPDFKit;
2-
using System;
1+
using System;
32
using System.Threading.Tasks;
4-
using Windows.UI.Xaml;
3+
using PSPDFKit.Document;
4+
using PSPDFKit.UI;
5+
using Windows.Storage;
6+
using Windows.UI.Popups;
57
using Windows.UI.Xaml.Controls;
68

79
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -14,19 +16,35 @@ namespace ReactNativePSPDFKit
1416
public sealed partial class PDFViewPage : Page
1517
{
1618

17-
API _API;
18-
string _license;
19+
Controller _controller;
20+
const string _css = "ms-appx-web:///Assets/pspdfkit/windows.css";
1921

20-
public PDFViewPage(API api, string license)
22+
public PDFViewPage()
2123
{
22-
_API = api;
23-
_license = license;
2424
InitializeComponent();
2525
}
2626

2727
private void PDFView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
2828
{
29-
_API.InitializeWithWebView(_license, "", sender);
29+
_controller = new Controller(sender, _css);
30+
}
31+
32+
/// <summary>
33+
/// Take the file and call the conroller to open the document.
34+
/// </summary>
35+
/// <param name="file">File to open.</param>
36+
internal async void OpenFile(StorageFile file)
37+
{
38+
try
39+
{
40+
await _controller.ShowDocumentAsync(DocumentSource.CreateFromStorageFile(file));
41+
}
42+
catch (Exception e)
43+
{
44+
// Show a dialog with the exception message.
45+
var dialog = new MessageDialog(e.Message);
46+
await dialog.ShowAsync();
47+
}
3048
}
3149
}
3250
}

0 commit comments

Comments
 (0)