Skip to content

Commit 2cc34ee

Browse files
author
vakrilov
committed
IOS stylers
1 parent 9d9e2a9 commit 2cc34ee

9 files changed

Lines changed: 95 additions & 11 deletions

File tree

‎CrossPlatformModules.csproj‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@
192192
<Content Include="apps\ui-tests-app\action-bar\all.xml">
193193
<SubType>Designer</SubType>
194194
</Content>
195+
<Content Include="apps\ui-tests-app\action-bar\clean.xml">
196+
<SubType>Designer</SubType>
197+
</Content>
195198
<Content Include="apps\ui-tests-app\tab-view\background.xml">
196199
<SubType>Designer</SubType>
197200
</Content>
@@ -214,6 +217,8 @@
214217
<SubType>Designer</SubType>
215218
</Content>
216219
<Content Include="apps\ui-tests-app\app.css" />
220+
<TypeScriptCompile Include="apps\ui-tests-app\action-bar\all.ts" />
221+
<TypeScriptCompile Include="apps\ui-tests-app\action-bar\color.ts" />
217222
<TypeScriptCompile Include="apps\ui-tests-app\nordic\nordic.ts">
218223
<DependentUpon>nordic.xml</DependentUpon>
219224
</TypeScriptCompile>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import frame = require("ui/frame");
2+
3+
export function navigate(args) {
4+
frame.topmost().navigate("action-bar/clean");
5+
}

