Skip to content

Commit

Permalink
[ALOY-1584] Android: Ti.UI.Toolbar has no click event (#853)
Browse files Browse the repository at this point in the history
* Extract ActionBar properties as constants.

* Fix typo in constant name.

* Add simple test.

* Define CONST.

* Add Jake generated code.

* Move files to the proper location.
  • Loading branch information
ypbnv authored and feons committed Nov 6, 2017
1 parent 23d978b commit ed734eb
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Alloy/commands/compile/parsers/Ti.Android.ActionBar.js
Expand Up @@ -12,7 +12,7 @@ function parse(node, state, args) {
var eventObject = 'e',
code = '',
xmlStyles = {},
actionBarProperties = ['title', 'subtitle', 'backgroundImage', 'displayHomeAsUp', 'homeButtonEnabled', 'icon', 'logo', 'navigationMode', 'onHomeIconItemSelected'];
actionBarProperties = ['title', 'subtitle', CONST.BACKGROUND_IMAGE, CONST.DISPLAY_HOME_AS_UP, CONST.HOME_BUTTON_ENABLED, 'icon', 'logo', CONST.NAVIGATION_MODE, CONST.ON_HOME_ICON_ITEM_SELECTED];

// if this isn't android, generate no code, but show a warning
var config = CU.getCompilerConfig(),
Expand Down
3 changes: 2 additions & 1 deletion Alloy/commands/compile/parsers/Ti.UI.Toolbar.js
@@ -1,6 +1,7 @@
var _ = require('../../../lib/alloy/underscore')._,
tiapp = require('../../../tiapp'),
U = require('../../../utils'),
CONST = require('../../../common/constants'),
CU = require('../compilerUtils');

exports.parse = function(node, state) {
Expand All @@ -16,7 +17,7 @@ exports.parse = function(node, state) {
code = '',
xmlStyles = {};
// Properties inherited from ActionBar when Toolbar is passed to the Activity
var inheritedProperties = ['backgroundImage', 'displayHomeAsUp', 'homeButtonEnabled', 'navigationMode', 'onHomeItemSelected'];
var inheritedProperties = [CONST.BACKGROUND_IMAGE, CONST.DISPLAY_HOME_AS_UP, CONST.HOME_BUTTON_ENABLED, CONST.NAVIGATION_MODE, CONST.ON_HOME_ICON_ITEM_SELECTED];

state = _.extend(state, {
itemContainerDefinition: {
Expand Down
7 changes: 7 additions & 0 deletions Alloy/common/constants.js
Expand Up @@ -68,6 +68,13 @@ exports.MODEL_ELEMENTS = ['Alloy.Collection', 'Alloy.Model'];
exports.MODEL_BINDING_EVENTS = 'fetch change destroy';
exports.COLLECTION_BINDING_EVENTS = 'fetch destroy change add remove reset';

// Constants for properties shared between ActionBar and Toolbar on Android
exports.BACKGROUND_IMAGE = 'backgroundImage';
exports.DISPLAY_HOME_AS_UP = 'displayHomeAsUp';
exports.HOME_BUTTON_ENABLED = 'homeButtonEnabled';
exports.NAVIGATION_MODE = 'navigationMode';
exports.ON_HOME_ICON_ITEM_SELECTED = 'onHomeIconItemSelected';

// Listings for supported platforms and commands
exports.INSTALL_TYPES = ['plugin'];
exports.GENERATE_TARGETS = ['controller', 'jmk', 'model', 'migration', 'view', 'widget', 'style'];
Expand Down
@@ -0,0 +1,62 @@
function __processArg(obj, key) {
var arg = null;
if (obj) {
arg = obj[key] || null;
delete obj[key];
}
return arg;
}

function Controller() {
function __alloyId0() {
$.__views.index.removeEventListener("open", __alloyId0);
if ($.__views.index.activity) {
$.__views.index.activity.setSupportActionBar($.__views.toolBarID);
$.__views.index.activity.actionBar.displayHomeAsUp = true;
$.__views.index.activity.actionBar.homeButtonEnabled = true;
} else {
Ti.API.warn("You attempted to access an Activity on a lightweight Window or other");
Ti.API.warn("UI component which does not have an Android activity. Android Activities");
Ti.API.warn("are valid with only windows in TabGroups or heavyweight Windows.");
}
}
require("/alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
this.__controllerPath = "index";
this.args = arguments[0] || {};
if (arguments[0]) {
__processArg(arguments[0], "__parentSymbol");
__processArg(arguments[0], "$model");
__processArg(arguments[0], "__itemTemplate");
}
var $ = this;
var exports = {};
$.__views.index = Ti.UI.createWindow({
title: "My Test App",
backgroundColor: "gray",
customToolbar: "toolBarID",
theme: "Theme.AppCompat.NoTitleBar",
id: "index"
});
$.__views.index && $.addTopLevelView($.__views.index);
$.__views.toolBarID = Ti.UI.createToolbar({
id: "toolBarID",
title: "MyMenu",
subtitle: "Subtitle",
width: Ti.UI.FILL,
top: 0,
homeButtonEnabled: true,
displayHomeAsUp: true,
onHomeIconItemSelected: "clickAlert",
barColor: "#639851"
});
$.__views.index.add($.__views.toolBarID);
$.__views.index.addEventListener("open", __alloyId0);
exports.destroy = function() {};
_.extend($, $.__views);
$.index.open();
_.extend($, exports);
}

var Alloy = require("/alloy"), Backbone = Alloy.Backbone, _ = Alloy._;

module.exports = Controller;
@@ -0,0 +1,62 @@
function __processArg(obj, key) {
var arg = null;
if (obj) {
arg = obj[key] || null;
delete obj[key];
}
return arg;
}

function Controller() {
function __alloyId0() {
$.__views.index.removeEventListener("open", __alloyId0);
if ($.__views.index.activity) {
$.__views.index.activity.setSupportActionBar($.__views.toolBarID);
$.__views.index.activity.actionBar.displayHomeAsUp = true;
$.__views.index.activity.actionBar.homeButtonEnabled = true;
} else {
Ti.API.warn("You attempted to access an Activity on a lightweight Window or other");
Ti.API.warn("UI component which does not have an Android activity. Android Activities");
Ti.API.warn("are valid with only windows in TabGroups or heavyweight Windows.");
}
}
require("/alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
this.__controllerPath = "index";
this.args = arguments[0] || {};
if (arguments[0]) {
__processArg(arguments[0], "__parentSymbol");
__processArg(arguments[0], "$model");
__processArg(arguments[0], "__itemTemplate");
}
var $ = this;
var exports = {};
$.__views.index = Ti.UI.createWindow({
title: "My Test App",
backgroundColor: "gray",
customToolbar: "toolBarID",
theme: "Theme.AppCompat.NoTitleBar",
id: "index"
});
$.__views.index && $.addTopLevelView($.__views.index);
$.__views.toolBarID = Ti.UI.createToolbar({
id: "toolBarID",
title: "MyMenu",
subtitle: "Subtitle",
width: Ti.UI.FILL,
top: 0,
homeButtonEnabled: true,
displayHomeAsUp: true,
onHomeIconItemSelected: "clickAlert",
barColor: "#639851"
});
$.__views.index.add($.__views.toolBarID);
$.__views.index.addEventListener("open", __alloyId0);
exports.destroy = function() {};
_.extend($, $.__views);
$.index.open();
_.extend($, exports);
}

var Alloy = require("/alloy"), Backbone = Alloy.Backbone, _ = Alloy._;

module.exports = Controller;
@@ -0,0 +1,62 @@
function __processArg(obj, key) {
var arg = null;
if (obj) {
arg = obj[key] || null;
delete obj[key];
}
return arg;
}

function Controller() {
function __alloyId0() {
$.__views.index.removeEventListener("open", __alloyId0);
if ($.__views.index.activity) {
$.__views.index.activity.setSupportActionBar($.__views.toolBarID);
$.__views.index.activity.actionBar.displayHomeAsUp = true;
$.__views.index.activity.actionBar.homeButtonEnabled = true;
} else {
Ti.API.warn("You attempted to access an Activity on a lightweight Window or other");
Ti.API.warn("UI component which does not have an Android activity. Android Activities");
Ti.API.warn("are valid with only windows in TabGroups or heavyweight Windows.");
}
}
require("/alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
this.__controllerPath = "index";
this.args = arguments[0] || {};
if (arguments[0]) {
__processArg(arguments[0], "__parentSymbol");
__processArg(arguments[0], "$model");
__processArg(arguments[0], "__itemTemplate");
}
var $ = this;
var exports = {};
$.__views.index = Ti.UI.createWindow({
title: "My Test App",
backgroundColor: "gray",
customToolbar: "toolBarID",
theme: "Theme.AppCompat.NoTitleBar",
id: "index"
});
$.__views.index && $.addTopLevelView($.__views.index);
$.__views.toolBarID = Ti.UI.createToolbar({
id: "toolBarID",
title: "MyMenu",
subtitle: "Subtitle",
width: Ti.UI.FILL,
top: 0,
homeButtonEnabled: true,
displayHomeAsUp: true,
onHomeIconItemSelected: "clickAlert",
barColor: "#639851"
});
$.__views.index.add($.__views.toolBarID);
$.__views.index.addEventListener("open", __alloyId0);
exports.destroy = function() {};
_.extend($, $.__views);
$.index.open();
_.extend($, exports);
}

var Alloy = require("/alloy"), Backbone = Alloy.Backbone, _ = Alloy._;

module.exports = Controller;
@@ -0,0 +1,62 @@
function __processArg(obj, key) {
var arg = null;
if (obj) {
arg = obj[key] || null;
delete obj[key];
}
return arg;
}

function Controller() {
function __alloyId0() {
$.__views.index.removeEventListener("open", __alloyId0);
if ($.__views.index.activity) {
$.__views.index.activity.setSupportActionBar($.__views.toolBarID);
$.__views.index.activity.actionBar.displayHomeAsUp = true;
$.__views.index.activity.actionBar.homeButtonEnabled = true;
} else {
Ti.API.warn("You attempted to access an Activity on a lightweight Window or other");
Ti.API.warn("UI component which does not have an Android activity. Android Activities");
Ti.API.warn("are valid with only windows in TabGroups or heavyweight Windows.");
}
}
require("/alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
this.__controllerPath = "index";
this.args = arguments[0] || {};
if (arguments[0]) {
__processArg(arguments[0], "__parentSymbol");
__processArg(arguments[0], "$model");
__processArg(arguments[0], "__itemTemplate");
}
var $ = this;
var exports = {};
$.__views.index = Ti.UI.createWindow({
title: "My Test App",
backgroundColor: "gray",
customToolbar: "toolBarID",
theme: "Theme.AppCompat.NoTitleBar",
id: "index"
});
$.__views.index && $.addTopLevelView($.__views.index);
$.__views.toolBarID = Ti.UI.createToolbar({
id: "toolBarID",
title: "MyMenu",
subtitle: "Subtitle",
width: Ti.UI.FILL,
top: 0,
homeButtonEnabled: true,
displayHomeAsUp: true,
onHomeIconItemSelected: "clickAlert",
barColor: "#639851"
});
$.__views.index.add($.__views.toolBarID);
$.__views.index.addEventListener("open", __alloyId0);
exports.destroy = function() {};
_.extend($, $.__views);
$.index.open();
_.extend($, exports);
}

var Alloy = require("/alloy"), Backbone = Alloy.Backbone, _ = Alloy._;

module.exports = Controller;
5 changes: 5 additions & 0 deletions test/apps/testing/ALOY-1584/controllers/index.js
@@ -0,0 +1,5 @@
function clickAlert() {
alert('Alert!');
}

$.index.open();
15 changes: 15 additions & 0 deletions test/apps/testing/ALOY-1584/views/index.xml
@@ -0,0 +1,15 @@
<Alloy>
<Window title="My Test App" backgroundColor="gray" customToolbar="toolBarID" theme="Theme.AppCompat.NoTitleBar">
<Toolbar
id="toolBarID"
title="MyMenu"
subtitle="Subtitle"
width="Ti.UI.FILL"
top="0"
homeButtonEnabled = "true"
displayHomeAsUp = "true"
onHomeIconItemSelected = "clickAlert"
barColor="#639851"
/>
</Window>
</Alloy>

0 comments on commit ed734eb

Please sign in to comment.