Skip to content

Commit b2b0e17

Browse files
authored
Re-implement Css Customization (#221)
As explained in #219 (comment) due to limitations with file permissions in UWP it was necessary to rework the CSS customization. Therefore now the viable solution is to provide a native option. In this PR I have reverted the previous CSS work and added the option to start the PSPDFKit react native package with a Uri parameter which will be passed as the CSS resource. Within this CSS resource, it's possible to set the main colors of the toolbar. As before.
1 parent fec925d commit b2b0e17

File tree

14 files changed

+91
-155
lines changed

14 files changed

+91
-155
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,24 @@ Opens a document in the available `<PSPDFKitView>`. If the element is not displa
794794
PSPDFKit.Present("ms-appx:///Assets/pdf/Business Report.pdf");
795795
```
796796
797+
#### Theming support
798+
799+
It is possible to theme/customize the PdfView with the use of a CSS file. To do this simple pass a `Uri` within the web context to the instantiated [`PSPDFKitPackage`](https://github.com/PSPDFKit/react-native/blob/master/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitPackage.cs#L32).
800+
801+
To see this in action, make the following changes in [`samples/Catalog/windows/Catalog/MainReactNativeHost.cs`](https://github.com/PSPDFKit/react-native/blob/master/samples/Catalog/windows/Catalog/MainReactNativeHost.cs) and run the catalog the catalog.
802+
```diff
803+
protected override List<IReactPackage> Packages => new List<IReactPackage>
804+
{
805+
new MainReactPackage(),
806+
- new ReactNativePSPDFKit.PSPDFKitPackage(),
807+
+ new ReactNativePSPDFKit.PSPDFKitPackage(new Uri("ms-appx-web:///Assets/css/greenTheme.css")),
808+
new RNFSPackage()
809+
};
810+
```
811+
The code above will pass an asset held in the `Catalog` project's `Assets/css` to the web context of PSPDFKit for Windows. The file can then be used to theme the view.
812+
813+
For more information on CSS Customization in PSPDFKit for Windows please refer to [CSS Customization](https://pspdfkit.com/guides/windows/current/customizing-the-interface/css-customization/)
814+
797815
## License
798816
799817
This project can be used for evaluation or if you have a valid PSPDFKit license.

index.windows.js

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,22 @@ import {
1111
requireNativeComponent,
1212
ViewPropTypes,
1313
findNodeHandle,
14-
UIManager,
15-
processColor
14+
UIManager
1615
} from "react-native";
1716

1817
class PSPDFKitView extends React.Component {
1918
_nextRequestId = 1;
2019
_requestMap = new Map();
2120

22-
state = {
23-
pdfStyle: {
24-
highlightColor: null,
25-
primaryColor: null,
26-
primaryDarkColor: null
27-
},
28-
style: ViewPropTypes.style
29-
};
30-
31-
constructor(props) {
32-
super(props);
33-
34-
this.state.pdfStyle.highlightColor = processColor(props.style.highlightColor);
35-
delete props.style.highlightColor;
36-
this.state.pdfStyle.primaryColor = processColor(props.style.primaryColor);
37-
delete props.style.primaryColor;
38-
this.state.pdfStyle.primaryDarkColor = processColor(props.style.primaryDarkColor);
39-
delete props.style.primaryDarkColor;
40-
41-
this.state.style = props.style;
42-
}
43-
4421
render() {
4522
return (
4623
<RCTPSPDFKitView
4724
ref="pdfView"
48-
document={this.props.document}
49-
pageIndex={this.props.pageIndex}
50-
hideNavigationBar={this.props.hideNavigationBar}
25+
{...this.props}
5126
onAnnotationsChanged={this._onAnnotationsChanged}
5227
onDataReturned={this._onDataReturned}
5328
onOperationResult={this._onOperationResult}
54-
pdfStyle={this.state.pdfStyle}
55-
style={this.state.style}/>
29+
/>
5630
);
5731
}
5832

@@ -256,13 +230,6 @@ class PSPDFKitView extends React.Component {
256230
}
257231
}
258232

259-
const PDFStylePropTypes = PropTypes.shape({
260-
highlightColor: PropTypes.string,
261-
primaryColor: PropTypes.string,
262-
primaryDarkColor: PropTypes.string,
263-
...ViewPropTypes.style
264-
});
265-
266233
PSPDFKitView.propTypes = {
267234
/**
268235
* Path to the PDF file that should be displayed.
@@ -285,19 +252,7 @@ PSPDFKitView.propTypes = {
285252
* }
286253
*/
287254
onAnnotationsChanged: PropTypes.func,
288-
/**
289-
* Holds the standard style properties as expected plus extra pdf view style specific properties.
290-
* Styles the pdf view in accordance to https://pspdfkit.com/guides/windows/current/customizing-the-interface/css-customization/
291-
*
292-
* Expects optional values of.
293-
* {
294-
* highlightColor: PropTypes.string, | Highlight or hover color.
295-
* primaryColor: PropTypes.string, | Color for the main toolbar
296-
* primaryDarkColor: PropTypes.string | Color for the second toolbar
297-
* ...ViewPropTypes.style | Standard style props
298-
* }
299-
*/
300-
style: PDFStylePropTypes
255+
...ViewPropTypes
301256
};
302257

303258
const RCTPSPDFKitView = requireNativeComponent(

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.23.9",
3+
"version": "1.23.10",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/Catalog.windows.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
Image,
1616
TouchableHighlight,
1717
NativeModules,
18-
Button
18+
Button,
19+
Linking
1920
} from "react-native";
2021
import {StackNavigator} from "react-navigation";
2122
import PSPDFKitView from "react-native-pspdfkit";
@@ -86,15 +87,15 @@ const examples = [
8687
{
8788
key: "item1",
8889
name: "Open assets document",
89-
description: "Opens a document from your project assets folder",
90+
description: "Open document from your project assets folder",
9091
action: component => {
9192
component.props.navigation.navigate("PdfView");
9293
}
9394
},
9495
{
9596
key: "item2",
9697
name: "Present a file from source",
97-
description: "Opens a document from assets with Present",
98+
description: "Open document from source",
9899
action: component => {
99100
component.props.navigation.navigate("PdfView");
100101
// Present can only take files loaded in the Visual studio Project's Assets. Please use RNFS.
@@ -177,20 +178,13 @@ const examples = [
177178
{
178179
key: "item8",
179180
name: "Custom colors",
180-
description: "Supplies different colors for Pdf View Toolbar.",
181+
description: "Explains how to theme your UWP react native application.",
181182
action: component => {
182183
component.props.navigation.navigate("PdfViewStyle");
183184
}
184185
}
185186
];
186187

187-
const pdfStyle = {
188-
flex: 1,
189-
highlightColor: "#61D800", /* Highlight or hover color. */
190-
primaryColor: "red", /* Color for the main toolbar */
191-
primaryDarkColor: "rgb(255, 0, 255)" /* Color for the second toolbar */
192-
};
193-
194188
const styles = StyleSheet.create({
195189
page: {
196190
flex: 1,
@@ -249,7 +243,19 @@ const styles = StyleSheet.create({
249243
flexDirection: "row",
250244
justifyContent: "space-between",
251245
alignItems: "center"
252-
}
246+
},
247+
container: {
248+
flex: 1,
249+
justifyContent: 'center',
250+
alignItems: 'center',
251+
backgroundColor: "white",
252+
},
253+
stlyeExplanation: {
254+
color: "#666666",
255+
fontSize: 16,
256+
textAlign: 'center',
257+
margin: 50
258+
},
253259
});
254260

255261
class CatalogScreen extends Component<{}> {
@@ -310,7 +316,8 @@ class PdfViewScreen extends Component<{}> {
310316
ref="pdfView"
311317
style={styles.pdfView}
312318
// The default file to open.
313-
document="ms-appx:///Assets/pdf/annualReport.pdf"/>
319+
document="ms-appx:///Assets/pdf/annualReport.pdf"
320+
/>
314321
<View style={styles.footer}>
315322
<View style={styles.button}>
316323
<Button onPress={() => PSPDFKit.OpenFilePicker()} title="Open"/>
@@ -463,12 +470,21 @@ class PdfViewStyleScreen extends Component<{}> {
463470
render() {
464471
return (
465472
<View style={styles.page}>
466-
<PSPDFKitView
467-
ref="pdfView"
468-
style={pdfStyle}
469-
// The default file to open.
470-
document="ms-appx:///Assets/pdf/annualReport.pdf"/>
473+
<View style={styles.container}>
474+
<Text style={styles.stlyeExplanation}>
475+
Native changes are needed to customize the PdfView. Please follow the setups shown in the{" "}
476+
<Text
477+
style={{color: 'blue'}}
478+
onPress={() => {
479+
Linking.openURL('https://github.com/PSPDFKit/react-native/blob/master/README.md#theming-support')
480+
}}
481+
>
482+
README
483+
</Text>
484+
</Text>
485+
</View>
471486
<View style={styles.footer}>
487+
472488
<Image
473489
source={require("./assets/logo-flat.png")}
474490
style={styles.logo}
@@ -482,7 +498,6 @@ class PdfViewStyleScreen extends Component<{}> {
482498
}
483499
}
484500

485-
486501
export default StackNavigator(
487502
{
488503
Catalog: {
@@ -502,7 +517,7 @@ export default StackNavigator(
502517
},
503518
PdfViewStyle: {
504519
screen: PdfViewStyleScreen
505-
},
520+
}
506521
},
507522
{
508523
initialRouteName: "Catalog"

samples/Catalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Catalog",
3-
"version": "1.23.9",
3+
"version": "1.23.10",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Main Toolbar */
2+
@import url("../pspdfkit/windows.css");
3+
4+
:root {
5+
--primary: #61D800; /* Hightlight or hover color. */
6+
--primary-dark-1: #09AF00; /* Color for the main toolbar */
7+
--primary-dark-2: #008B00; /* Color for the secondard toolbar */
8+
}

samples/Catalog/windows/Catalog/Catalog.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
<AppxManifest Include="Package.appxmanifest">
189189
<SubType>Designer</SubType>
190190
</AppxManifest>
191+
<Content Include="Assets\css\greenTheme.css" />
191192
<Content Include="Assets\pdf\annualReport.pdf">
192193
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
193194
</Content>
@@ -280,4 +281,4 @@
280281
<Target Name="AfterBuild">
281282
</Target>
282283
-->
283-
</Project>
284+
</Project>

samples/Catalog/windows/Catalog/MainReactNativeHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using ReactNative;
23
using ReactNative.Modules.Core;
34
using ReactNative.Shell;

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Assets/customTheme.css

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

0 commit comments

Comments
 (0)