Remove Android WebView from view system before calling destroy()

See original GitHub issue

Bug description:

React-native needs to remove WebView from the view hierarchy before calling .destroy(). From this comment it seems react-native is not doing so:

...
W/cr_AwContents: WebView.destroy() called while WebView is still attached to window.
...

This probably isn’t causing a crash (WebView tries to handle this case gracefully), but older versions of WebView may not handle this as gracefully (I’ve observed crashes on really old Android versions).

To Reproduce:

Not sure. This log message probably repros every time you trigger the cleanup code path.

Expected behavior:

The documentation states:

This method should be called after this WebView has been removed from the view system. No other methods may be called on this WebView after destroy.

https://developer.android.com/reference/android/webkit/WebView.html#destroy()

Screenshots/Videos:

N/A

Environment:

  • OS: Android
  • OS version: probably all
  • react-native version:
  • react-native-webview version:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

4reactions
zlwucommented, Jul 28, 2020

when using react navigation, we can hide WebView in event listener


  React.useEffect(() => navigation.addListener('blur', () => setShow(false)), [ navigation ]);

2reactions
Leanderson-Coelhocommented, Sep 11, 2020

when using react navigation, we can hide WebView in event listener

  React.useEffect(() => navigation.addListener('blur', () => setShow(false)), [ navigation ]);

it worked here!!! thank you ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove Android WebView from view system before calling ...
Bug description: React-native needs to remove WebView from the view hierarchy before calling .destroy() . From this comment it seems react- ...
Read more >
Destroy webview in Android - Stack Overflow
Old Answer: To remove the WebView from memory, override the finish() method and place the code you have in onDestroy() in finish(). finish...
Read more >
WebView - Android Developers
public void destroy (). Destroys the internal state of this WebView. This method should be called after this WebView has been removed from...
Read more >
Android 5.1 WebView memory leakage analysis - Alibaba Cloud
The core idea is to let the onDetachedFromWindow go first. So we can call the destroy() method before the active call and remove...
Read more >
webview_flutter | Flutter Package - Pub.dev
A Flutter plugin that provides a WebView widget on Android and iOS. ... Calling destroy on Android webview when flutter webview is getting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found