Skip to content

Commit

Permalink
fix: android props listener leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweenkie committed Dec 20, 2019
1 parent 7ce7a65 commit eb3b833
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ class PdfScanner extends React.Component<PdfScannerProps> {
}
}

componentDidUpdate(prevProps: PdfScannerProps) {
if (Platform.OS === 'android') {
if (this.props.onPictureTaken !== prevProps.onPictureTaken) {
if (prevProps.onPictureTaken)
DeviceEventEmitter.removeListener('onPictureTaken', prevProps.onPictureTaken)
if (this.props.onPictureTaken)
DeviceEventEmitter.addListener('onPictureTaken', this.props.onPictureTaken)
}
if (this.props.onProcessing !== prevProps.onProcessing) {
if (prevProps.onProcessing)
DeviceEventEmitter.removeListener('onProcessingChange', prevProps.onProcessing)
if (this.props.onProcessing)
DeviceEventEmitter.addListener('onProcessingChange', this.props.onProcessing)
}
}
}

componentWillUnmount () {
if (Platform.OS === 'android') {
const { onPictureTaken, onProcessing } = this.props
Expand Down

0 comments on commit eb3b833

Please sign in to comment.