IOS stylers

This commit is contained in:
vakrilov
2015-10-29 15:27:12 +02:00
parent 815a4fc23c
commit 7e85de351e
9 changed files with 95 additions and 11 deletions

View File

@ -192,6 +192,9 @@
<Content Include="apps\ui-tests-app\action-bar\all.xml"> <Content Include="apps\ui-tests-app\action-bar\all.xml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
<Content Include="apps\ui-tests-app\action-bar\clean.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="apps\ui-tests-app\tab-view\background.xml"> <Content Include="apps\ui-tests-app\tab-view\background.xml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
@ -214,6 +217,8 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
<Content Include="apps\ui-tests-app\app.css" /> <Content Include="apps\ui-tests-app\app.css" />
<TypeScriptCompile Include="apps\ui-tests-app\action-bar\all.ts" />
<TypeScriptCompile Include="apps\ui-tests-app\action-bar\color.ts" />
<TypeScriptCompile Include="apps\ui-tests-app\nordic\nordic.ts"> <TypeScriptCompile Include="apps\ui-tests-app\nordic\nordic.ts">
<DependentUpon>nordic.xml</DependentUpon> <DependentUpon>nordic.xml</DependentUpon>
</TypeScriptCompile> </TypeScriptCompile>

View File

@ -0,0 +1,5 @@
import frame = require("ui/frame");
export function navigate(args) {
frame.topmost().navigate("action-bar/clean");
}

View File

@ -8,6 +8,6 @@
</ActionBar> </ActionBar>
</Page.actionBar> </Page.actionBar>
<StackLayout> <StackLayout>
<Button text="do nothing"/> <Button text="go to cleared page" tap="navigate"/>
</StackLayout> </StackLayout>
</Page> </Page>

View File

@ -0,0 +1,13 @@
<Page>
<Page.actionBar>
<ActionBar title="Page Title">
<NavigationButton text="go back"/>
<ActionBar.actionItems>
<ActionItem text="ITEM" />
</ActionBar.actionItems>
</ActionBar>
</Page.actionBar>
<StackLayout>
<Button text="do nothing"/>
</StackLayout>
</Page>

View File

@ -0,0 +1,5 @@
import frame = require("ui/frame");
export function navigate(args) {
frame.topmost().navigate("action-bar/clean");
}

View File

@ -1,6 +1,6 @@
<Page> <Page>
<Page.actionBar> <Page.actionBar>
<ActionBar title="Page Title" style="background-color: green;"> <ActionBar title="Page Title" style="color: green;">
<NavigationButton text="go back"/> <NavigationButton text="go back"/>
<ActionBar.actionItems> <ActionBar.actionItems>
<ActionItem text="ITEM" /> <ActionItem text="ITEM" />
@ -8,6 +8,6 @@
</ActionBar> </ActionBar>
</Page.actionBar> </Page.actionBar>
<StackLayout> <StackLayout>
<Button text="do nothing"/> <Button text="go to cleared page" tap="navigate"/>
</StackLayout> </StackLayout>
</Page> </Page>

View File

@ -203,4 +203,9 @@ declare module "ui/action-bar" {
export class NavigationButton extends ActionItemBase { export class NavigationButton extends ActionItemBase {
} }
//@private
export function _setNavBarColor(navBar: UINavigationBar, color: UIColor);
export function _setNavBarBackgroundColor(navBar: UINavigationBar, color: UIColor);
//@endprivate
} }

View File

