Responding to the Keyboard With React Native

Creating dynamic layouts that adapt to the on-screen keyboard.

One of the best things in React Native is the ability to write the native interface with Javascript that feels way better than any hybrid solution out there. With your UI represented as a set of UIViews, UITextInputs are not only a great way to make your app interactive but also to make your users feel at home.

In almost all typical applications, we have forms. We use them to interact with our users by getting the data they have provided. With forms, comes our good friend — the state-of-art iOS keyboard. In this short article, we are going to show you how we’ve managed to make your interface play well with different keyboard states by utilising react-native-keyboardevents, making it super easy to replicate that functionality between different pages.

Poor little postcode field… why does everyone keep ignoring you :(

Who wants letters in their email address anyway?

Step 1

The events

Before we start thinking about adjusting our UI to our keyboard, we first need to somehow get its state. We ideally want to know whether the keyboard is open or not, and what frame size the keyboard is occupying on the screen. In order to achieve that, we are going to add one small dependency to our project — the react-native-keyboardevents package.

Once you have successfully integrated the above package into your project, take a look at the below code sample from its repository:

[gist]ab4981fc7c10ba2b31de[/gist]

Yeah, I know higher order components for the win, but let’s stick with a pattern everyone knows. I assume everyone familiar with the new ES6 approach will be able to rewrite that in a couple of seconds!

This snippet will update our state whenever the keyboard event occurs, giving us all the information we need about the keyboard height and its state.

Step 2

The component

We’ve already nailed our keyboard events, so now let’s start on simple implementation by taking a look at the simple form we might have in our app.

[gist]96ad065f99c6929fdc38[/gist]

The above Page (the application is an Este.js implementation, which I strongly recommend you have a look at) simply displays the LoginForm component that contains some inputs. Whenever they are active, the padding will change and will move the LoginForm to the top of the screen making the last input still visible (previously it had been overlapped by our keyboard).

Now we can set a postcode without hiding the keyboard!

Step 3

The animations

As you may have noticed, the above implementation will cause our UI to jump from the previous to the new state in quite an ugly way. We all love animations and it’s something iOS is awesome at. So let’s take the simplest solution possible and utilise the LayoutAnimation engine.

Try adding the following:

[gist]7a860fe69f842572effb[/gist]

You now get beautiful animations of your choice whenever the keyboard state changes.

Here’s the final effect:

Now with added smoothness!

That’s a simple way to add some pizzazz to your apps and give your lower inputs the loving they deserve!

Insights

Learn more about React Native

cover

Aug 4Podcast

VisionCamera V5 With Marc Rousavy

Marc Rousavy joins Mike Grabowski to unpack VisionCamera v5, Nitro Modules, the constraints API, migration work, and what changed for React Native camera apps.

cover

Jul 1Podcast

Redraw for Effects Beyond Skia

William Candillon talks about where Redraw fits next to Skia, from physics-based rendering to camera effects, AR, and new UI patterns.

cover

Jun 29Article

Less Boilerplate, More Type Safety: React Navigation 8's Typed Hooks

React Navigation 8 improves typed hooks with screen-aware types, less boilerplate, and fewer unsafe casts in shared UI and nested navigators.

cover

Apr 30Live Stream

Build a React Native App With the TanStack Stack

Join Callstack’s live stream on building a React Native app from the ground up using the TanStack toolbelt.

cover

Apr 28Article

React Native production lessons from React Universe Meetup x Zalando

Lessons from React Universe Meetup x Zalando on React Native in production, covering brownfield performance, feed video, native API access, and on-device AI.

cover

Apr 23Talk

Shipping iOS Live Activities with React: The Voltra Story

How Voltra enables Live Activities and Dynamic Island views using React without writing Swift. A deep dive into iOS constraints and architecture.

cover

Apr 16Live Stream

React Native 0.85: Animation Backend and Key Updates

A recap of React Native 0.85, covering the new animation backend, DevTools improvements, and ecosystem takeaways.

cover

Mar 5Article

Keeping Screens Visible With <Activity mode="hidden">

A cross‑platform workaround to keep screens visible while <Activity mode="hidden"> unmounts effects on inactive screens by setting mode="hidden".

cover

Feb 25Article

React Native Monorepo With pnpm Workspaces

Set up a React Native monorepo with pnpm workspaces for mobile and Next.js web, including Metro fixes, hoisted node-linker, and shared packages.

cover

Feb 18Article

A Practical Guide to React Native Monorepo With Yarn Workspaces

Learn how to set up a React Native monorepo with Yarn workspaces for mobile and web, including Metro, Gradle, and shared packages.

cover

Feb 17Podcast

From Teddy Bears to Voice Agents: Kraen Hansen on Voice AI, Local-First & App Security

What happens when you combine voice agents and teddy bears? A hands-on look at local-first systems, voice AI, and security lessons from poking real apps.

cover

Jan 28Article

Bringing CSS Clipping to React Native

A deep look at how a single CSS feature moves through React Native’s New Architecture, from JavaScript styles to native rendering on iOS and Android.

cover

Mar 19Tutorial

The Hard Way vs. The React Native AI SDK Way: Stop Writing Custom Modules for Every Model

Learn how React Native AI uses a unified provider model to switch between cloud and on-device LLMs without rewriting application logic, enabling reliable AI experiences online and offline.

cover

Mar 12Tutorial

Build Smarter Apps: Tool Calling & AI Orchestration Explained

Learn how on-device models in React Native can call tools, interact with external APIs, and return structured outputs you can use directly in application logic.

cover

Mar 5Tutorial

MLC LLM + React Native: On-Device AI Without the Pain

Learn how to run third-party on-device LLMs in React Native using MLC LLM. Choose your models, run them efficiently across platforms, and keep a unified JavaScript API with React Native AI.

cover

Feb 24Tutorial

Intelligent Fallbacks with Apple Intelligence in React Native

Learn how to use Apple’s built-in Foundation Models in React Native apps, reduce memory usage, and enable fast, fully on-device AI with React Native AI Apple.

cover

Feb 10Tutorial

What Is the React Native AI SDK? A Complete Intro & Quickstart

Learn why on-device AI matters for React Native apps, how local LLMs behave offline, and what problems React Native AI is designed to solve from day one.

cover

Jan 29Tutorial

Implementing an Android TurboModule with Kotlin

Learn how to implement a React Native TurboModule on Android, from the TypeScript spec and Codegen to the Kotlin implementation and package registration.

cover

Jan 19Tutorial

Working with Different Threads in Swift TurboModules

Learn how JavaScript, native module, background, and main threads interact in React Native TurboModules, and how to use GCD queues to run async work safely in Swift.

cover

Jan 9Tutorial

How to Add Type-Safe Constants to Swift TurboModules

Learn how to expose typed, immutable constants from a Swift TurboModule using Codegen, and get full end-to-end type safety between native and JavaScript.

cover

Dec 30Tutorial

Adding Event Emitters to Your TurboModule in Swift

Learn how to emit native events from a Swift TurboModule and subscribe to them in JavaScript, including proper memory management and Codegen integration.

cover

Dec 22Tutorial

Writing Your First TurboModule in Swift

Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.