"react-native": "^0.44.0"

This commit is contained in:
MichaelSun 2017-05-25 17:24:15 +08:00
parent ebb089d763
commit 5270092dc8
2 changed files with 18 additions and 18 deletions

View File

@ -2,7 +2,7 @@
* Created by lvbingru on 12/16/15. * Created by lvbingru on 12/16/15.
*/ */
import React, {Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import ReactNative, { import ReactNative, {
InteractionManager, View, Text, ScrollView, Platform, Animated, UIManager, NativeModules, Dimensions, InteractionManager, View, Text, ScrollView, Platform, Animated, UIManager, NativeModules, Dimensions,
Keyboard, Keyboard,
@ -12,13 +12,13 @@ const ViewPlugins = NativeModules.InputScrollViewPlugin;
const dismissKeyboard = Keyboard.dismiss; const dismissKeyboard = Keyboard.dismiss;
const propTypes = { const propTypes = {
distance : PropTypes.number, distance: PropTypes.number,
tapToDismiss : PropTypes.bool, tapToDismiss: PropTypes.bool,
} }
const defaultProps = { const defaultProps = {
distance : 50, distance: 50,
tapToDismiss : true, tapToDismiss: true,
} }
export default class InputScrollView extends Component { export default class InputScrollView extends Component {
@ -59,7 +59,7 @@ export default class InputScrollView extends Component {
}); });
} }
}; };
onKeyboardWillHide = e=> { onKeyboardWillHide = e => {
if (!this.scrollViewRef) { if (!this.scrollViewRef) {
return; return;
} }
@ -70,11 +70,11 @@ export default class InputScrollView extends Component {
}; };
render() { render() {
const {distance, tapToDismiss, onKeyboardWillShow, keyboardShouldPersistTaps, children, ...others} = this.props const { distance, tapToDismiss, onKeyboardWillShow, keyboardShouldPersistTaps, children, ...others } = this.props
return ( return (
<View <View
style = {{flex:1}} style={{ flex: 1 }}
onStartShouldSetResponderCapture = {e=>{ onStartShouldSetResponderCapture={e => {
if (tapToDismiss === true) { if (tapToDismiss === true) {
const currentlyFocusedTextInput = TextInputState.currentlyFocusedField(); const currentlyFocusedTextInput = TextInputState.currentlyFocusedField();
if (e.target != currentlyFocusedTextInput) { if (e.target != currentlyFocusedTextInput) {
@ -82,7 +82,7 @@ export default class InputScrollView extends Component {
ViewPlugins.isTextInput( ViewPlugins.isTextInput(
e.target, e.target,
r => { r => {
if (r===false) { if (r === false) {
dismissKeyboard(); dismissKeyboard();
} }
} }
@ -97,13 +97,13 @@ export default class InputScrollView extends Component {
}} }}
> >
<ScrollView <ScrollView
style = {{flex:1}} style={{ flex: 1 }}
contentContainerStyle = {[{alignItems : 'stretch',}]} contentContainerStyle={[{ alignItems: 'stretch', }]}
keyboardShouldPersistTaps = {tapToDismiss?true:keyboardShouldPersistTaps} keyboardShouldPersistTaps={tapToDismiss ? 'always' : keyboardShouldPersistTaps ? always : 'never'}
ref={(srcollView) => { ref={(srcollView) => {
this.scrollViewRef = srcollView; this.scrollViewRef = srcollView;
}} }}
onMomentumScrollEnd = {e=>{ onMomentumScrollEnd={e => {
if (!this.moved) { if (!this.moved) {
this.offsetY = Math.max(0, e.nativeEvent.contentOffset.y) this.offsetY = Math.max(0, e.nativeEvent.contentOffset.y)
} }
@ -121,8 +121,8 @@ export default class InputScrollView extends Component {
UIManager.measureLayout( UIManager.measureLayout(
currentlyFocusedTextInput, currentlyFocusedTextInput,
ReactNative.findNodeHandle(this.scrollViewRef.getInnerViewNode()), ReactNative.findNodeHandle(this.scrollViewRef.getInnerViewNode()),
e=>{console.warning(e)}, e => { console.warning(e) },
(left, top, width, height)=>{ (left, top, width, height) => {
let keyboardScreenY = Dimensions.get('window').height; let keyboardScreenY = Dimensions.get('window').height;
if (e) { if (e) {
keyboardScreenY = e.endCoordinates.screenY; keyboardScreenY = e.endCoordinates.screenY;
@ -140,7 +140,7 @@ export default class InputScrollView extends Component {
} }
scrollToY(offsetY) { scrollToY(offsetY) {
this.scrollViewRef.scrollTo({x:0, y:offsetY}); this.scrollViewRef.scrollTo({ x: 0, y: offsetY });
} }
} }

View File

@ -26,6 +26,6 @@
"semver": "^5.1.0" "semver": "^5.1.0"
}, },
"peerDependencies": { "peerDependencies": {
"react-native": "^0.35.0" "react-native": "^0.44.0"
} }
} }