Skip to content

Commit

Permalink
Merge pull request wojtekmaj#1 from diegomura/text-component
Browse files Browse the repository at this point in the history
Add PDFTextComponent for plain text nodes
  • Loading branch information
diegomura authored Oct 22, 2016
2 parents 9eec8eb + 672edbf commit 5db8a60
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Binary file modified examples/example.pdf
Binary file not shown.
22 changes: 22 additions & 0 deletions src/PDFTextComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const PDFTextComponent = function(element) {
this._currentElement = element;
};

const PDFTextComponentMixin = {
mountComponent(transaction, nativeParent, nativeContainerInfo, context) {
// Just return the text value
return this._currentElement;
},
receiveComponent(){},
getHostNode() {},
unmountComponent() {},
};

Object.assign(
PDFTextComponent.prototype,
PDFTextComponentMixin
);

export default PDFTextComponent;
12 changes: 2 additions & 10 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ const PDFRendererComponentMixin = {
return this.node;
},

mountComponent(
transaction,
nativeParent,
nativeContainerInfo,
context
) {
mountComponent(transaction, nativeParent, nativeContainerInfo, context) {
const node = this.node = this._currentElement;
const {children, ...props} = node.props;

Expand All @@ -36,10 +31,7 @@ const PDFRendererComponentMixin = {
context.doc[node.type](children, props);
}

// Naive way of not mounting TextComponent
if (typeof children != 'string') {
this.mountChildren(children, transaction, context);
}
this.mountChildren(children, transaction, context);

return node;
},
Expand Down
5 changes: 5 additions & 0 deletions src/injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import ReactHostComponent from 'react/lib/ReactHostComponent';
import ReactDefaultBatchingStrategy from 'react/lib/ReactDefaultBatchingStrategy';
import PDFRendererReconcileTransaction from './reconcileTransaction';
import PDFRendererComponent from './component';
import PDFTextComponent from './PDFTextComponent';

function inject() {
ReactInjection.HostComponent.injectGenericComponentClass(
PDFRendererComponent
);

ReactInjection.HostComponent.injectTextComponentClass(
PDFTextComponent
);

ReactInjection.Updates.injectReconcileTransaction(
PDFRendererReconcileTransaction
);
Expand Down

0 comments on commit 5db8a60

Please sign in to comment.