Skip to content
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

Feature/windows vnext #1

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
250038a
Update README.md
pedramsaleh Oct 12, 2016
90d694f
Update README.md
pedramsaleh Oct 13, 2016
a2d5ac9
Merge pull request #32 from pedramsaleh/patch-1
sibelius Oct 25, 2016
45c667d
fixed React Native 0.40 headers
horsekitlin Jan 16, 2017
9c759f4
Merge pull request #38 from horsekitlin/master
sibelius Jan 31, 2017
1829626
testing imports
Dec 16, 2016
3f67566
readding deprecated library to build (temp)
Dec 16, 2016
eb4f14b
removing listener imports
Dec 16, 2016
cfe8716
removing listener imports
Dec 16, 2016
7c9866a
switching to newer/more maintained lib
Dec 16, 2016
990c9c7
switching index to start from 0
mkoo21 Feb 23, 2017
5eb4fba
removing old lib from build.gradle
mkoo21 Feb 23, 2017
18facd5
changing positive number check to include 0
mkoo21 Feb 23, 2017
d0be1b5
minor readability change for non-negative page number check
mkoo21 Feb 23, 2017
5464e73
fix: fix #39
raininfall Mar 1, 2017
e2d44f3
update for RN 0.42.0 and RNFS 2.1.0
mkoo21 Mar 2, 2017
306a149
update for RN 0.42.0 and RNFS 2.1.0
mkoo21 Mar 2, 2017
06c6725
fixing appregistry
mkoo21 Mar 2, 2017
7cf2f32
updating for react 15.4.2 and RN 0.42.0
mkoo21 Mar 2, 2017
44b4f0c
update to allow http
mkoo21 Mar 2, 2017
0155fd3
Merge pull request #36 from mkoo21/master
sibelius Mar 2, 2017
e758074
improve example a bit
sibelius Mar 2, 2017
b9ffa3f
add TypeScript typings
gyzerok Mar 2, 2017
bee47b2
Merge pull request #46 from gyzerok/add-ts-typings
sibelius Mar 2, 2017
1454d03
Merge pull request #45 from RainInFall/master
sibelius Mar 2, 2017
172c880
Bumped version to 0.4.0
Mar 7, 2017
74fd7a3
Merge pull request #51 from remanation/bumped_version
sibelius Mar 20, 2017
a62c21d
fix typescript types in accordance to update within @types/react-native
gyzerok Mar 24, 2017
2a7be88
Merge pull request #54 from gyzerok/typescript-types-fix
sibelius Mar 24, 2017
3ae2feb
add prop-types as dependency for #90
Noitidart Dec 6, 2017
390b8cd
Update package.json
Noitidart Dec 6, 2017
9f891cc
Update PDFView.ios.js
Noitidart Dec 6, 2017
36e12f6
Update PDFView.android.js
Noitidart Dec 6, 2017
7f54227
Merge pull request #95 from Noitidart/patch-1
sibelius May 24, 2018
fcb7048
Added vnext pdfview, started test program
gillpeacegood Apr 3, 2020
3476a38
Program builds but some problem with the XAML
gillpeacegood Apr 7, 2020
56a9bd8
Get the binding to display correctly in form designer
gillpeacegood Apr 9, 2020
6b888be
Update PDF_Render.xaml.cs
gillpeacegood Apr 9, 2020
4f14137
Update App.js
gillpeacegood Apr 9, 2020
63b6e01
cherrypicked android change
gillpeacegood Feb 4, 2020
3e4cc37
Cherrypick podspec
gillpeacegood Feb 7, 2020
becc537
Reference project from install as well as dev directory.
gillpeacegood Apr 21, 2020
8a66c41
Patch for react-native-windows 0.63
gillpeacegood Oct 16, 2020
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ local.properties
node_modules/
npm-debug.log
*.iml


# Windows vnext
#
.vs/
packages/
bin/
obj/
msbuild.binlog
windows/RNPDFvnext/RNPDFvnext/obj/x64/Debug/intermediatexaml/RNPDFvnext.winmdobj
*.pdb
*.winmd
*.xbf
windows/RNPDFvnext/RNPDFvnext/obj/project.assets.json
*.cache
windows/RNPDFvnext/RNPDFvnext/obj/RNPDFvnext.csproj.nuget.dgspec.json
windows/RNPDFvnext/RNPDFvnext/obj/RNPDFvnext.csproj.nuget.g.props
3 changes: 2 additions & 1 deletion PDFView.android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
import React,{ Component, PropTypes } from 'react';
import React,{ Component } from 'react';
import { requireNativeComponent, View } from 'react-native';
import PropTypes from 'prop-types';

