Skip to content

Commit ed0e262

Browse files
committed
fix issue with text input height on Android
1 parent 0fa97f8 commit ed0e262

File tree

2 files changed

+7
-62
lines changed

2 files changed

+7
-62
lines changed

src/components/inputs/TextInput.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,11 @@ export default class TextInput extends BaseInput {
188188
}
189189

190190
getHeight() {
191-
const {multiline, numberOfLines} = this.props;
192-
if (multiline && numberOfLines) {
193-
if (Constants.isAndroid) {
194-
return undefined;
195-
} else if (!this.state.height) {
196-
// get numberOfLines support for iOS
197-
this.setState({height: this.getLinesHeightLimit()});
198-
}
199-
}
200-
201-
if (multiline) {
202-
const {height} = this.state;
203-
return height;
191+
const {multiline} = this.props;
192+
if (!multiline) {
193+
const typography = this.getTypography();
194+
return typography.lineHeight;
204195
}
205-
206-
const typography = this.getTypography();
207-
return typography.lineHeight;
208196
}
209197

210198
getLinesHeightLimit() {
@@ -353,7 +341,7 @@ export default class TextInput extends BaseInput {
353341
}
354342

355343
renderTextInput() {
356-
const {value, height} = this.state;
344+
const {value} = this.state;
357345
const color = this.props.color || this.extractColorValue();
358346
const typography = this.getTypography();
359347
const {
@@ -369,7 +357,7 @@ export default class TextInput extends BaseInput {
369357
this.styles.input,
370358
typography,
371359
color && {color},
372-
{height},
360+
{height: this.getHeight()},
373361
style,
374362
];
375363

src/components/inputs/__tests__/TextInput.spec.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import TextInput from '../TextInput';
2-
import {Constants} from '../../../helpers';
3-
import {Typography, Colors} from '../../../style';
4-
2+
import {Colors} from '../../../style';
53

64
describe('TextInput', () => {
75
// beforeEach(() => {});
@@ -50,42 +48,6 @@ describe('TextInput', () => {
5048
});
5149
});
5250

53-
describe('getHeight', () => {
54-
it('when not multiline, should setState not be called', () => {
55-
const uut = new TextInput({});
56-
jest.spyOn(uut, 'setState').mockImplementation(() => {});
57-
uut.getHeight();
58-
expect(uut.setState).not.toHaveBeenCalled();
59-
});
60-
61-
it('should iOS, when only multiline, setState height with undefined', () => {
62-
const uut = new TextInput({multiline: true});
63-
jest.spyOn(uut, 'setState').mockImplementation(() => {});
64-
uut.getHeight();
65-
expect(uut.setState.height).toBeUndefined();
66-
});
67-
68-
it('should iOS, when multiline and numberOfLines, setState height with typography * numberOfLines', () => {
69-
const uut = new TextInput({multiline: true, numberOfLines: 2});
70-
jest.spyOn(uut, 'setState').mockImplementation(() => {});
71-
jest.spyOn(uut, 'getTypography');
72-
uut.getTypography.mockReturnValue(Typography.text70);
73-
const lineHeight = Typography.text70.lineHeight;
74-
const {numberOfLines} = uut.props;
75-
const boxHeight = lineHeight * numberOfLines;
76-
uut.getHeight();
77-
expect(uut.setState).toHaveBeenCalledWith({height: boxHeight});
78-
});
79-
80-
it('should Android, when multiline and numberOfLines, setState not be called', () => {
81-
mockAndroid();
82-
const uut = new TextInput({multiline: true, numberOfLines: 2});
83-
jest.spyOn(uut, 'setState').mockImplementation(() => {});
84-
uut.getHeight();
85-
expect(uut.setState).not.toHaveBeenCalled();
86-
});
87-
});
88-
8951
describe('getCharCount', () => {
9052
it('should return 5 when value is "inbal"', () => {
9153
const uut = new TextInput({value: 'inbal'});
@@ -108,8 +70,3 @@ describe('TextInput', () => {
10870
});
10971
});
11072
});
111-
112-
function mockAndroid() {
113-
Constants.isIOS = false;
114-
Constants.isAndroid = true;
115-
}

0 commit comments

Comments
 (0)