KeyboardToolbar
KeyboardToolbar
is a view that sticky to the keyboard and has next and previous buttons for switching between inputs as well as Done button for closing the keyboard.
This component is fully customizable and allows you to define any behavior for provided buttons and also allows you to render additional content.
Features
- Fully customizable UI 🎨: Tailor the appearance of the toolbar to match your app's design.
- Supports dark/light theme 🌓: Adapts to the theme settings of the user's device for a seamless experience.
- Extended accessibility support 🔍: Ensures that all users, including those with disabilities, can navigate through inputs effectively.
- Full control over the buttons behavior 🔧: Customize the actions triggered by the next, previous, and done buttons according to your needs.
- Extends ViewProps 📜: Supports all the props that
View
component has.
Props
View Props
Inherits View Props.
KeyboardStickyViewProps
Inherits KeyboardStickyViewProps.
button
This property allows to render custom touchable component for next, previous and done button.
import { TouchableOpacity } from "react-native-gesture-handler";
import {
KeyboardToolbar,
KeyboardToolbarProps,
} from "react-native-keyboard-controller";
const CustomButton: KeyboardToolbarProps["button"] = ({
children,
onPress,
}) => <TouchableOpacity onPress={onPress}>{children}</TouchableOpacity>;
// ...
<KeyboardToolbar button={CustomButton} />;
blur
This property allows to render custom blur effect for the toolbar (by default iOS keyboard is opaque and it blurs the content underneath, so if you want to follow HIG (Human Interface Guidelines) properly - consider to add this effect).
By default it is null
and will not render any blur effect, because it's not a responsibility of this library to provide a blur effect. Instead it provides a property where you can specify your own blur effect and its provider, i. e. @react-native-community/blur
, expo-blur
or maybe even react-native-skia
(based on your project preferences of course).
Please, note, that you need to specify opacity
prop for this prop to work. Because otherwise you will not see a blur effect.
import { BlurView } from "@react-native-community/blur";
import {
KeyboardToolbar,
KeyboardToolbarProps,
} from "react-native-keyboard-controller";
const CustomBlur: KeyboardToolbarProps["blur"] = ({ children }) => (
<BlurView
blurType="chromeMaterial"
blurAmount={10}
reducedTransparencyFallbackColor="white"
style={{ position: "absolute", top: 0, left: 0, bottom: 0, right: 0 }}
>
{children}
</BlurView>
);
// ...
<KeyboardToolbar blur={CustomBlur} opacity="4F" />;
content
This property allows you to show a custom content in the middle of the toolbar. It accepts JSX element. Default value is null
.
<KeyboardToolbar
content={
showAutoFill ? (
<AutoFillContacts onContactSelected={onContactSelected} />
) : null
}
/>
doneText
The property that allows to specify custom text for Done
button.
<KeyboardToolbar doneText="Close" />
icon
icon
property allows to render custom icons for prev and next buttons.
import { Text } from "react-native";
import {
KeyboardToolbar,
KeyboardToolbarProps,
} from "react-native-keyboard-controller";
const Icon: KeyboardToolbarProps["icon"] = ({ type }) => {
return <Text>{type === "next" ? "⬇️" : "⬆️"}</Text>;
};
// ...
<KeyboardToolbar icon={Icon} />;