Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Perfect TextInput ScrollView

License

NotificationsYou must be signed in to change notification settings

baijunjie/react-native-input-scroll-view

Repository files navigation

Mainly to achieve the following functions:

  • When the keyboard pops up, theTextInput will automatically adjust to the top of the keyboard.
  • When the keyboard pops up, the content of theScrollView will not be obscured by the keyboard.
  • When multilineTextInput gets focus, the selected cursor will be automatically adjusted to the top of the keyboard.
  • When the multilineTextInput create new line, the new line will automatically adjust to the top of the keyboard.
  • Put your finger on top ofTextInput and slideScrollView, when you lift your finger, theTextInput will not get focus.

    

Installation

npm

$ npm install react-native-input-scroll-view --save

yarn

$ yarn add react-native-input-scroll-view

Usage

importInputScrollViewfrom'react-native-input-scroll-view';...state={text:'',};render(){const{ text}=this.state;return(<InputScrollView><TextInput/><TextInput/><TextInputvalue={text}onChangeText={text=>this.setState({ text})}multiline/></InputScrollView>);}

React-native-input-scroll-view automatically modify onContentSizeChange, onSelectionChange, and onChangeTextInput props. It is not yet designed to pass them down if theTextInput is wrapped into another component so don’t forget to do it:

importInputScrollViewfrom'react-native-input-scroll-view';...constMyComponent=props=>(<View><TextInput{...props}/></View>);...state={text:'',};render(){const{ text}=this.state;return(<InputScrollView><MyComponentvalue={text}onChangeText={text=>this.setState({ text})}/></InputScrollView>);}

Note that if the cursor is to be correctly adjusted to the top of the keyboard, you must bindvalue toTextInput.

Multiline TextInput in the Android

If your ReactNative version is on or abovev0.57, skip this section.

Before a certain version of ReactNative, multilineTextInput height on an Android device could not change properly based on its content, so we need to add additional processing code

importInputScrollViewfrom'react-native-input-scroll-view';...state={text:'',textareaHeight:null,};render(){const{ text, textareaHeight}=this.state;return(<InputScrollView><TextInput/><TextInput/><TextInputstyle={{height:textareaHeight}}value={text}onChangeText={text=>this.setState({ text})}onContentSizeChange={this._onContentSizeChange}multiline/></InputScrollView>);}_onContentSizeChange=({nativeEvent:event})=>{this.setState({textareaHeight:event.contentSize.height});};

Props

PropertyTypeDefaultDescription
topOffsetnumberundefinedThe offset of theInputScrollView relative to the top of the window. When the screen containsTopBar, it is usually set to the height ofTopBar. If not explicitly set, the program will automatically determine, but may cause problems.issues#43
keyboardOffsetnumber40When automatic adjustment, the cursor relative to the top of the keyboard offset.
multilineInputStyleStylenullIf your multilineTextInput has a specific style, to ensure that the cursor can be accurately adjusted to the top of the keyboard, this is set as a multilineTextInput style, The style attributes that mainly includefontSizefontFamilylineHeight etc. affect the position of the cursor.Be careful not to includewidth andheight.
useAnimatedScrollViewboolfalseReplace regularScrollView component withAnimated.ScrollView component.
supportHardwareKeyboardboolfalsebeta If your device does not use a soft keyboard, try using this parameter to solve the problem.issues#69
keyboardAvoidingViewPropspropsnullKeyboardAvoidingView component Props. Check them here:https://facebook.github.io/react-native/docs/keyboardavoidingview
...ScrollView.propspropsAll props from ScrollView are inherited. Check them here:https://facebook.github.io/react-native/docs/scrollview.html

ENV

"react": "^16.0.0-alpha.12""react-native": ">=0.46.0"

Product case

App_Store

License

MIT

About

Perfect TextInput ScrollView

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp