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

[TIMOB-24841] iOS: Add Ti.UI.AlertDialog.tintColor #9150

Merged
merged 7 commits into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion apidoc/Titanium/UI/AlertDialog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ excludes:
backgroundImage,backgroundLeftCap,backgroundRepeat,backgroundSelectedColor,
backgroundSelectedImage,backgroundTopCap,borderColor,borderRadius,borderWidth,bottom,center,
children,clipMode,focusable,height,horizontalWrap,keepScreenOn,layout,left,opacity,overrideCurrentAnimation,
pullBackgroundColor,rect,right,size,softKeyboardOnFocus,tintColor,top,touchEnabled,transform,
pullBackgroundColor,rect,right,size,softKeyboardOnFocus,top,touchEnabled,transform,
viewShadowColor,viewShadowOffset,viewShadowRadius,visible,width,zIndex]

events:
Expand Down Expand Up @@ -129,6 +129,16 @@ events:
<Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT>.
type: String
platforms: [iphone, ipad]

- name: tintColor
summary: The tint-color of the dialog.
description: |
This property is a direct correspondant of the `tintColor` property of
UIView on iOS. For a dialog, it will tint the color of it's buttons.
type: [String]
since: "6.2.0"
osver: {ios: {min: "8.0"}}
platforms: [iphone,ipad]

methods:
- name: show
Expand Down
10 changes: 8 additions & 2 deletions iphone/Classes/TiUIAlertDialogProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,22 @@ -(void)show:(id)args
}

style = [TiUtils intValue:[self valueForKey:@"style"] def:UIAlertViewStyleDefault];

RELEASE_TO_NIL(alertController);
[[[TiApp app] controller] incrementActiveAlertControllerCount];

alertController = [[UIAlertController alertControllerWithTitle:[TiUtils stringValue:[self valueForKey:@"title"]]
message:[TiUtils stringValue:[self valueForKey:@"message"]]
preferredStyle:UIAlertControllerStyleAlert] retain];
int curIndex = 0;

id tintColor = [self valueForKey:@"tintColor"];

if (tintColor != nil) {
[[alertController view] setTintColor:[[TiUtils colorValue:tintColor] color]];
}

//Configure the Buttons
// Configure the Buttons
for (id btn in buttonNames) {
NSString* btnName = [TiUtils stringValue:btn];
if (!IS_NULL_OR_NIL(btnName)) {
Expand Down
107 changes: 107 additions & 0 deletions tests/Resources/ti.ui.alertdialog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-2016 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
var should = require('./utilities/assertions'),
utilities = require('./utilities/utilities');

describe('Titanium.UI.AlertDialog', function () {
it('apiName', function () {
var dialog = Ti.UI.createAlertDialog();
should(dialog).have.readOnlyProperty('apiName').which.is.a.String;
should(dialog.apiName).be.eql('Ti.UI.AlertDialog');
});

it('title', function () {
var bar = Ti.UI.createAlertDialog({
title: 'this is some text'
});
should(bar.title).be.a.String;
should(bar.getTitle).be.a.Function;
should(bar.title).eql('this is some text');
should(bar.getTitle()).eql('this is some text');
bar.title = 'other text';
should(bar.title).eql('other text');
should(bar.getTitle()).eql('other text');
});

// FIXME titleid doesn't seem to set title on iOS?
(utilities.isIOS() ? it.skip : it)('titleid', function () {
var bar = Ti.UI.createAlertDialog({
titleid: 'this_is_my_key'
});
should(bar.titleid).be.a.String;
should(bar.getTitleid).be.a.Function;
should(bar.titleid).eql('this_is_my_key');
should(bar.getTitleid()).eql('this_is_my_key');
should(bar.title).eql('this is my value'); // fails on iOS, gives undefined
bar.titleid = 'other text';
should(bar.titleid).eql('other text');
should(bar.getTitleid()).eql('other text');
should(bar.title).eql('this is my value'); // retains old value if key not found: https://jira.appcelerator.org/browse/TIMOB-23498
});

it('message', function () {
var bar = Ti.UI.createAlertDialog({
message: 'this is some text'
});
should(bar.message).be.a.String;
should(bar.getMessage).be.a.Function;
should(bar.message).eql('this is some text');
should(bar.getMessage()).eql('this is some text');
bar.message = 'other text';
should(bar.message).eql('other text');
should(bar.getMessage()).eql('other text');
});

// FIXME Get working on iOS - defaults to undefined, should be ['OK']
// FIXME Get working on Android - defaults to undefined, should be ['OK']
((utilities.isIOS() || utilities.isAndroid()) ? it.skip : it)('buttonNames', function () {
var bar = Ti.UI.createAlertDialog({});
should(bar.buttonNames).be.an.Array; // undefined on iOS and Android
should(bar.getButtonNames).be.a.Function;
should(bar.buttonNames).be.empty;
should(bar.getButtonNames()).be.empty;
bar.buttonNames = ['this','other'];
should(bar.buttonNames.length).eql(2);
should(bar.getButtonNames().length).eql(2);
});

// FIXME Get working on iOS - defaults to undefined, should be -1
// FIXME Get working on Android - defaults to undefined, should be -1
((utilities.isIOS() || utilities.isAndroid()) ? it.skip : it)('cancel', function (finish) {
var bar = Ti.UI.createAlertDialog({});
should(bar.cancel).be.a.Number; // undefined on iOS and Android
should(bar.getCancel).be.a.Function;
bar.cancel = 1;
should(bar.cancel).eql(1);
should(bar.getCancel()).eql(1);
});

// Skip on other platforms, since it's an iOS-only property
(utilities.isIOS() ? it : it.skip)('tintColor', function () {
var bar = Ti.UI.createAlertDialog({
tintColor: 'red'
});

// Check getter
should(bar.tintColor).be.a.String;
should(bar.getTintColor).be.a.Function;
should(bar.tintColor).eql('red');
should(bar.getTintColor()).eql('red');

// Set new value
bar.tintColor = '#f00';

// Check getter again
should(bar.tintColor).eql('#f00');
should(bar.getTintColor()).eql('#f00');

// Check setter
should(bar.setTintColor).be.a.Function;
bar.setTintColor('#0f0');
should(bar.tintColor).eql('#0f0');
});
});