[TIMOB-14292] (3_1_X) Avoid race condition on view detach

Backport of PR #4516
Test is in [JIRA](https://jira.appcelerator.org/browse/TIMOB-14292)