Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-ios-keyboard-viewport

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ios-keyboard-viewport

A React hook that dynamically adjusts element positioning during iOS keyboard display, utilizing the Visual Viewport API for precise calculations.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33
increased by57.14%
Maintainers
1
Weekly downloads
 
Created
Source

react-ios-keyboard-viewport

npm version MIT License

A React hook that dynamically adjusts element positioning during iOS keyboard display, utilizing the Visual Viewport API for precise calculations.

Features

  • 📱 Overriding styles specifically when the iOS keyboard is displayed
  • 🐥 Easy to use
  • 🫙 Zero Dependencies

Installation

Install from npm:

npm install react-ios-keyboard-viewport

Usage

useFixedStyleWithIOsKeyboard

This hook generates a style object for elements that you want to fix to the Top/Center/Bottom of the screen. The style object is only generated when the keyboard is displayed on iOS, so please use this style object to override after styling for the normal display state.

import { useFixedStyleWithIOsKeyboard } from 'react-ios-keyboard-viewport';

const Component = () => {
  const { fixedTop, fixedCenter, fixedBottom } = useFixedStyleWithIOsKeyboard();
  return (
    <div className="wrapper">
      <header className="header" style={fixedTop}>
        Fixed to Top
      </header>
      <div className="center" style={fixedCenter}>
        Fixed to Center
      </div>
      <footer className="footer" style={fixedBottom}>
        Fixed to Bottom
      </footer>
    </div>
  );
};

useViewportDistanceFromPageTop

This hook calculates the distance from the top of the page to the Top/Center/Bottom of the visualViewport. The calculated values are used in the styles of useFixedStyleWithIosKeyboard, but they can also be used to freely customize styles in cases where that hook is not suitable.

import { useViewportDistanceFromPageTop } from 'react-ios-keyboard-viewport';
const { toTop, toCenter, toBottom } = useViewportDistanceFromPageTop();

useIOsKeyboardHeight

This hook calculates the height of the virtual keyboard of iOS. It is used inside useFixedStyleWithIosKeyboard to determine whether the iOS keyboard is open.

import { useiOsKeyboardHeight } from 'react-ios-keyboard-viewport';
const iOsKeyboardHeight = useiOsKeyboardHeight();

Contribution

Feel free to open an issue or make a pull request.

License

Distributed under the MIT License. See LICENSE for more information.

Keywords

FAQs

Package last updated on 06 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc