Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
react-native-avoid-softinput
Advanced tools
Native logic for avoiding covering text inputs by soft input views
react-native-avoid-softinput
Native solution for common React Native problem of focused views being covered by soft input view. It is solved by listening for soft input events and applying bottom padding to react root view entirely on native side and only if currently focused view is covered by soft input frame. It supports focused views being positioned in scroll views and regular views (check out example app).
yarn add react-native-avoid-softinput
On iOS run additionally
npx pod-install
:warning: Library on iOS uses Swift. Make sure that your project has bridging header configured (the easiest way is to create empty
.swift
file in XCode, which will offer to create bridging header)
Enable module:
import React from "react";
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
React.useEffect(() => {
AvoidSoftinput.setEnabled(true);
}, []);
//...
Enable module:
Before using module on Android, check if system support (android:windowSoftInputMode="adjustResize"
in Android manifest for <activity>
tag) is enough for your use case.
If you cannot use system support, then enable module and set android:windowSoftInputMode
attribute to adjustNothing
either in manifest or programmatically with setAdjustNothing
method
:warning: Do not enable module with
adjustResize
value set, as it will result in padding being applied to already resized android window
import React from "react";
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
React.useEffect(() => {
AvoidSoftinput.setAdjustNothing();
AvoidSoftinput.setEnabled(true);
}, []);
//...
If you want to listen to events when soft input is shown/hidden:
import React from "react";
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
React.useEffect(() => {
const unsubscribeShown = AvoidSoftinput.onSoftInputShown(
({ softInputHeight }) => {
console.log("soft input shown", softInputHeight); // Soft input is shown with height
}
);
const unsubscribeHidden = AvoidSoftInput.onSoftInputHidden(() => {
console.log("soft input hidden"); // Soft input is hidden
});
return () => {
unsubscribeShown.remove();
unsubscribeHidden.remove();
};
}, []);
//...
android:windowSoftInputMode
attribute (Android only) Library exposes methods for managing android:windowSoftInputMode
value:
setAdjustNothing
Sets android:windowSoftInputMode
to adjustNothing
value
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
AvoidSoftinput.setAdjustNothing();
//...
setAdjustPan
Sets android:windowSoftInputMode
to adjustPan
value
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
AvoidSoftinput.setAdjustPan();
//...
setAdjustResize
Sets android:windowSoftInputMode
to adjustResize
value
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
AvoidSoftinput.setAdjustResize();
//...
setAdjustUnspecified
Sets android:windowSoftInputMode
to adjustUnspecified
value
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
AvoidSoftinput.setAdjustUnspecified();
//...
setDefaultAppSoftInputMode
sets android:windowSoftInputMode
to default value from Android manifest
import * as AvoidSoftinput from "react-native-avoid-softinput";
//...
AvoidSoftinput.setDefaultAppSoftInputMode();
//...
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
FAQs
Native logic for avoiding covering text inputs by soft input views
The npm package react-native-avoid-softinput receives a total of 13,906 weekly downloads. As such, react-native-avoid-softinput popularity was classified as popular.
We found that react-native-avoid-softinput demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.