[Google Maps Library] Correctly remove "resize" event listener.
Forge component by Labs
Published on 26 Feb 2020
Application Type

If we set AutoFitOnWindowResize input of Map block as True and navigate between screens and try to rotate the device (or change screen size in simulator) we have this error:

Invalid call of the 'Map_OnResize' client action of the '***' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action

If AutoFitOnWindowResize is False the event listener EventListener("resize", $parameters.ObjResize) won't be set and no error will be logged in console.  There is removeEventListener in OnDestroy of Map block .

Also if we remove event listener before adding new one it also fixes the issue.

// Listen for window size changes


    $parameters.ObjResize = function(){$actions.Map_OnResize();};

    window.removeEventListener("resize", $parameters.ObjResize); 

    window.addEventListener("resize", $parameters.ObjResize);


If we have map on multiple screens and navigating between them then initialisation of new screen (and map) is run before previous "destroy".

Is it a correct way of handling event listeners ?