Code for React Native Sortable Listview with KeyboardAware

Krissada Chalermsook
krissada
Published in
1 min readJul 1, 2017

I faced a lot of problem with react-native and iOS keyboard

  1. First, the view will be covered by keyboard if there is a TextInput and you are focusing on the TextInput. The solution for this is quite simple. We can just use https://facebook.github.io/react-native/docs/keyboardavoidingview.html
  2. However, I also use https://github.com/deanmcpherson/react-native-sortable-listview based of my requirement of the app… So, how can I make the ListView and can be sortable and acted the same as KeyboardAvoidingView. I cannot find the code anywhere, so I write it by myself but just lazy to put it to github. So, I just paste it here
/* @flow */import React, { PropTypes } from 'react'
import { ListView } from 'react-native'
import {KeyboardAwareMixin} from 'react-native-keyboard-aware-scroll-view'
import SortableListView from 'react-native-sortable-listview';
const KeyboardAwareDragableListView = React.createClass({
propTypes: {
viewIsInsideTabBar: React.PropTypes.bool,
resetScrollToCoords: PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
}),
},
mixins: [KeyboardAwareMixin],
componentWillMount: function () {
this.setViewIsInsideTabBar(this.props.viewIsInsideTabBar)
this.setResetScrollToCoords(this.props.resetScrollToCoords)
},
render: function () {
return (
<SortableListView
ref='_rnkasv_keyboardView'
keyboardDismissMode='interactive'
contentInset={{bottom: this.state.keyboardSpace}}
showsVerticalScrollIndicator={true}
scrollEventThrottle={0}
{...this.props}
onScroll={e => {
this.handleOnScroll(e)
this.props.onScroll && this.props.onScroll(e)
}}
/>
)
},
})
export default KeyboardAwareDragableListView

OK Done.

--

--

Krissada Chalermsook
krissada

Instructor, Entrepreneur, Geek, Technology lover, Project Manager with the dream to spread good education to everyone in Thailand with http://www.acourse.io