react-native-auto-grow-textinput
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "react-native-auto-grow-textinput", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "This component allows to create auto grow text input for both platforms (iOS and Android).", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,4 +0,2 @@ | ||
/** | ||
* @flow | ||
*/ | ||
// @flow | ||
@@ -17,2 +15,3 @@ import React, { Component } from 'react'; | ||
onResized?: () => void; | ||
value: ?string; | ||
}; | ||
@@ -22,6 +21,6 @@ | ||
limit: ?number; | ||
text: string; | ||
height: number; | ||
}; | ||
export default class AutoGrowTextInput extends React.Component { | ||
@@ -42,3 +41,2 @@ props: Props; | ||
limit, | ||
text: '', | ||
height: 30, | ||
@@ -52,3 +50,3 @@ }; | ||
const textInputStyle = { | ||
height: this.state.height, | ||
height: this.state.height | ||
}; | ||
@@ -64,16 +62,3 @@ | ||
underlineColorAndroid='transparent' | ||
onChange={ (event) => { | ||
const { contentSize } = event.nativeEvent; | ||
const allowResized = this.state.height !== contentSize.height; | ||
const height = this._calcHeight(contentSize.height); | ||
this.setState({ | ||
text: event.nativeEvent.text, | ||
height, | ||
}); | ||
if (allowResized && this.props.onResized) { | ||
this.props.onResized(); | ||
} | ||
}} | ||
onContentSizeChange={ this._onContentSizeChange } | ||
style={[ externalStyle, textInputStyle ]} | ||
@@ -84,16 +69,16 @@ /> | ||
_calcHeight(actualHeight: number): number { | ||
let result; | ||
_onContentSizeChange = (event) => { | ||
const { contentSize } = event.nativeEvent; | ||
const height = _calcHeight(contentSize.height, this.state.limit); | ||
if (this.state.limit) { | ||
result = this.state.limit > actualHeight | ||
? actualHeight | ||
: this.state.limit; | ||
if (height === this.state.height) { | ||
return; | ||
} | ||
else { | ||
result = Math.max(30, actualHeight); | ||
} | ||
this.setState({ height }); | ||
this.props.onResized && this.props.onResized(); | ||
} | ||
return result; | ||
} | ||
}; | ||
const _calcHeight = (actualHeight: number, limit:? number) => | ||
limit ? Math.min(limit, actualHeight): Math.max(30, actualHeight); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14979
66