react-native-pdf-view
react-native-pdf-view copied to clipboard
The specified child already has a parent. You must call removeView() on the child's parent first.
I'm getting this error when I rerender any PDF file on Android.
Any idea what might be causing it?
Thanks
Had a similar problem when using the navigator to swap a new pdf view on top of an old one.
For mine, the path was stored in state and render() returned a fetching message (instead of a pdfview) if the path was unset. I can't say too much about why rendering a new PDF view on top of an old one seems to be problematic, but manually setting the path to null and delaying the navigation until after a rerender (promises, timeouts) all get me around this issue.
Indeed some delay fixed that issue. Thanks a lot 👍
Unfortunately I dont know much about the native part (android) to fix the internal issue. So I think this issue should remain opened.
How did you implement the delay to make this work? I keep running into this issue.
@KristoferEng I implemented a simple hack adding some timeout while reseting the pdfPath value from my state. I was getting this error in my fullscreen
functionality.
toggleFullscreen = () => {
const pdfLocation = this.state.pdfLocation;
this.setState({
pdfLocation: null,
fullscreen: !this.state.fullscreen,
}, () => {
setTimeout(() => { this.setState({ pdfLocation }); }, 10);
});
}
However, it seems this bug has already been fixed. So it'd be better if @cnjon could release a new version with these last fixes.. 😄
I'm also running into this issue, is there a patch with this bug fix you mentioned?
@Traviskn if you pull the latest code from the repo (e.g. replace the version number in your package json with the repository url) it should be resolved
git+https://[email protected]/cnjon/react-native-pdf-view#commit-number
Thanks, I'll give that a shot!
Unfortunately even using the latest version git+https://[email protected]/cnjon/react-native-pdf-view#74fd7a3
I am still running into errors, although it is a different error message this time Trying to remove a view index above child count 2 view tag...
. If I use a short setTimeout though the error does not occur. It seems there are still some issues?
Hi I'm getting the same error "The specified child already has a parent. You must call removeView() on the child's parent first."
I'm using PDFView as a redux router component in an Scene
<Scene key={"pdfViewer"} component={PdfViewer} />
when I open a PDF the first time everything is OK, but when a try to open a new PDF in the same Scene i get the error, the Pdf name is different every time that i try to open it.
Any idea what is causing it?
"react": "15.4.2",
"react-native": "0.42.0",
"react-native-pdf-view": "^0.3.2",
Thanks in advance
Was this issue solved? I have a pdfView within a screen and am trying to fullscreen the pdf on touch, however I get this same error 'specified child already has a parent. You must call removeView() on the child's parent first' Any help would be great
I had the same issue using react-native-router-flux: every time I came back to a tab that contained a PDF the app would show this message.
I solved it by setting the path to my PDF to null
everytime I changed tabs and setting it to its actual value when I was going to the tab where it's displayed.
Then I had to actually remove the PDFView when the path was null
like that:
{this.props.pdfPath !== null && <PDFView path={this.props.pdfPath} />}
My page something like that {this.state.isPdfDownload ? <PDFView ref={(pdf) => { path={this.path}/> : <Text>Waiting For Pdf</Text>}
when i hit back button to select a new pdf im doing this.setState({isPdfDownload:false});
and this worked for me. In conclusion; set your states previous ones when you try to select new pdf.
@Traviskn if you pull the latest code from the repo (e.g. replace the version number in your package json with the repository url) it should be resolved
this solved this issue for me right away, although I spent some significant time trying other solutions I found for it. Thank you!