‎apps/ui-tests-app/action-bar/all.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</ActionBar>
99
</Page.actionBar>
1010
<StackLayout>
11-
<Button text="do nothing"/>
11+
<Button text="go to cleared page" tap="navigate"/>
1212
</StackLayout>
1313
</Page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Page>
2+
<Page.actionBar>
3+
<ActionBar title="Page Title">
4+
<NavigationButton text="go back"/>
5+
<ActionBar.actionItems>
6+
<ActionItem text="ITEM" />
7+
</ActionBar.actionItems>
8+
</ActionBar>
9+
</Page.actionBar>
10+
<StackLayout>
11+
<Button text="do nothing"/>
12+
</StackLayout>
13+
</Page>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import frame = require("ui/frame");
2+
3+
export function navigate(args) {
4+
frame.topmost().navigate("action-bar/clean");
5+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Page>
22
<Page.actionBar>
3-
<ActionBar title="Page Title" style="background-color: green;">
3+
<ActionBar title="Page Title" style="color: green;">
44
<NavigationButton text="go back"/>
55
<ActionBar.actionItems>
66
<ActionItem text="ITEM" />
77
</ActionBar.actionItems>
88
</ActionBar>
99
</Page.actionBar>
1010
<StackLayout>
11-
<Button text="do nothing"/>
11+
<Button text="go to cleared page" tap="navigate"/>
1212
</StackLayout>
1313
</Page>

‎ui/action-bar/action-bar.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,9 @@ declare module "ui/action-bar" {
203203
export class NavigationButton extends ActionItemBase {
204204

205205
}
206+
207+
//@private
208+
export function _setNavBarColor(navBar: UINavigationBar, color: UIColor);
209+
export function _setNavBarBackgroundColor(navBar: UINavigationBar, color: UIColor);
210+
//@endprivate
206211
}

‎ui/action-bar/action-bar.ios.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export class ActionBar extends common.ActionBar {
8080

8181
// Populate action items
8282
this.populateMenuItems(navigationItem);
83+
84+
// update colors explicitly - they may have to be cleared form a previous page
85+
this.updateColors(navigationBar);
8386
}
8487

8588
private populateMenuItems(navigationItem: UINavigationItem) {
@@ -129,6 +132,21 @@ export class ActionBar extends common.ActionBar {
129132
return barButtonItem;
130133
}
131134

135+
private updateColors(navBar: UINavigationBar) {
136+
var color = this.color;
137+
if (color) {
138+
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
139+
navBar.tintColor = color.ios;
140+
}
141+
else {
142+
navBar.titleTextAttributes = null;
143+
navBar.tintColor = null;
144+
}
145+
146+
var bgColor = this.backgroundColor;
147+
navBar.barTintColor = bgColor ? bgColor.ios : null;
148+
}
149+
132150
public _onTitlePropertyChanged() {
133151
if (!this.page) {
134152
return;

‎ui/styling/stylers.ios.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ interface TextUIView {
1616
textColor: UIColor;
1717
}
1818

19+
var ignorePropertyHandler = new stylersCommon.StylePropertyChangedHandler(
20+
(view, val) => {
21+
// empty
22+
},
23+
(view, val) => {
24+
// empty
25+
});
26+
1927
export class DefaultStyler implements definition.stylers.Styler {
2028
//Background methods
2129
private static setBackgroundInternalProperty(view: view.View, newValue: any) {
@@ -537,13 +545,13 @@ export class SwitchStyler implements definition.stylers.Styler {
537545
SwitchStyler.resetColorProperty,
538546
SwitchStyler.getNativeColorValue), "Switch");
539547

540-
var bkgHandler = new stylersCommon.StylePropertyChangedHandler(
548+
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
541549
SwitchStyler.setBackgroundColorProperty,
542550
SwitchStyler.resetBackgroundColorProperty,
543-
SwitchStyler.getBackgroundColorProperty);
551+
SwitchStyler.getBackgroundColorProperty), "Switch");
544552

545-
style.registerHandler(style.backgroundColorProperty, bkgHandler, "Switch");
546-
style.registerHandler(style.backgroundInternalProperty, bkgHandler, "Switch");
553+
// Ignore the default backgroundInternalProperty handler
554+
style.registerHandler(style.backgroundInternalProperty, ignorePropertyHandler, "Switch");
547555
}
548556
}
549557

@@ -634,23 +642,48 @@ export class ActionBarStyler implements definition.stylers.Styler {
634642
private static setColorProperty(view: view.View, newValue: any) {
635643
var topFrame = frame.topmost();
636644
if (topFrame) {
637-
var bar = topFrame.ios.controller.navigationBar;
638-
(<any>bar).titleTextAttributes = { [NSForegroundColorAttributeName]: newValue };
645+
var navBar = topFrame.ios.controller.navigationBar;
646+
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: newValue };
647+
navBar.tintColor = newValue;
639648
}
640649
}
641650

642651
private static resetColorProperty(view: view.View, nativeValue: any) {
643652
var topFrame = frame.topmost();
644653
if (topFrame) {
645-
var bar = topFrame.ios.controller.navigationBar;
646-
(<any>bar).titleTextAttributes = null;
654+
var navBar = topFrame.ios.controller.navigationBar;
655+
navBar.titleTextAttributes = null;
656+
navBar.tintColor = null;
657+
}
658+
}
659+
660+
// background-color
661+
private static setBackgroundColorProperty(view: view.View, newValue: any) {
662+
var topFrame = frame.topmost();
663+
if (topFrame) {
664+
var navBar = topFrame.ios.controller.navigationBar;
665+
navBar.barTintColor = newValue;
666+
}
667+
}
668+
669+
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
670+
var topFrame = frame.topmost();
671+
if (topFrame) {
672+
var navBar = topFrame.ios.controller.navigationBar;
673+
navBar.barTintColor = null;
647674
}
648675
}
649676

650677
public static registerHandlers() {
651678
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
652679
ActionBarStyler.setColorProperty,
653680
ActionBarStyler.resetColorProperty), "ActionBar");
681+
682+
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
683+
ActionBarStyler.setBackgroundColorProperty,
684+
ActionBarStyler.resetBackgroundColorProperty), "ActionBar");
685+
686+
style.registerHandler(style.backgroundInternalProperty, ignorePropertyHandler, "ActionBar");
654687
}
655688
}
656689

0 commit comments

Comments
 (0)