Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): set tintcolor of UIBarButtonItem #12245

Merged
merged 12 commits into from
Nov 20, 2020
1 change: 1 addition & 0 deletions iphone/Classes/TiUINavBarButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ - (id)initWithProxy:(TiUIButtonProxy *)proxy_
self = [super initWithImage:theimage style:[self style:proxy_] target:self action:@selector(clicked:)];
} else {
self = [super initWithTitle:[self title:proxy_] style:[self style:proxy_] target:self action:@selector(clicked:)];
self.tintColor = [proxy_ valueForKey:@"color"] ? [TiUtils colorValue:[proxy_ valueForKey:@"color"]].color : [TiUtils colorValue:[proxy_ valueForKey:@"tintColor"]].color;
}
}
proxy = proxy_; // Don't retain
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions tests/Resources/ti.ui.window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,134 @@ describe('Titanium.UI.Window', function () {
});
});

it.ios('.leftNavButtons and .rightNavButtons', finish => {
const rightButton1 = Ti.UI.createButton({
title: 'Right1',
color: 'green',
});

const rightButton2 = Ti.UI.createButton({
title: 'Right2',
color: 'green',
});

const leftButton = Ti.UI.createButton({
title: 'Left',
color: 'blue'
});

const rootWindow = Ti.UI.createWindow({
backgroundColor: 'white',
leftNavButtons: [ leftButton ],
rightNavButtons: [ rightButton1, rightButton2 ],
});

win = Ti.UI.createNavigationWindow({
window: rootWindow
});

win.open();

rootWindow.addEventListener('focus', function focus() {
rootWindow.removeEventListener('focus', focus);
try {
should(rootWindow.rightNavButtons).be.an.Array();
should(rootWindow.rightNavButtons.length).be.eql(2);
rootWindow.rightNavButtons = [ rightButton1 ];
should(rootWindow.rightNavButtons.length).be.eql(1);

should(rootWindow.leftNavButtons).be.an.Array();
should(rootWindow.leftNavButtons.length).be.eql(1);
} catch (e) {
return finish(e);
}
finish();
});
});

it.ios('.leftNavButton with default color (no color value) and .rightNavButton with tintColor', finish => {
const density = Ti.Platform.displayCaps.logicalDensityFactor;
const rightButton = Ti.UI.createButton({
title: 'Right',
tintColor: 'green',
});

const leftButton = Ti.UI.createButton({
title: 'Left',
});

const rootWindow = Ti.UI.createWindow({
backgroundColor: 'white',
leftNavButton: leftButton,
rightNavButton: rightButton,
});

win = Ti.UI.createNavigationWindow({
height: '400px',
width: '400px',
window: rootWindow
});

win.open();

rootWindow.addEventListener('postlayout', function postlayout() {
rootWindow.removeEventListener('postlayout', postlayout);
setTimeout(function () {
try {
should(rootWindow.leftNavButton).be.an.Object();
should(rootWindow.rightNavButton).be.an.Object();
should(win).matchImage(`snapshots/navButton_left_defaultColor_right_greenColor_${density}x.png`);
} catch (e) {
return finish(e);
}
finish();
}, 10);
});
});

it.ios('.leftNavButton and .rightNavButton with color and tintColor', finish => {
const density = Ti.Platform.displayCaps.logicalDensityFactor;

const rightButton = Ti.UI.createButton({
title: 'Right',
tintColor: 'red',
color: 'green', // should have preference
});

const leftButton = Ti.UI.createButton({
title: 'Left',
tintColor: 'red'
});

const rootWindow = Ti.UI.createWindow({
backgroundColor: 'white',
leftNavButton: leftButton,
rightNavButton: rightButton,
});

win = Ti.UI.createNavigationWindow({
height: '400px',
width: '400px',
window: rootWindow
});

win.open();

rootWindow.addEventListener('postlayout', function postlayout() {
rootWindow.removeEventListener('postlayout', postlayout);
setTimeout(function () {
try {
should(rootWindow.leftNavButton).be.an.Object();
should(rootWindow.rightNavButton).be.an.Object();
should(win).matchImage(`snapshots/navButton_left_redColor_right_greenColor_${density}x.png`);
} catch (e) {
return finish(e);
}
finish();
}, 10);
});
});

// FIXME Move these rect/size tests into Ti.UI.View!
it.windowsBroken('.size is read-only', finish => {
win = Ti.UI.createWindow({
Expand Down