class PDFView extends Component {
constructor(props) {
Expand Down
3 changes: 2 additions & 1 deletion PDFView.ios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
import React,{ Component, PropTypes } from 'react';
import React, { Component } from 'react';
import { requireNativeComponent, View } from 'react-native';
import PropTypes from 'prop-types';

class PDFView extends Component {
constructor(props) {
Expand Down
40 changes: 40 additions & 0 deletions PDFView.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
import React, { Component } from 'react';
import { requireNativeComponent, View } from 'react-native';
import PropTypes from 'prop-types';

class PDFView extends Component {
constructor(props) {
super(props);
this._onChange = this._onChange.bind(this);
}

setNativeProps(nativeProps) {
this._root.setNativeProps(nativeProps);
}

_onChange(event:Event) {
this.props.onLoadComplete && this.props.onLoadComplete(Number(event.nativeEvent.message));
}

render() {
return <PDFCustomView ref={component => this._root = component} {...this.props} onChange={this._onChange}/>;
}
}

PDFView.propTypes = {
...View.propTypes,
src: PropTypes.string,
path: PropTypes.string,
pageNumber: PropTypes.number,
zoom: PropTypes.number,
onLoadComplete: PropTypes.func
};

//var PDFCustomView = requireNativeComponent('RNPDFView', null);

var PDFCustomView = requireNativeComponent('PDF_Render', PDFView, {
nativeOnly: {onChange: true}
});

export default PDFView;
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# react-native-pdf-view
React Native PDF View (cross-platform support)

### Breaking change
### Breaking changes

React native 0.19 changed the ReactProps class which led to problems with updating native view properties (see https://github.com/facebook/react-native/issues/5649). These errors are corrected in react-native-pdf-view version 0.2.0. Use version 0.2.* for react native >=0.19 and for earlier react native versions use version 0.1.3.
* React native 0.40 moved iOS headers, thus all iOS react import statements has been changed. Use version 0.4.* for react native >=0.40. For earlier version see below breaking change.

* React native 0.19 changed the ReactProps class which led to problems with updating native view properties (see https://github.com/facebook/react-native/issues/5649). These errors are corrected in react-native-pdf-view version 0.2.0. Use version 0.2.* for react native >=0.19 and for earlier react native versions use version 0.1.3.

### Installation
```bash
npm i react-native-pdf-view --save

react-native link react-native-pdf-view
```
* In `android/setting.gradle`

Expand Down
12 changes: 6 additions & 6 deletions RNPDFView/RNPDFView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
// Copyright © 2016 Facebook. All rights reserved.
//

#import "RCTEventDispatcher.h"
#import <React/RCTEventDispatcher.h>
#import "UIView+React.h"

@class RCTEventDispatcher;

@interface RNPDFView : UIView

@property (nonatomic, strong) NSString *src;
@property (nonatomic, strong) NSString *path;
@property (nonatomic, strong) NSNumber *pageNumber;
@property (nonatomic, strong) NSNumber *zoom;
@property(nonatomic, strong) NSString *src;
@property(nonatomic, strong) NSString *path;
@property(nonatomic, strong) NSNumber *pageNumber;
@property(nonatomic, strong) NSNumber *zoom;

@property (nonatomic, copy) RCTBubblingEventBlock onChange;
@property(nonatomic, copy) RCTBubblingEventBlock onChange;

@end
6 changes: 3 additions & 3 deletions RNPDFView/RNPDFView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

#import "RCTBridgeModule.h"
#import "RCTEventDispatcher.h"
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#import "UIView+React.h"
#import "RCTLog.h"
#import <React/RCTLog.h>

#import "TiledPDFView.h"
#import "PDFScrollView.h"
Expand Down
4 changes: 2 additions & 2 deletions RNPDFView/RNPDFViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//

#import <Foundation/Foundation.h>
#import "RCTBridge.h"
#import <React/RCTBridge.h>
#import "RNPDFViewManager.h"
#import "RNPDFView.h"
#import "RCTEventDispatcher.h"
#import <React/RCTEventDispatcher.h>

@implementation RNPDFViewManager

Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ repositories {
}

dependencies {
compile 'com.facebook.react:react-native:0.20.+'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
implementation 'com.facebook.react:react-native:0.20.+'
implementation 'com.github.barteksc:android-pdf-viewer:2.3.0'
}
26 changes: 22 additions & 4 deletions android/src/main/java/com/keyee/pdfview/PDFViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
import java.io.File;

import android.content.Context;
import android.view.ViewGroup;
import android.util.Log;
import android.graphics.PointF;

import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;

/*
import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnPageChangeListener;
import com.joanzapata.pdfview.listener.OnLoadCompleteListener;
*/

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -22,12 +29,13 @@
import com.facebook.react.common.MapBuilder;

import static java.lang.String.format;
import java.lang.ClassCastException;

public class PDFViewManager extends SimpleViewManager<PDFView> implements OnPageChangeListener,OnLoadCompleteListener {
private static final String REACT_CLASS = "RCTPDFViewAndroid";
private Context context;
private PDFView pdfView;
Integer pageNumber = 1;
Integer pageNumber = 0;
String assetName;
String filePath;

Expand All @@ -45,6 +53,16 @@ public String getName() {
public PDFView createViewInstance(ThemedReactContext context) {
if (pdfView == null){
pdfView = new PDFView(context, null);
} else {
/* #39 check parent and remove self from parent */
try {
final ViewGroup parentView = (ViewGroup) pdfView.getParent();
if (parentView != null) {
parentView.removeView(pdfView);
}
} catch (ClassCastException e) {
showLog("does not has a parent");
}
}
return pdfView;
//return new PDFView(context, null);
Expand Down Expand Up @@ -75,7 +93,7 @@ private void display(boolean jumpToFirstPage) {
if (assetName != null) {
pdfView.fromAsset(assetName)
.defaultPage(pageNumber)
.swipeVertical(true)
//.swipeVertical(true)
.onPageChange(this)
.onLoad(this)
.load();
Expand All @@ -87,7 +105,7 @@ private void display(boolean jumpToFirstPage) {
.defaultPage(pageNumber)
//.showMinimap(false)
//.enableSwipe(true)
.swipeVertical(true)
//.swipeVertical(true)
.onPageChange(this)
.onLoad(this)
.load();
Expand All @@ -103,7 +121,7 @@ public void setAsset(PDFView view, String ast) {
@ReactProp(name = "pageNumber")
public void setPageNumber(PDFView view, Integer pageNum) {
//view.setPageNumber(pageNum);
if (pageNum > 0){
if (pageNum >= 0){
pageNumber = pageNum;
display(false);
}
Expand Down
109 changes: 56 additions & 53 deletions example/PDFExample.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
/**
* Created by Kevin on 16/3/9.
*/
'use strict';

import React,{
Component,
StyleSheet,
View,
Text
import React from 'react';
import {
StyleSheet,
View,
Text
} from 'react-native';

import PDFView from 'react-native-pdf-view';
import RNFS from 'react-native-fs';

const pdfDownloadURL = 'http://image.tianjimedia.com/imagelist/2009/190/caq4z56jadof.pdf';

export default class PDFExample extends Component {
constructor(props) {
super(props);
this.state={
isPdfDownload: false
};
this.pdfView = null;
this.pdfPath = RNFS.DocumentDirectoryPath + '/test.pdf'
}
export default class PDFExample extends React.Component {
state = {
isPdfDownload: false,
};

componentDidMount() {
RNFS.downloadFile(pdfDownloadURL, this.pdfPath).then(res => {
this.setState({isPdfDownload: true});
}).catch(err => {
console.log(err);
});
}
constructor(props) {
super(props);
this.pdfView = null;
this.pdfPath = RNFS.DocumentDirectoryPath + '/test.pdf'
}

zoom(val = 2.1){
this.pdfView && setTimeout(()=>{
this.pdfView.setNativeProps({zoom: val});
}, 3000);
}
componentDidMount() {
const options = {
fromUrl: pdfDownloadURL,
toFile: this.pdfPath
};
RNFS.downloadFile(options).promise.then(res => {
this.setState({isPdfDownload: true});
}).catch(err => {
console.log(err);
});
}

render(){
if (!this.state.isPdfDownload){
return (
<View style={styles.container}>
<Text>Downloading</Text>
</View>
);
}
return (
<PDFView ref={(pdf)=>{this.pdfView = pdf;}}
key="sop"
path={this.pdfPath}
onLoadComplete = {(pageCount)=>{
zoom(val = 2.1) {
this.pdfView && setTimeout(() => {
this.pdfView.setNativeProps({zoom: val});
}, 3000);
}

render() {
if (!this.state.isPdfDownload) {
return (
<View style={styles.container}>
<Text>Downloading</Text>
</View>
);
}
return (
<PDFView ref={(pdf)=>{this.pdfView = pdf;}}
key="sop"
path={this.pdfPath}
onLoadComplete={(pageCount)=>{
console.log(`total page count: ${pageCount}`);
this.zoom();
}}
style={styles.pdf}/>
)
}
style={styles.pdf}/>
)
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
pdf: {
flex:1
}
});
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
pdf: {
flex: 1
}
});
Loading