Skip to content

Add catalog example for changing pages #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ PSPDFKitView.propTypes = {
* formEditingActive: bool,
* }
*
* @platform android
*/
onStateChanged: PropTypes.func,
/**
Expand Down
1 change: 1 addition & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
@property (nonatomic, copy) RCTBubblingEventBlock onDocumentSaved;
@property (nonatomic, copy) RCTBubblingEventBlock onAnnotationTapped;
@property (nonatomic, copy) RCTBubblingEventBlock onAnnotationsChanged;
@property (nonatomic, copy) RCTBubblingEventBlock onStateChanged;

@end
7 changes: 7 additions & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitView.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ - (BOOL)pdfViewController:(PSPDFViewController *)pdfController didTapOnAnnotatio
return self.disableDefaultActionForTappedAnnotations;
}

- (void)pdfViewController:(PSPDFViewController *)pdfController willBeginDisplayingPageView:(PSPDFPageView *)pageView forPageAtIndex:(NSInteger)pageIndex {
if (self.onStateChanged) {
self.onStateChanged(@{@"currentPageIndex" : @(pageIndex), @"pageCount" : @(pdfController.document.pageCount)});
}
}

#pragma mark - Notifications

- (void)annotationChangedNotification:(NSNotification *)notification {
id object = notification.object;
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ @implementation RCTPSPDFKitViewManager

RCT_EXPORT_VIEW_PROPERTY(onAnnotationsChanged, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTBubblingEventBlock)

- (UIView *)view {
return [[RCTPSPDFKitView alloc] init];
}
Expand Down
77 changes: 77 additions & 0 deletions samples/Catalog/Catalog.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
StyleSheet,
Text,
View,
Button,
Image,
TouchableHighlight,
ListView,
Expand Down Expand Up @@ -94,6 +95,17 @@ var examples = [
component.props.navigator.push(nextRoute)
},
},
{
name: 'Change Pages Buttons',
description:
'Adds a toolbar at the bottom with buttons to the change pages.',
action: component => {
const nextRoute = {
component: ChangePages
}
component.props.navigator.push(nextRoute)
},
},
{
name: 'Split PDF',
description: 'Show two PDFs side by side by using PSPDFKitView components.',
Expand Down Expand Up @@ -233,6 +245,71 @@ class SplitPDF extends Component {
}
}

class ChangePages extends Component {
constructor(props) {
super(props)
this.state = {
currentPageIndex: 0,
pageCount: 0,
};
}

render() {
return (
<View style={{ flex: 1 }}>
<PSPDFKitView
document={'PDFs/Annual Report.pdf'}
configuration={{
backgroundColor: processColor('lightgrey'),
thumbnailBarMode: 'scrollable',
}}
pageIndex={this.state.currentPageIndex}
showCloseButton={true}
onCloseButtonPressed={this.props.onClose}
style={{ flex: 1, color: pspdfkitColor }}
onStateChanged={event => {
this.setState({
currentPageIndex: event.currentPageIndex,
pageCount: event.pageCount,
});
}}
/>
<View style={{ flexDirection: 'row', height: 60, alignItems: 'center', padding: 10 }}>
<Text>
{"Page " + (this.state.currentPageIndex + 1) + " of " + this.state.pageCount}
</Text>
<View>
<Button onPress={() => {
this.setState(previousState => {
return { currentPageIndex: previousState.currentPageIndex - 1 }
})
}} disabled={this.state.currentPageIndex == 0} title="Previous Page" />
</View>
<View style={{ marginLeft: 10 }}>
<Button onPress={() => {
this.setState(previousState => {
return { currentPageIndex: previousState.currentPageIndex + 1 }
})
}} disabled={this.state.currentPageIndex == this.state.pageCount - 1} title="Next Page" />
</View>
</View>
</View>
)
}

_getOptimalLayoutDirection = () => {
const width = this.state.dimensions
? this.state.dimensions.width
: Dimensions.get('window').width
return width > 450 ? 'row' : 'column'
}

_onLayout = event => {
let { width, height } = event.nativeEvent.layout
this.setState({ dimensions: { width, height } })
}
}

export default class Catalog extends Component {
render() {
return (
Expand Down
47 changes: 45 additions & 2 deletions samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
841A136C210762A4006CD78D /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 841A13462107627F006CD78D /* libRCTAnimation.a */; };
8439DE692100F4F6008F1674 /* PSPDFKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6572778F1D83184800A5E1A8 /* PSPDFKit.framework */; };
8439DE6A2100F4F6008F1674 /* PSPDFKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6572778F1D83184800A5E1A8 /* PSPDFKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
8439DE9F2100F991008F1674 /* libRNFS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6540D1951D8A9F9100B8F94F /* libRNFS.a */; };
Expand Down Expand Up @@ -201,6 +202,20 @@
remoteGlobalIDString = 58B5119B1A9E6C1200147676;
remoteInfo = RCTText;
};
841A13452107627F006CD78D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTAnimation;
};
841A13472107627F006CD78D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 2D2A28201D9B03D100D4039D;
remoteInfo = "RCTAnimation-tvOS";
};
8439DE6F2100F4F7008F1674 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */;
Expand Down Expand Up @@ -335,7 +350,7 @@
657278751D86C28800A5E1A8 /* RCTPSPDFKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTPSPDFKit.xcodeproj; path = ../../../ios/RCTPSPDFKit.xcodeproj; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
8439DEA12100FC9F008F1674 /* PDFs */ = {isa = PBXFileReference; lastKnownFileType = folder; name = PDFs; path = "../node_modules/react-native-pspdfkit/samples/PDFs"; sourceTree = "<group>"; };
841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
8439DEA32100FCB8008F1674 /* PDFs */ = {isa = PBXFileReference; lastKnownFileType = folder; name = PDFs; path = ../../PDFs; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -352,6 +367,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
841A136C210762A4006CD78D /* libRCTAnimation.a in Frameworks */,
8439DEA02100FAA8008F1674 /* libRCTPSPDFKit.a in Frameworks */,
8439DE9F2100F991008F1674 /* libRNFS.a in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */,
Expand Down Expand Up @@ -546,6 +562,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand All @@ -562,7 +579,6 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
8439DEA12100FC9F008F1674 /* PDFs */,
8439DEA32100FCB8008F1674 /* PDFs */,
13B07FAE1A68108700A75B9A /* Catalog */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
Expand All @@ -583,6 +599,15 @@
name = Products;
sourceTree = "<group>";
};
841A13402107627E006CD78D /* Products */ = {
isa = PBXGroup;
children = (
841A13462107627F006CD78D /* libRCTAnimation.a */,
841A13482107627F006CD78D /* libRCTAnimation.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -655,6 +680,10 @@
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
},
{
ProductGroup = 841A13402107627E006CD78D /* Products */;
ProjectRef = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
},
{
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
Expand Down Expand Up @@ -870,6 +899,20 @@
remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
841A13462107627F006CD78D /* libRCTAnimation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAnimation.a;
remoteRef = 841A13452107627F006CD78D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
841A13482107627F006CD78D /* libRCTAnimation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAnimation.a;
remoteRef = 841A13472107627F006CD78D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
8439DE702100F4F7008F1674 /* libRCTImage-tvOS.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
Expand Down