feat(ios): add icon rendering mode for bottom navigation (#7738)

This commit is contained in:
Martin Yankov
2019-08-28 17:10:55 +03:00
committed by GitHub
parent f436b6f100
commit ff6d89fc13
6 changed files with 21 additions and 43 deletions

View File

@ -11,7 +11,7 @@
</StackLayout> </StackLayout>
<GridLayout row="1"> <GridLayout row="1">
<BottomNavigation automationText="tabNavigation" loaded="bottomNavigaitonLoaded" items="{{ tabContentItems }}"> <BottomNavigation automationText="tabNavigation" loaded="bottomNavigaitonLoaded" items="{{ tabContentItems }}">
<TabStrip items="{{ tabStripItems }}"> <TabStrip items="{{ tabStripItems }}" iosIconRenderingMode="alwaysOriginal">
</TabStrip> </TabStrip>
</BottomNavigation> </BottomNavigation>
</GridLayout> </GridLayout>

View File

@ -3,23 +3,8 @@
<ActionBar title="BottomNavigation" icon="" class="action-bar"> <ActionBar title="BottomNavigation" icon="" class="action-bar">
</ActionBar> </ActionBar>
<!-- w/o TabStrip -->
<!-- <BottomNavigation>
<TabContentItem>
<GridLayout>
<Label text="First View"/>
</GridLayout>
</TabContentItem>
<TabContentItem>
<GridLayout>
<Label text="Second View"/>
</GridLayout>
</TabContentItem>
</BottomNavigation> -->
<!-- w/ TabStrip -->
<BottomNavigation id="bottomNav" automationText="tabNavigation" > <BottomNavigation id="bottomNav" automationText="tabNavigation" >
<TabStrip> <TabStrip iosIconRenderingMode="alwaysOriginal">
<TabStripItem title="First Tab 11" iconSource="res://icon"></TabStripItem> <TabStripItem title="First Tab 11" iconSource="res://icon"></TabStripItem>
<TabStripItem> <TabStripItem>
<!-- <Image src="res://icon" /> --> <!-- <Image src="res://icon" /> -->
@ -71,26 +56,4 @@
</StackLayout> </StackLayout>
</TabContentItem> </TabContentItem>
</BottomNavigation> </BottomNavigation>
<!-- =============================================================================================== -->
<!-- Bottom Bar with TabStrip -->
<!-- <BottomNavigationBar>
<TabStrip>
<TabStripItem title="First Tab" iconSource="res://icon"></TabStripItem>
<TabStripItem>
<Image src="res://icon" />
<Label text="Second Tab" />
</TabStripItem>
</TabStrip>
</BottomNavigationBar> -->
<!-- Bottom Bar w/o TabStrip -->
<!-- <BottomNavigationBar>
<TabStripItem title="First Tab" iconSource="res://icon"></TabStripItem>
<TabStripItem>
<Image src="res://icon" />
<Label text="Second Tab" />
</TabStripItem>
</BottomNavigationBar> -->
</Page> </Page>

View File

@ -2,7 +2,7 @@
<ActionBar title="BottomNavigation" icon="" class="action-bar"> <ActionBar title="BottomNavigation" icon="" class="action-bar">
</ActionBar> </ActionBar>
<BottomNavigation id="bottomNavigation" automationText="tabNavigation" class="font-awesome"> <BottomNavigation id="bottomNavigation" automationText="tabNavigation" class="font-awesome">
<TabStrip> <TabStrip iosIconRenderingMode="alwaysOriginal">
<TabStripItem title="motorcycle-res" iconSource="res://baseline_motorcycle_black_24"></TabStripItem> <TabStripItem title="motorcycle-res" iconSource="res://baseline_motorcycle_black_24"></TabStripItem>
<TabStripItem iconSource="font://&#xf206;" title="icon"> <TabStripItem iconSource="font://&#xf206;" title="icon">
</TabStripItem> </TabStripItem>

View File

@ -3,7 +3,7 @@
</ActionBar> </ActionBar>
<BottomNavigation id="tab-view" selectedIndexChanged="onSelectedIndexChanged" automationText="tabNavigation" > <BottomNavigation id="tab-view" selectedIndexChanged="onSelectedIndexChanged" automationText="tabNavigation" >
<TabStrip> <TabStrip iosIconRenderingMode="alwaysOriginal">
<TabStripItem iconSource="res://icon" title="selected"></TabStripItem> <TabStripItem iconSource="res://icon" title="selected"></TabStripItem>
<TabStripItem iconSource="res://testlogo" title="unselected"></TabStripItem> <TabStripItem iconSource="res://testlogo" title="unselected"></TabStripItem>
</TabStrip> </TabStrip>

View File

@ -531,7 +531,15 @@ export class BottomNavigation extends TabNavigationBase {
} }
private getIconRenderingMode(): UIImageRenderingMode { private getIconRenderingMode(): UIImageRenderingMode {
return UIImageRenderingMode.AlwaysOriginal; switch (this.tabStrip && this.tabStrip.iosIconRenderingMode) {
case "alwaysOriginal":
return UIImageRenderingMode.AlwaysOriginal;
case "alwaysTemplate":
return UIImageRenderingMode.AlwaysTemplate;
case "automatic":
default:
return UIImageRenderingMode.Automatic;
}
} }
private getIcon(tabStripItem: TabStripItem): UIImage { private getIcon(tabStripItem: TabStripItem): UIImage {
@ -547,10 +555,12 @@ export class BottomNavigation extends TabNavigationBase {
const color = target.style.color; const color = target.style.color;
const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(";"); const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(";");
let isFontIcon = false;
let image: UIImage = this._iconsCache[iconTag]; let image: UIImage = this._iconsCache[iconTag];
if (!image) { if (!image) {
let is = new ImageSource; let is = new ImageSource;
if (isFontIconURI(iconSource)) { if (isFontIconURI(iconSource)) {
isFontIcon = true;
const fontIconCode = iconSource.split("//")[1]; const fontIconCode = iconSource.split("//")[1];
is = fromFontIconCode(fontIconCode, font, color); is = fromFontIconCode(fontIconCode, font, color);
} else { } else {
@ -564,7 +574,11 @@ export class BottomNavigation extends TabNavigationBase {
image = this.getFixedSizeIcon(image); image = this.getFixedSizeIcon(image);
} }
const originalRenderedImage = image.imageWithRenderingMode(this.getIconRenderingMode()); let renderingMode: UIImageRenderingMode = UIImageRenderingMode.AlwaysOriginal;
if (!isFontIcon) {
renderingMode = this.getIconRenderingMode();
}
const originalRenderedImage = image.imageWithRenderingMode(renderingMode);
this._iconsCache[iconTag] = originalRenderedImage; this._iconsCache[iconTag] = originalRenderedImage;
image = originalRenderedImage; image = originalRenderedImage;
} else { } else {

View File

@ -885,6 +885,7 @@ export class Tabs extends TabsBase {
} }
private getIconRenderingMode(): UIImageRenderingMode { private getIconRenderingMode(): UIImageRenderingMode {
// MDCTabBar doesn't work with rendering mode AlwaysTemplate
return UIImageRenderingMode.AlwaysOriginal; return UIImageRenderingMode.AlwaysOriginal;
} }