Simple drop-in replacement for React Native <TextInput>
that makes devs happy π
This is the very first version and that's why it offers just a few props to customize it: overlayColor
, header
, footer
and animationConfig
.
However, that covers a lot of use cases.
Here is a snack so you can give it a try! https://snack.expo.io/@gaguirre/rnspotlightinput-demo
yarn add react-native-spotlight-input
import React, { Component } from 'react'
import Text from 'react-native'
import TextInput from 'react-native-spotlight-input'
class Example extends Component {
render() {
return (
<TextInput
// ...traditionalInputProps
overlayColor="#0496FF"
header={() => <Text>Header</Text>}
footer={() => <Text>Footer</Text>}
animationConfig={{
duration: 350,
delay: 100,
}}
/>
)
}
}
A string
defining the background color when focused
const Example = () => (
<TextInput
// ...other props
overlayColor="#0496FF"
/>
)
A component (could be either function
or class
component) that takes inputValue
as a prop.
Will be rendered before the TextInput
when focused.
const Header = ({ inputValue }) => <Text>You are writing this: {inputValue}</Text>
const WithHeader = () => (
<TextInput
// ...other props
header={Header}
/>
)
A component (could be either function or class component) that takes inputValue
as a prop.
Will be rendered after the TextInput
when focused.
const Footer = ({ inputValue }) => <Text>You have written this: {inputValue}</Text>
const WithFooter = () => (
<TextInput
// ...other props
footer={Footer}
/>
)
Is an object to override Animated.timing
configuration.
import { Easing } from 'react-native'
const animationConfig = {
delay: 100,
duration: 500,
easing: Easing.in(Easing.ease),
}
const WithCustomAnimationConfig = () => (
<TextInput
// ...other props
animationConfig={animationConfig}
/>
)
Default value is
{
delay: 0,
duration: 350,
easing: Easing.inOut(Easing.ease),
}
Notice that useNativeDriver
and toValue
cannot be overwritten.
Decides wether or not the component should collapse on keyboard hide. Default value is true
.
const NoCollapseOnKeyboardHide = () => (
<TextInput
// ...other props
collapseOnKeyboardHide={false}
/>
)
Besides the props, you can control it using the component ref.
Calling componentRef.expand()
you can show the expanded mode of the component
Calling componentRef.collapse()
you can go back to the collapsed mode of the component
class ControlledInputExample extends Component {
constructor() {
super()
this.componentRef = React.createRef()
}
handleExpandButtonPress = () => {
this.componentRef.expand()
}
handleCollapseButtonPress = () => {
this.componentRef.collapse()
}
render() {
return (
<View>
<TextInput
ref={this.componentRef}
footer={() => <Button title="Collapse" onPress={this.handleCollapseButtonPress} />}
collapseOnKeyboardHide={false}
/>
<Button title="Expand" onPress={this.handleExpandButtonPress} />
</View>
)
}
}
See the ReactNativeSpotlightInputExample
folder in packages
to find more detailed examples.
- In DEV mode you can't use the developer tools when input is focused due to this RN issue
- If input has borders then those will be visible during transition to focused state