@ -80,6 +80,9 @@ export class ActionBar extends common.ActionBar {
// Populate action items // Populate action items
this.populateMenuItems(navigationItem); this.populateMenuItems(navigationItem);
// update colors explicitly - they may have to be cleared form a previous page
this.updateColors(navigationBar);
} }
private populateMenuItems(navigationItem: UINavigationItem) { private populateMenuItems(navigationItem: UINavigationItem) {
@ -129,6 +132,21 @@ export class ActionBar extends common.ActionBar {
return barButtonItem; return barButtonItem;
} }
private updateColors(navBar: UINavigationBar) {
var color = this.color;
if (color) {
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
navBar.tintColor = color.ios;
}
else {
navBar.titleTextAttributes = null;
navBar.tintColor = null;
}
var bgColor = this.backgroundColor;
navBar.barTintColor = bgColor ? bgColor.ios : null;
}
public _onTitlePropertyChanged() { public _onTitlePropertyChanged() {
if (!this.page) { if (!this.page) {
return; return;

View File

@ -16,6 +16,14 @@ interface TextUIView {
textColor: UIColor; textColor: UIColor;
} }
var ignorePropertyHandler = new stylersCommon.StylePropertyChangedHandler(
(view, val) => {
// empty
},
(view, val) => {
// empty
});
export class DefaultStyler implements definition.stylers.Styler { export class DefaultStyler implements definition.stylers.Styler {
//Background methods //Background methods
private static setBackgroundInternalProperty(view: view.View, newValue: any) { private static setBackgroundInternalProperty(view: view.View, newValue: any) {
@ -537,13 +545,13 @@ export class SwitchStyler implements definition.stylers.Styler {
SwitchStyler.resetColorProperty, SwitchStyler.resetColorProperty,
SwitchStyler.getNativeColorValue), "Switch"); SwitchStyler.getNativeColorValue), "Switch");
var bkgHandler = new stylersCommon.StylePropertyChangedHandler( style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
SwitchStyler.setBackgroundColorProperty, SwitchStyler.setBackgroundColorProperty,
SwitchStyler.resetBackgroundColorProperty, SwitchStyler.resetBackgroundColorProperty,
SwitchStyler.getBackgroundColorProperty); SwitchStyler.getBackgroundColorProperty), "Switch");
style.registerHandler(style.backgroundColorProperty, bkgHandler, "Switch"); // Ignore the default backgroundInternalProperty handler
style.registerHandler(style.backgroundInternalProperty, bkgHandler, "Switch"); style.registerHandler(style.backgroundInternalProperty, ignorePropertyHandler, "Switch");
} }
} }
@ -634,16 +642,35 @@ export class ActionBarStyler implements definition.stylers.Styler {
private static setColorProperty(view: view.View, newValue: any) { private static setColorProperty(view: view.View, newValue: any) {
var topFrame = frame.topmost(); var topFrame = frame.topmost();
if (topFrame) { if (topFrame) {
var bar = topFrame.ios.controller.navigationBar; var navBar = topFrame.ios.controller.navigationBar;
(<any>bar).titleTextAttributes = { [NSForegroundColorAttributeName]: newValue }; navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: newValue };
navBar.tintColor = newValue;
} }
} }
private static resetColorProperty(view: view.View, nativeValue: any) { private static resetColorProperty(view: view.View, nativeValue: any) {
var topFrame = frame.topmost(); var topFrame = frame.topmost();
if (topFrame) { if (topFrame) {
var bar = topFrame.ios.controller.navigationBar; var navBar = topFrame.ios.controller.navigationBar;
(<any>bar).titleTextAttributes = null; navBar.titleTextAttributes = null;
navBar.tintColor = null;
}
}
// background-color
private static setBackgroundColorProperty(view: view.View, newValue: any) {
var topFrame = frame.topmost();
if (topFrame) {
var navBar = topFrame.ios.controller.navigationBar;
navBar.barTintColor = newValue;
}
}
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
var topFrame = frame.topmost();
if (topFrame) {
var navBar = topFrame.ios.controller.navigationBar;
navBar.barTintColor = null;
} }
} }
@ -651,6 +678,12 @@ export class ActionBarStyler implements definition.stylers.Styler {
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler( style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
ActionBarStyler.setColorProperty, ActionBarStyler.setColorProperty,
ActionBarStyler.resetColorProperty), "ActionBar"); ActionBarStyler.resetColorProperty), "ActionBar");
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
ActionBarStyler.setBackgroundColorProperty,
ActionBarStyler.resetBackgroundColorProperty), "ActionBar");
style.registerHandler(style.backgroundInternalProperty, ignorePropertyHandler, "ActionBar");
} }
} }