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

The specified child already has a parent. You must call removeView() on the child's parent first. #39

Open
andrejunges opened this issue Jan 21, 2017 · 14 comments · Fixed by #45 or joltup/react-native-pdf-view#1 · May be fixed by #55

Comments

@andrejunges
Copy link

I'm getting this error when I rerender any PDF file on Android.

image

Any idea what might be causing it?

Thanks

@mkoo21
Copy link
Contributor

mkoo21 commented Jan 21, 2017

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.

@andrejunges
Copy link
Author

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.

@KristoferEng
Copy link

How did you implement the delay to make this work? I keep running into this issue.

@andrejunges
Copy link
Author

andrejunges commented Mar 7, 2017

@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.. 😄

@Traviskn
Copy link

I'm also running into this issue, is there a patch with this bug fix you mentioned?

@mkoo21
Copy link
Contributor

mkoo21 commented Mar 20, 2017

@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

@sibelius
Copy link
Contributor

git+https://[email protected]/cnjon/react-native-pdf-view#commit-number

@Traviskn
Copy link

Thanks, I'll give that a shot!

@Traviskn
Copy link

Traviskn commented Mar 23, 2017

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?
errormessage

@sibelius sibelius reopened this Mar 23, 2017
@jorge627
Copy link

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

Traviskn added a commit to joltup/react-native-pdf-view that referenced this issue Mar 27, 2017
fixes cnjon#39

Always returning a new view instance prevents crashing when multiple
PDFViews are rendered.
@Traviskn Traviskn linked a pull request Mar 27, 2017 that will close this issue
@DeveloperAlly
Copy link

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

@louiszawadzki
Copy link

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} />}

@barbarossusuz
Copy link

barbarossusuz commented May 18, 2017

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.

chukcha-wtf added a commit to axsy-dev/react-native-pdf-view that referenced this issue Aug 22, 2017
mataron added a commit to mataron/react-native-pdf-view that referenced this issue Sep 24, 2017
@sharoneh
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants