Skip to content

Commit 9629e28

Browse files
committed
fix(textfield): some padding fixes to be the same on ios/android
1 parent e6558de commit 9629e28

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

packages/textfield/platforms/android/res/values/textfieldstyles.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<item name="backgroundColor">@null</item>
66
<item name="android:paddingLeft">0dp</item>
77
<item name="android:paddingRight">0dp</item>
8-
<item name="android:paddingTop">13dp</item>
9-
<item name="android:paddingBottom">13dp</item>
8+
<item name="android:paddingTop">0dp</item>
9+
<item name="android:paddingBottom">0dp</item>
1010
</style>
1111
<style name="ThemeOverlay" parent="@style/ThemeOverlay.MaterialComponents.TextInputEditText.FilledBox">
1212
<item name="editTextStyle">@style/TextInputEditText</item>

src/textfield/textfield.android.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ import {
1313
strokeDisabledColorProperty,
1414
strokeInactiveColorProperty
1515
} from '@nativescript-community/ui-material-core/textbase/cssproperties';
16-
import { Background, Color, Font, Utils, backgroundInternalProperty, borderBottomLeftRadiusProperty, fontInternalProperty, hintProperty, placeholderColorProperty, profile } from '@nativescript/core';
16+
import {
17+
Background,
18+
Color,
19+
Font,
20+
Length,
21+
Utils,
22+
backgroundInternalProperty,
23+
borderBottomLeftRadiusProperty,
24+
fontInternalProperty,
25+
hintProperty,
26+
paddingBottomProperty,
27+
paddingLeftProperty,
28+
paddingRightProperty,
29+
paddingTopProperty,
30+
placeholderColorProperty,
31+
profile
32+
} from '@nativescript/core';
1733
import { secureProperty } from '@nativescript/core/ui/text-field';
1834
import { TextFieldBase } from './textfield.common';
1935

@@ -41,11 +57,13 @@ export class TextField extends TextFieldBase {
4157
constructor() {
4258
super();
4359
}
60+
// @ts-ignore
4461
get nativeTextViewProtected() {
4562
return this.editText;
4663
}
4764

4865
drawingBackground = false;
66+
// @ts-ignore
4967
get nativeViewProtected() {
5068
return this.layoutView;
5169
}
@@ -288,5 +306,17 @@ export class TextField extends TextFieldBase {
288306
this.nativeViewProtected.setTypeface(value instanceof Font ? value.getAndroidTypeface() : value);
289307
}
290308
}
309+
[paddingTopProperty.setNative](value: Length) {
310+
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
311+
}
312+
[paddingRightProperty.setNative](value: Length) {
313+
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
314+
}
315+
[paddingBottomProperty.setNative](value: Length) {
316+
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
317+
}
318+
[paddingLeftProperty.setNative](value: Length) {
319+
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
320+
}
291321
}
292322
//

src/textfield/textfield.ios.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class TextInputControllerImpl extends MDCTextInputControllerBase {
6464

6565
return delegate;
6666
}
67-
textInsets(defaultValue) {
68-
let result = super.textInsets(defaultValue);
67+
textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint) {
68+
let result = super.textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint);
6969
const owner = this._owner ? this._owner.get() : null;
7070
if (owner) {
7171
result = owner._getTextInsetsForBounds(result);
@@ -83,8 +83,8 @@ class TextInputControllerOutlinedImpl extends MDCTextInputControllerOutlined {
8383

8484
return delegate;
8585
}
86-
textInsets(defaultValue) {
87-
let result = super.textInsets(defaultValue);
86+
textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint) {
87+
let result = super.textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint);
8888
const owner = this._owner ? this._owner.get() : null;
8989
if (owner) {
9090
result = owner._getTextInsetsForBounds(result);
@@ -102,8 +102,8 @@ class TextInputControllerFilledImpl extends MDCTextInputControllerFilled {
102102

103103
return delegate;
104104
}
105-
textInsets(defaultValue) {
106-
let result = super.textInsets(defaultValue);
105+
textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint) {
106+
let result = super.textInsetsWithSizeThatFitsWidthHint(defaultValue, widthHint);
107107
const owner = this._owner ? this._owner.get() : null;
108108
if (owner) {
109109
result = owner._getTextInsetsForBounds(result);

0 commit comments

Comments
 (0)