Skip to content

Commit

Permalink
use lodashClamp for calc textInput height
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdshrif committed Jul 19, 2023
1 parent 57ff809 commit 6c3ad47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ function BaseTextInput(props) {
onPress={onPress}
focusable={false}
accessibilityLabel={props.label}
style={[props.autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, maxHeight), !isMultiline && styles.componentHeightLarge, ...props.containerStyles]}
style={[
props.autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, maxHeight),
!isMultiline && styles.componentHeightLarge,
...props.containerStyles,
]}
>
<View
// When autoGrowHeight is true we calculate the width for the textInput, so it will break lines properly
Expand Down
21 changes: 11 additions & 10 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defaultStyles as defaultPickerStyles} from 'react-native-picker-select/src/styles';
import lodashClamp from 'lodash/clamp';
import fontFamily from './fontFamily';
import addOutlineWidth from './addOutlineWidth';
import themeColors from './themes/default';
Expand Down Expand Up @@ -855,16 +856,16 @@ const styles = {
backgroundColor: themeColors.buttonDefaultBG,
},

autoGrowHeightInputContainer: (textInputHeight, maxHeight) => {
const minHeight = variables.componentSizeLarge;
let height = textInputHeight;
if (height >= maxHeight) {
height = maxHeight;
} else if (height <= minHeight) {
height = minHeight;
}
return {height, minHeight};
},
/**
* @param {number} textInputHeight
* @param {number} minHeight
* @param {number} maxHeight
* @returns {object}
*/
autoGrowHeightInputContainer: (textInputHeight, minHeight, maxHeight) => ({
height: lodashClamp(textInputHeight, minHeight, maxHeight),
minHeight,
}),

autoGrowHeightHiddenInput: (maxWidth, maxHeight) => ({
maxWidth,
Expand Down

0 comments on commit 6c3ad47

Please sign in to comment.