npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

on-screen-keyboard-detector

v2.3.0

Published

Detects presence of the On-Screen-Keyboard in mobile browsers

Downloads

14,680

Readme

NPM Version Dependencies Reactive Programming

On-screen keyboard detector

Indirect detection of the presence of the on-screen keyboard (OSK) shown by mobile browsers when the user interacts with input controls on a webpage.

Background

This approach employs the browsers layout and visual viewports (Explainer, MDN, Demo) to observe the appearance of the virtual keyboard.

Simplified, since it's introduction

  • Mobile Safari excludes the keyboard from the visual viewport, while
  • Chrome for Android the keyboard is excluded from both the visual and the layout viewport.

Browser Viewports

Chrome's behaviour makes it necessary to also observe focusin, focusout, resize and visibilitychange events.

Limitations

The indirect detection relying on viewport and window DOM events brings some limitations:

  • hidden and visible events are dispatched with a approximate 1 second delay.
  • On Chrome for Android the keyboard must be initially hidden when subscribing to the detector.
  • On iOS requires Safari v. ≥ 13
  • On iPad the predictive text bar, which is shown when an external keyboard is used, is not detected as visible keyboard.

iPad Predictive Text Bar

Because of these caveats, the straight-forward way of detecting blur and focus events on inputs should be explored before falling back on this project.

Install

npm install on-screen-keyboard-detector

Usage

Basic

import { subscribe, isSupported } from 'on-screen-keyboard-detector';

if (isSupported()) {
	const unsubscribe = subscribe(visibility => {
		if (visibility === "hidden") {
			// ...
		}
		else { // visibility === "visible"
			// ...
		}
	});
	
	// After calling unsubscribe() the callback will no longer be invoked.
   unsubscribe();
}

API

subscribe(listenerCallback): unsubscribe

Begins to observe browser events and invokes the provided callback function when a change in the keyboard visibility is detected.

| Parameter | Type | Description | |-----------|------|-------------| | callback |function(String)| user-defined handler which receives the keyboard visibility changes |

Return value

function(): void : Unsubscribes to receive updates

isSupported()

Returns true if the browser runtime supports oskd.

Advanced Usage

Multiple Subscriptions (PubSub)

PubSub is not part of this module and needs additional tools, e.g. emittery. See demo/pubsub.html

import {subscribe} from 'on-screen-keyboard-detector';
import Emitter from 'emittery';

const emitter = new Emitter();

subscribe(visibility => emitter.emit(visibility));

emitter.on('hidden', function() { /* ... */ });
emitter.on('visible', function() { /* ... */ });

Tests

Requirements (not listed in package.json)

  • mocha :coffee:
  • chai :tea:
  • selenium-webdriver
  • a Mac for Mobile Safari tests
  • running a local webserver (see TEST_SERVER in package.json), E.g. run http-server in the project root folder http-server . --port 8081

Android

For real devices make sure

  • the adb server is running (adb start-server), and
  • a device is connected via USB or Wifi (adb devices -l)
  • ggf. adb tcpip 5555 and adb connect <test phone ip address> (see "setup_test" in package.json) Then run npm run test:chrome.

iOS

Connect a device where Remote Automatation is enabled for Safari (see the Webkit blog). Then run npm run test:ios

iOS tests should be performed manually (see the demo folder), because Webdriver controlled Mobile Safari does not show the virtual keyboard

Dependencies

Ramda, and Most for the reactive functional infrastructure.

Changelog (See changelog.md)