|
| 1 | +--- |
| 2 | +id: inputaccessoryview |
| 3 | +title: InputAccessoryView |
| 4 | +--- |
| 5 | + |
| 6 | +A component which enables customization of the keyboard input accessory view on iOS. The input accessory view is displayed above the keyboard whenever a `TextInput` has focus. This component can be used to create custom toolbars. |
| 7 | + |
| 8 | +To use this component wrap your custom toolbar with the InputAccessoryView component, and set a `nativeID`. Then, pass that `nativeID` as the `inputAccessoryViewID` of whatever `TextInput` you desire. A simple example: |
| 9 | + |
| 10 | +```ReactNativeWebPlayer |
| 11 | +import React, { Component } from 'react'; |
| 12 | +import { View, ScrollView, AppRegistry, TextInput, InputAccessoryView, Button } from 'react-native'; |
| 13 | +
|
| 14 | +export default class UselessTextInput extends Component { |
| 15 | + constructor(props) { |
| 16 | + super(props); |
| 17 | + this.state = {text: 'Placeholder Text'}; |
| 18 | + } |
| 19 | +
|
| 20 | + render() { |
| 21 | + const inputAccessoryViewID = "uniqueID"; |
| 22 | + return ( |
| 23 | + <View> |
| 24 | + <ScrollView keyboardDismissMode="interactive"> |
| 25 | + <TextInput |
| 26 | + style={{ |
| 27 | + padding: 10, |
| 28 | + paddingTop: 50, |
| 29 | + }} |
| 30 | + inputAccessoryViewID={inputAccessoryViewID} |
| 31 | + onChangeText={text => this.setState({text})} |
| 32 | + value={this.state.text} |
| 33 | + /> |
| 34 | + </ScrollView> |
| 35 | + <InputAccessoryView nativeID={inputAccessoryViewID}> |
| 36 | + <Button |
| 37 | + onPress={() => this.setState({text: 'Placeholder Text'})} |
| 38 | + title="Reset Text" |
| 39 | + /> |
| 40 | + </InputAccessoryView> |
| 41 | + </View> |
| 42 | + ); |
| 43 | + } |
| 44 | +} |
| 45 | +
|
| 46 | +// skip this line if using Create React Native App |
| 47 | +AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput); |
| 48 | +``` |
| 49 | + |
| 50 | +This component can also be used to create sticky text inputs (text inputs which are anchored to the top of the keyboard). To do this, wrap a `TextInput` with the `InputAccessoryView` component, and don't set a `nativeID`. For an example, look at [InputAccessoryViewExample.js](https://github.com/facebook/react-native/blob/master/RNTester/js/InputAccessoryViewExample.js). |
| 51 | + |
| 52 | +### Props |
| 53 | + |
| 54 | +* [`backgroundColor`](inputaccessoryview.md#backgroundcolor) |
| 55 | +* [`nativeID`](inputaccessoryview.md#nativeid) |
| 56 | +* [`style`](inputaccessoryview.md#style) |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +# Reference |
| 61 | + |
| 62 | +## Properties |
| 63 | + |
| 64 | +### `backgroundColor` |
| 65 | + |
| 66 | +| Type | Required | |
| 67 | +| ------------------ | -------- | |
| 68 | +| [color](colors.md) | No | |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### `nativeID` |
| 73 | + |
| 74 | +An ID which is used to associate this `InputAccessoryView` to specified TextInput(s). |
| 75 | + |
| 76 | +| Type | Required | |
| 77 | +| ------ | -------- | |
| 78 | +| string | No | |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +### `style` |
| 83 | + |
| 84 | +| Type | Required | |
| 85 | +| ---------------------------- | -------- | |
| 86 | +| [style](view-style-props.md) | No | |
0 commit comments