FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(): local icon handling in actionbar and tabview (#7009) · NativeScript/NativeScript@cd66300 · GitHub

Commit cd66300

Browse files
authored andcommitted
feat(): local icon handling in actionbar and tabview (#7009)
1 parent 5a5435a commit cd66300

14 files changed

Lines changed: 160 additions & 5 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as frame from "tns-core-modules/ui/frame";
2+
import { EventData } from "tns-core-modules/ui/frame";
3+
import { Button } from "tns-core-modules/ui/button";
4+
import { ActionBar } from "tns-core-modules/ui/action-bar";
5+
6+
const iconModes = ["automatic", "alwaysOriginal", "alwaysTemplate", undefined];
7+
8+
export function navigate(args) {
9+
frame.topmost().navigate("ui-tests-app/action-bar/clean");
10+
}
11+
12+
export function onChangeRenderingMode(args: EventData) {
13+
const button = <Button>args.object;
14+
const actionBar = <ActionBar>button.page.actionBar
15+
actionBar.iosIconRenderingMode = <"automatic" | "alwaysOriginal" | "alwaysTemplate">iconModes[(iconModes.indexOf(actionBar.iosIconRenderingMode) + 1) % iconModes.length];
16+
button.text = "" + actionBar.iosIconRenderingMode;
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page>
2+
<Page.actionBar>
3+
<ActionBar>
4+
<ActionBar.actionItems>
5+
<ActionItem icon="res://icon" tap="navigate"/>
6+
<ActionItem icon="res://add_to_fav" tap="navigate"/>
7+
</ActionBar.actionItems>
8+
</ActionBar>
9+
</Page.actionBar>
10+
<StackLayout>
11+
<Button text="go to cleared page" tap="navigate"/>
12+
<Button text="undefined" tap="onChangeRenderingMode"/>
13+
</StackLayout>
14+
</Page>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as frame from "tns-core-modules/ui/frame";
2+
import { EventData } from "tns-core-modules/ui/frame";
3+
import { Button } from "tns-core-modules/ui/button";
4+
import { ActionBar } from "tns-core-modules/ui/action-bar";
5+
6+
const iconModes = ["automatic", "alwaysOriginal", "alwaysTemplate", undefined];
7+
8+
export function navigate(args) {
9+
frame.topmost().navigate("ui-tests-app/action-bar/clean");
10+
}
11+
12+
export function onChangeRenderingMode(args: EventData) {
13+
const button = <Button>args.object;
14+
const actionBar = <ActionBar>button.page.actionBar
15+
actionBar.iosIconRenderingMode = <"automatic" | "alwaysOriginal" | "alwaysTemplate">iconModes[(iconModes.indexOf(actionBar.iosIconRenderingMode) + 1) % iconModes.length];
16+
button.text = "" + actionBar.iosIconRenderingMode;
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page>
2+
<Page.actionBar>
3+
<ActionBar>
4+
<ActionBar.actionItems>
5+
<ActionItem icon="~/ui-tests-app/resources/images/icon.png" tap="navigate"/>
6+
<ActionItem icon="~/ui-tests-app/resources/images/add_to_fav@3x.png" tap="navigate"/>
7+
</ActionBar.actionItems>
8+
</ActionBar>
9+
</Page.actionBar>
10+
<StackLayout>
11+
<Button text="go to cleared page" tap="navigate"/>
12+
<Button text="undefined" tap="onChangeRenderingMode"/>
13+
</StackLayout>
14+
</Page>

‎apps/app/ui-tests-app/action-bar/main-page.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export function loadExamples() {
1515
examples.set("actBG", "action-bar/background");
1616
examples.set("actStyle", "action-bar/all");
1717
examples.set("actIcons", "action-bar/system-icons");
18+
examples.set("actLocalIcons", "action-bar/local-icons");
19+
examples.set("actResIcons", "action-bar/icons");
1820
examples.set("actView", "action-bar/action-view");
1921
examples.set("actionItemPosition", "action-bar/action-item-position");
2022
examples.set("actBGCss", "action-bar/background-css");

‎apps/app/ui-tests-app/tab-view/main-page.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function loadExamples() {
1919
examples.set("tabmore", "tab-view/tab-view-more");
2020
examples.set("tabViewCss", "tab-view/tab-view-css");
2121
examples.set("tab-view-icons", "tab-view/tab-view-icon");
22+
examples.set("tab-view-icons-local", "tab-view/tab-view-icon-local");
2223
examples.set("tab-view-icon-change", "tab-view/tab-view-icon-change");
2324
examples.set("text-transform", "tab-view/text-transform");
2425
examples.set("tab-view-bottom-position", "tab-view/tab-view-bottom-position");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { EventData } from "tns-core-modules/data/observable";
2+
import { Button } from "tns-core-modules/ui/button";
3+
import { TabView } from "tns-core-modules/ui/tab-view";
4+
5+
let iconModes = ["automatic", "alwaysOriginal", "alwaysTemplate", undefined];
6+
7+
export const onNavigate = updateButtons;
8+
9+
export function onChangeRenderingMode(args: EventData) {
10+
let tabView = (<Button>args.object).page.getViewById<TabView>("tab-view");
11+
tabView.iosIconRenderingMode = <"automatic" | "alwaysOriginal" | "alwaysTemplate">iconModes[(iconModes.indexOf(tabView.iosIconRenderingMode) + 1) % iconModes.length];
12+
updateButtons(args);
13+
}
14+
15+
function updateButtons(args) {
16+
let button = (<Button>args.object);
17+
let tabView = button.page.getViewById<TabView>("tab-view");
18+
for (let i = 0, length = tabView.items.length; i < length; i++) {
19+
(<Button>tabView.items[i].view).text = "" + tabView.iosIconRenderingMode;
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigate">
2+
<TabView id="tab-view" tabTextColor="green" selectedTabTextColor="red" tabBackgroundColor="yellow">
3+
<TabView.items>
4+
<TabViewItem iconSource="~/ui-tests-app/resources/images/icon.png">
5+
<TabViewItem.view>
6+
<Button text="undefined" tap="onChangeRenderingMode"/>
7+
</TabViewItem.view>
8+
</TabViewItem>
9+
<TabViewItem iconSource="~/ui-tests-app/resources/images/add_to_fav@3x.png">
10+
<TabViewItem.view>
11+
<Button text="undefined" tap="onChangeRenderingMode"/>
12+
</TabViewItem.view>
13+
</TabViewItem>
14+
<TabViewItem iconSource="~/ui-tests-app/resources/images/icon.png" title="NativeScript">
15+
<TabViewItem.view>
16+
<Button text="undefined" tap="onChangeRenderingMode"/>
17+
</TabViewItem.view>
18+
</TabViewItem>
19+
<TabViewItem iconSource="~/ui-tests-app/resources/images/add_to_fav@3x.png" title="Favorites">
20+
<TabViewItem.view>
21+
<Button text="undefined" tap="onChangeRenderingMode"/>
22+
</TabViewItem.view>
23+
</TabViewItem>
24+
</TabView.items>
25+
</TabView>
26+
</Page>

‎tns-core-modules/ui/action-bar/action-bar-common.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class ActionBarBase extends View implements ActionBarDefinition {
2929

3030
public title: string;
3131
public flat: boolean;
32+
public iosIconRenderingMode: "automatic" | "alwaysOriginal" | "alwaysTemplate";
3233

3334
get navigationButton(): NavigationButton {
3435
return this._navigationButton;
@@ -88,6 +89,10 @@ export class ActionBarBase extends View implements ActionBarDefinition {
8889
this.update();
8990
}
9091
}
92+
93+
get ios(): any {
94+
return undefined;
95+
}
9196

9297
get android(): AndroidActionBarSettings {
9398
return undefined;
@@ -346,6 +351,9 @@ export function traceMissingIcon(icon: string) {
346351
traceMessageType.error);
347352
}
348353

354+
export const iosIconRenderingModeProperty = new Property<ActionBarBase, "automatic" | "alwaysOriginal" | "alwaysTemplate">({ name: "iosIconRenderingMode", defaultValue: "alwaysOriginal" });
355+
iosIconRenderingModeProperty.register(ActionBarBase);
356+
349357
export const textProperty = new Property<ActionItemBase, string>({ name: "text", defaultValue: "", valueChanged: onItemChanged });
350358
textProperty.register(ActionItemBase);
351359

‎tns-core-modules/ui/action-bar/action-bar.android.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
437437

438438
let is = fromFileOrResource(icon);
439439
if (is) {
440-
drawable = new android.graphics.drawable.BitmapDrawable(is.android);
440+
drawable = new android.graphics.drawable.BitmapDrawable(appResources, is.android);
441441
}
442442

443443
result = drawable;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL