I have this "drop menu" that literally drops from the top using the Matter.js 2d physics engine: https://github.com/NeilSentence/galerie-sens
let world, engine, runner
const { Engine, Runner, World, Bodies, MouseConstraint, Composites, Body } = Matter
class Scene extends React.Component {
componentDidMount(){
const runCode = () => {
// set up all matter.js stuff here (works!).
// At the bottom, an IIFE called update:
(function update(){
requestAnimationFrame(update)
// updates CSS positions of DOM elements. works(!)
Engine.update(engine)
})()
}
run()
}
componentWillUnmount(){
// cancel matter stuff here:
World.clear(world);
Engine.clear(engine);
Runner.stop(runner);
}
}
Problem is, when I toggle the menu (close than open again), things fall down faster!
This is after I tried to fix a bug where Bodies remained active after re-mount. Found this answer How to completely stop/reset/reinitialize Matter.js canvas/world/engine/instance where Mr. Greenstreet outlines his reset setup.
However, in my case it's only working until the point where he explains the need for stopping the Runner. Stopping it makes no difference.
BTW, I'm not using Render, as I only use the engine to produce values for my HTML-elements.
I'm using React - the Scene is a class component (I'm just getting started with react).
Full project is under src/components/menudrop.js