Skip to content

Commit ac5ab3b

Browse files
authored
Merge pull request #98 from PSPDFKit/rad/add-catalog-example-for-changing-pages
Add catalog example for changing pages
2 parents e77cf10 + 69b04c8 commit ac5ab3b

File tree

6 files changed

+132
-3
lines changed

6 files changed

+132
-3
lines changed

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ PSPDFKitView.propTypes = {
181181
* formEditingActive: bool,
182182
* }
183183
*
184-
* @platform android
185184
*/
186185
onStateChanged: PropTypes.func,
187186
/**

ios/RCTPSPDFKit/RCTPSPDFKitView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
@property (nonatomic, copy) RCTBubblingEventBlock onDocumentSaved;
2424
@property (nonatomic, copy) RCTBubblingEventBlock onAnnotationTapped;
2525
@property (nonatomic, copy) RCTBubblingEventBlock onAnnotationsChanged;
26+
@property (nonatomic, copy) RCTBubblingEventBlock onStateChanged;
2627

2728
@end

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ - (BOOL)pdfViewController:(PSPDFViewController *)pdfController didTapOnAnnotatio
122122
return self.disableDefaultActionForTappedAnnotations;
123123
}
124124

125+
- (void)pdfViewController:(PSPDFViewController *)pdfController willBeginDisplayingPageView:(PSPDFPageView *)pageView forPageAtIndex:(NSInteger)pageIndex {
126+
if (self.onStateChanged) {
127+
self.onStateChanged(@{@"currentPageIndex" : @(pageIndex), @"pageCount" : @(pdfController.document.pageCount)});
128+
}
129+
}
130+
131+
#pragma mark - Notifications
125132

126133
- (void)annotationChangedNotification:(NSNotification *)notification {
127134
id object = notification.object;

ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ @implementation RCTPSPDFKitViewManager
5656

5757
RCT_EXPORT_VIEW_PROPERTY(onAnnotationsChanged, RCTBubblingEventBlock)
5858

59+
RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTBubblingEventBlock)
60+
5961
- (UIView *)view {
6062
return [[RCTPSPDFKitView alloc] init];
6163
}

samples/Catalog/Catalog.ios.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
StyleSheet,
1212
Text,
1313
View,
14+
Button,
1415
Image,
1516
TouchableHighlight,
1617
ListView,
@@ -94,6 +95,17 @@ var examples = [
9495
component.props.navigator.push(nextRoute)
9596
},
9697
},
98+
{
99+
name: 'Change Pages Buttons',
100+
description:
101+
'Adds a toolbar at the bottom with buttons to the change pages.',
102+
action: component => {
103+
const nextRoute = {
104+
component: ChangePages
105+
}
106+
component.props.navigator.push(nextRoute)
107+
},
108+
},
97109
{
98110
name: 'Split PDF',
99111
description: 'Show two PDFs side by side by using PSPDFKitView components.',
@@ -233,6 +245,71 @@ class SplitPDF extends Component {
233245
}
234246
}
235247

248+
class ChangePages extends Component {
249+
constructor(props) {
250+
super(props)
251+
this.state = {
252+
currentPageIndex: 0,
253+
pageCount: 0,
254+
};
255+
}
256+
257+
render() {
258+
return (
259+
<View style={{ flex: 1 }}>
260+
<PSPDFKitView
261+
document={'PDFs/Annual Report.pdf'}
262+
configuration={{
263+
backgroundColor: processColor('lightgrey'),
264+
thumbnailBarMode: 'scrollable',
265+
}}
266+
pageIndex={this.state.currentPageIndex}
267+
showCloseButton={true}
268+
onCloseButtonPressed={this.props.onClose}
269+
style={{ flex: 1, color: pspdfkitColor }}
270+
onStateChanged={event => {
271+
this.setState({
272+
currentPageIndex: event.currentPageIndex,
273+
pageCount: event.pageCount,
274+
});
275+
}}
276+
/>
277+
<View style={{ flexDirection: 'row', height: 60, alignItems: 'center', padding: 10 }}>
278+
<Text>
279+
{"Page " + (this.state.currentPageIndex + 1) + " of " + this.state.pageCount}
280+
</Text>
281+
<View>
282+
<Button onPress={() => {
283+
this.setState(previousState => {
284+
return { currentPageIndex: previousState.currentPageIndex - 1 }
285+
})
286+
}} disabled={this.state.currentPageIndex == 0} title="Previous Page" />
287+
</View>
288+
<View style={{ marginLeft: 10 }}>
289+
<Button onPress={() => {
290+
this.setState(previousState => {
291+
return { currentPageIndex: previousState.currentPageIndex + 1 }
292+
})
293+
}} disabled={this.state.currentPageIndex == this.state.pageCount - 1} title="Next Page" />
294+
</View>
295+
</View>
296+
</View>
297+
)
298+
}
299+
300+
_getOptimalLayoutDirection = () => {
301+
const width = this.state.dimensions
302+
? this.state.dimensions.width
303+
: Dimensions.get('window').width
304+
return width > 450 ? 'row' : 'column'
305+
}
306+
307+
_onLayout = event => {
308+
let { width, height } = event.nativeEvent.layout
309+
this.setState({ dimensions: { width, height } })
310+
}
311+
}
312+
236313
export default class Catalog extends Component {
237314
render() {
238315
return (

samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
2626
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
2727
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
28+
841A136C210762A4006CD78D /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 841A13462107627F006CD78D /* libRCTAnimation.a */; };
2829
8439DE692100F4F6008F1674 /* PSPDFKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6572778F1D83184800A5E1A8 /* PSPDFKit.framework */; };
2930
8439DE6A2100F4F6008F1674 /* PSPDFKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6572778F1D83184800A5E1A8 /* PSPDFKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3031
8439DE9F2100F991008F1674 /* libRNFS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6540D1951D8A9F9100B8F94F /* libRNFS.a */; };
@@ -201,6 +202,20 @@
201202
remoteGlobalIDString = 58B5119B1A9E6C1200147676;
202203
remoteInfo = RCTText;
203204
};
205+
841A13452107627F006CD78D /* PBXContainerItemProxy */ = {
206+
isa = PBXContainerItemProxy;
207+
containerPortal = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
208+
proxyType = 2;
209+
remoteGlobalIDString = 134814201AA4EA6300B7C361;
210+
remoteInfo = RCTAnimation;
211+
};
212+
841A13472107627F006CD78D /* PBXContainerItemProxy */ = {
213+
isa = PBXContainerItemProxy;
214+
containerPortal = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
215+
proxyType = 2;
216+
remoteGlobalIDString = 2D2A28201D9B03D100D4039D;
217+
remoteInfo = "RCTAnimation-tvOS";
218+
};
204219
8439DE6F2100F4F7008F1674 /* PBXContainerItemProxy */ = {
205220
isa = PBXContainerItemProxy;
206221
containerPortal = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */;
@@ -335,7 +350,7 @@
335350
657278751D86C28800A5E1A8 /* RCTPSPDFKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTPSPDFKit.xcodeproj; path = ../../../ios/RCTPSPDFKit.xcodeproj; sourceTree = "<group>"; };
336351
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
337352
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
338-
8439DEA12100FC9F008F1674 /* PDFs */ = {isa = PBXFileReference; lastKnownFileType = folder; name = PDFs; path = "../node_modules/react-native-pspdfkit/samples/PDFs"; sourceTree = "<group>"; };
353+
841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
339354
8439DEA32100FCB8008F1674 /* PDFs */ = {isa = PBXFileReference; lastKnownFileType = folder; name = PDFs; path = ../../PDFs; sourceTree = "<group>"; };
340355
/* End PBXFileReference section */
341356

@@ -352,6 +367,7 @@
352367
isa = PBXFrameworksBuildPhase;
353368
buildActionMask = 2147483647;
354369
files = (
370+
841A136C210762A4006CD78D /* libRCTAnimation.a in Frameworks */,
355371
8439DEA02100FAA8008F1674 /* libRCTPSPDFKit.a in Frameworks */,
356372
8439DE9F2100F991008F1674 /* libRNFS.a in Frameworks */,
357373
146834051AC3E58100842450 /* libReact.a in Frameworks */,
@@ -546,6 +562,7 @@
546562
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
547563
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
548564
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
565+
841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */,
549566
);
550567
name = Libraries;
551568
sourceTree = "<group>";
@@ -562,7 +579,6 @@
562579
83CBB9F61A601CBA00E9B192 = {
563580
isa = PBXGroup;
564581
children = (
565-
8439DEA12100FC9F008F1674 /* PDFs */,
566582
8439DEA32100FCB8008F1674 /* PDFs */,
567583
13B07FAE1A68108700A75B9A /* Catalog */,
568584
832341AE1AAA6A7D00B99B32 /* Libraries */,
@@ -583,6 +599,15 @@
583599
name = Products;
584600
sourceTree = "<group>";
585601
};
602+
841A13402107627E006CD78D /* Products */ = {
603+
isa = PBXGroup;
604+
children = (
605+
841A13462107627F006CD78D /* libRCTAnimation.a */,
606+
841A13482107627F006CD78D /* libRCTAnimation.a */,
607+
);
608+
name = Products;
609+
sourceTree = "<group>";
610+
};
586611
/* End PBXGroup section */
587612

588613
/* Begin PBXNativeTarget section */
@@ -655,6 +680,10 @@
655680
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
656681
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
657682
},
683+
{
684+
ProductGroup = 841A13402107627E006CD78D /* Products */;
685+
ProjectRef = 841A133F2107627E006CD78D /* RCTAnimation.xcodeproj */;
686+
},
658687
{
659688
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
660689
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
@@ -870,6 +899,20 @@
870899
remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */;
871900
sourceTree = BUILT_PRODUCTS_DIR;
872901
};
902+
841A13462107627F006CD78D /* libRCTAnimation.a */ = {
903+
isa = PBXReferenceProxy;
904+
fileType = archive.ar;
905+
path = libRCTAnimation.a;
906+
remoteRef = 841A13452107627F006CD78D /* PBXContainerItemProxy */;
907+
sourceTree = BUILT_PRODUCTS_DIR;
908+
};
909+
841A13482107627F006CD78D /* libRCTAnimation.a */ = {
910+
isa = PBXReferenceProxy;
911+
fileType = archive.ar;
912+
path = libRCTAnimation.a;
913+
remoteRef = 841A13472107627F006CD78D /* PBXContainerItemProxy */;
914+
sourceTree = BUILT_PRODUCTS_DIR;
915+
};
873916
8439DE702100F4F7008F1674 /* libRCTImage-tvOS.a */ = {
874917
isa = PBXReferenceProxy;
875918
fileType = archive.ar;

0 commit comments

Comments
 (0)