Skip to content

Commit 3aa93f0

Browse files
committed
fix(textfield): ensure we request layout only when necessary
1 parent ec3a420 commit 3aa93f0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/textfield/textfield.ios.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
placeholderColorProperty
3333
} from '@nativescript/core';
3434
import { textProperty } from '@nativescript/core/ui/text-base';
35+
import { layout } from '@nativescript/core/utils';
3536
import { TextFieldBase } from './textfield.common';
3637

3738
@NativeClass
@@ -171,13 +172,19 @@ export class TextField extends TextFieldBase {
171172
}
172173

173174
this.firstEdit = false;
174-
if (this.width === 'auto') {
175+
if (this.mCanAutoSize) {
175176
// if the textfield is in auto size we need to request a layout to take the new text width into account
176177
this.requestLayout();
177178
}
178179
return true;
179180
// return super.textFieldShouldChangeCharactersInRangeReplacementString(textField, range, replacementString);
180181
}
182+
private mCanAutoSize = false;
183+
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
184+
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
185+
this.mCanAutoSize = widthMode !== layout.EXACTLY;
186+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
187+
}
181188

182189
_getTextInsetsForBounds(insets: UIEdgeInsets): UIEdgeInsets {
183190
const style = this.style;

0 commit comments

Comments
 (0)