GithubHelp home page GithubHelp logo

mattpilott / ios-chat Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 308 KB

Solution for dealing with the iOS keyboard in a chat style UI. Works best as a PWA

Home Page: https://ios-chat.vercel.app

HTML 52.25% JavaScript 9.19% CSS 38.56%

ios-chat's Introduction

iOS Chat

This is a working example of handling the iOS keyboard in a chat style application where you want the message bar to remain visible when the keyboard is shown.

How it works

As iOS doesn't do much to help layout reflow when the keyboard is shown, we need to do this ourselves.

Using the visualViewport API we can detect when the keyboard is shown and adjust the layout accordingly.

This example takes the height of the visual viewport and sets a CSS variable --vvh conatining the height of the visualViewport. This can then be used in CSS to adjust the layout.

For notched devices we add a second CSS variable --vvs which is set to env(safe-area-inset-bottom) or 0px based on the height of the visualViewport.

Whilst everything in main.js (except the style import ๐Ÿ˜) file is needed, the style.css file contains a mix of styles needed for the demo and the styles critical to the technique. These have been marked with a comment.

const vv = window.visualViewport

function setVVH() {
	const vvh = `${vv.height}px`
	const vvs = vv.height < 600 ? '0px' : 'env(safe-area-inset-bottom)'

	document.body.style.setProperty('--vvh', vvh)
	document.body.style.setProperty('--vvs', vvs)
}

vv.addEventListener('resize', setVVH)
setVVH()

Found an bug?

Open an issue and I'll take a look.

ios-chat's People

Contributors

mattpilott avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.