Fixed: Unable to set padding for TextView

Resolves #2024
This commit is contained in:
Rossen Hristov
2016-04-25 17:05:18 +03:00
parent 198343f0ff
commit 2672752be8
5 changed files with 33 additions and 1 deletions

View File

@ -278,6 +278,8 @@
<DependentUpon>action-view.xml</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="apps\ui-tests-app\pages\touch-event.ts" />
<Content Include="apps\ui-tests-app\padding\padding.css" />
<Content Include="apps\ui-tests-app\padding\padding.xml" />
<Content Include="apps\ui-tests-app\pages\touch-event.xml">
<SubType>Designer</SubType>
</Content>
@ -2220,7 +2222,7 @@
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" />
<UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -80,6 +80,8 @@ examples.set("pwrap", "layouts-percent/wrap");
examples.set("modalview", "modal-view/modal-view");
examples.set("nordic", "nordic/nordic");
examples.set("padding", "padding/padding");
examples.set("gestures", "pages/gestures");
examples.set("touch", "pages/touch-event");
examples.set("handlers", "pages/handlers");

View File

@ -0,0 +1,3 @@
TextField, TextView, Button, Label {
padding: 50;
}

View File

@ -0,0 +1,8 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" >
<StackLayout>
<Label id="label" text="Label" backgroundColor="red"/>
<TextField id="textField" text="TextField" backgroundColor="green"/>
<TextView id="textView" text="TextView" backgroundColor="blue"/>
<Button id="button" text="Button" backgroundColor="yellow"/>
</StackLayout>
</Page>

View File

@ -165,11 +165,28 @@ export class TextViewStyler implements style.Styler {
}
}
// Padding
private static setPaddingProperty(view: View, newValue: any) {
var top = newValue.top + view.borderWidth;
var left = newValue.left + view.borderWidth;
var bottom = newValue.bottom + view.borderWidth;
var right = newValue.right + view.borderWidth;
(<UITextView>view._nativeView).textContainerInset = UIEdgeInsetsFromString(`{${top},${left},${bottom},${right}}`);
}
private static resetPaddingProperty(view: View, nativeValue: any) {
(<UITextView>view._nativeView).textContainerInset = UIEdgeInsetsFromString("{0,0,0,0}");
}
public static registerHandlers() {
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
TextViewStyler.setColorProperty,
TextViewStyler.resetColorProperty,
TextViewStyler.getNativeColorValue), "TextView");
style.registerHandler(style.nativePaddingsProperty, new style.StylePropertyChangedHandler(
TextViewStyler.setPaddingProperty,
TextViewStyler.resetPaddingProperty), "TextView");
}
}