We use the visual viewport API: VisualViewport - Web APIs | MDN.
You can search the JS files in our repo code for visualViewport. There are some quirks in iOS due to the placement of the composer, so we use some more complex overrides there, the relevant file is app/assets/javascripts/discourse/app/lib/safari-hacks.js.