Skip to content

Commit

Permalink
Merge pull request #9476 from maggieaxway/TIMOB-18500
Browse files Browse the repository at this point in the history
[TIMOB-18500] Android: event.cancel not set properly for optionsDialog
  • Loading branch information
eric34 committed Nov 13, 2017
2 parents 43395bb + 9add501 commit 1cc2aa1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,27 @@ public void handleEvent(int id)
int cancelIndex = (proxy.hasProperty(TiC.PROPERTY_CANCEL)) ?
TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL)) : -1;
KrollDict data = new KrollDict();
if ((id & BUTTON_MASK) != 0) {
data.put(TiC.PROPERTY_BUTTON, true);
id &= ~BUTTON_MASK;
} else {
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);

// TIMOB-18500 Android: event.cancel not set properly for optionsDialog
boolean isCancel = id == cancelIndex;
if (!isCancel) {
if ((id & BUTTON_MASK) != 0) {
data.put(TiC.PROPERTY_BUTTON, true);
id &= ~BUTTON_MASK;
} else {
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);
}
}
}
data.put(TiC.EVENT_PROPERTY_INDEX, id);
data.put(TiC.PROPERTY_CANCEL, id == cancelIndex);
fireEvent(TiC.EVENT_CLICK, data);
data.put(TiC.PROPERTY_CANCEL, isCancel);
if (isCancel) {
fireEvent(TiC.EVENT_CANCEL, data);
} else {
fireEvent(TiC.EVENT_CLICK, data);
}
}
}
51 changes: 34 additions & 17 deletions apidoc/Titanium/UI/OptionDialog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ description: |
The `destructive` property may be set for an item, to give a visual cue that selecting it
results in an irreversible action.
On iOS 4, option dialogs are automatically cancelled when the application is paused/suspended.
Since iOS 4, option dialogs are automatically cancelled when the application is paused/suspended.
##### iPhone
Expand Down Expand Up @@ -188,15 +188,13 @@ properties:
type: Number
default: undefined (Android), -1 (iOS)


- name: destructive
summary: Index to define the destructive option, indicated by a visual cue when rendered.
type: Number
default: -1
platforms: [iphone, ipad]
availability: creation


- name: options
summary: List of option names to display in the dialog.
description: |
Expand Down Expand Up @@ -242,17 +240,14 @@ properties:
summary: Key identifying a string in the locale file to use for the title text.
type: String


examples:
- title: Dialog with 3 Options
example: |
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
title: 'Click window to test',
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false
backgroundColor: 'white'
});
var opts = {
Expand All @@ -271,30 +266,52 @@ examples:
- title: Dialog with 2 Options and 1 Button on Android and 3 Options on iOS
example: |
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
title: 'Click window to test',
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false
var win = Ti.UI.createWindow({
title: 'Click window to test OptionDialog',
backgroundColor: 'white'
});
var opts = {
title: 'Delete File?'
};
var isAndroid = Ti.Platform.osname == 'android';
var isAndroid = Ti.Platform.osname === 'android';
if(isAndroid){
if (isAndroid) {
opts.options = ['Confirm', 'Cancel'];
opts.buttonNames = ['Help'];
} else {
opts.options = ['Confirm', 'Help', 'Cancel'];
}
win.addEventListener('click', function(e){
var dialog = Ti.UI.createOptionDialog(opts).show();
var dialog;
win.addEventListener('click', function() {
dialog = Ti.UI.createOptionDialog(opts);
dialog.addEventListener('click', onSelectDialog);
dialog.addEventListener('cancel', function(e) {
alert('Dialog canceled! e.cancel = ' + e.cancel + ', e.index = ' + e.index);
})
dialog.show();
});
function onSelectDialog(e) {
if (isAndroid) {
if (e.button === false && e.index === 0) {
alert('Confirm option selected! e.index = ' + e.index);
}
if (e.button === false && eventeindex === 1) {
alert('Cancel option selected! e.index = ' + e.index);
}
if (e.button === true && e.index === 0) {
alert('Help Button clicked! e.index = ' + e.index);
}
}
}
win.open();
- title: Alloy XML Markup
Expand Down

0 comments on commit 1cc2aa1

Please sign in to comment.