react-native-pdf-view icon indicating copy to clipboard operation
react-native-pdf-view copied to clipboard

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

Open andrejunges opened this issue 8 years ago • 14 comments

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

image

Any idea what might be causing it?

Thanks

andrejunges avatar Jan 21 '17 00:01 andrejunges

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.

mkoo21 avatar Jan 21 '17 01:01 mkoo21

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.

andrejunges avatar Jan 21 '17 18:01 andrejunges

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

KristoferEng avatar Mar 07 '17 00:03 KristoferEng

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

andrejunges avatar Mar 07 '17 02:03 andrejunges

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

Traviskn avatar Mar 20 '17 21:03 Traviskn

@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

mkoo21 avatar Mar 20 '17 21:03 mkoo21

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

sibelius avatar Mar 20 '17 21:03 sibelius

Thanks, I'll give that a shot!

Traviskn avatar Mar 20 '17 21:03 Traviskn

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

Traviskn avatar Mar 23 '17 19:03 Traviskn

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

jorge627 avatar Mar 25 '17 23:03 jorge627

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

DeveloperAlly avatar May 13 '17 04:05 DeveloperAlly

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

louiszawadzki avatar May 16 '17 16:05 louiszawadzki

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.

barbarossusuz avatar May 18 '17 16:05 barbarossusuz

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

sharoneh avatar Nov 21 '19 17:11 sharoneh