Titanium JIRA Archive
Alloy (ALOY)

[ALOY-667] Alloy: having a button (one for each platform) with same ID causes Ti.Contacts.showContacts() weirdness

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-01-21T19:58:40.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.3.0, 2014 Sprint 02
Componentsn/a
Labelsalloy, contacts, qe-closed-3.3.0
ReporterDavid Murray
AssigneeTony Lukasavage
Created2013-05-22T20:00:34.000+0000
Updated2014-06-19T09:21:03.000+0000

Description

*Problem* If you have an alloy view with two buttons with the same ID, specifically for the use case of platform-specific buttons, e.g.:
<Button id="btnFoo" title="Show Contacts" platform="ios" onClick="exports.showContacts" />
<Button id="btnFoo" title="Show Contacts" platform="android" onClick="exports.showContacts" />
And you open this window, then you open the contacts window via Ti.Contacts.showContacts() a couple unusual behaviors occur: 1. clicking "Cancel" triggers the cancel event but the window itself doesn't close 2. clicking a row triggers the row's click event but the window itself doesn't close 3. when the search bar has focus, typing doesn't have text show up in the window. If the button doesn't have an ID on it, this behavior doesn't occur. *Steps to reproduce* 1. Create a new standard Alloy project and drop in the app folder contents from the zip 2. Run on iOS 6 simulator and observe behavior described above 3. Try changing the id of one of the buttons to something else, observe that all the behavior described above is fixed

Attachments

FileDateSize
app.zip2013-05-22T20:00:34.000+00003687266

Comments

  1. Daniel Sefton 2013-05-22

    Tested and confirmed on iOS 6 simulator with Ti SDK 3.1 GA and latest 3.2 CI. I'm not sure whether this is a bug with the SDK, or Alloy, but since ids are Alloy-specific, I'll move it there first.
  2. Tim Poulsen 2014-01-20

    Tested with 3.2.0.GA and Alloy 1.3.0. No issues found. Test procedure 1. Create an alloy app with the following code:
       <Alloy>
           <Window fullscreen="true" backgroundColor="white">
       		<Button id="theOneTrueButton" platform="ios">Click me if you dare</Button>
       		<Button id="theOneTrueButton" platform="android">Click me if you dare</Button>
           </Window>
       </Alloy>
       
    2. Build for iOS simulator and Android emulator 3. No build errors, no runtime errors, only one button present on each platform
  3. Tim Poulsen 2014-01-21

    I didn't test this properly. Reopening.
  4. Tim Poulsen 2014-01-21

    I can confirm that the cancel button is non-functioning. Test procedure: 1. Create a new Alloy project 2. Download & unzip the attached app.zip, copy its app folder over the one in your new alloy project 3. Update modal.xml with the following to replace NavigationGroup with NavigationWindow. 4. Build for the iOS Simulator. 5. Click Show Modal, then click Show Contacts. 6. Clicking Cancel triggers the cancel event but doesn't close the window. Click a name and the details window opens as expected. At the contacts list screen, searching for a contact doesn't find any regardless of the text you enter. 7. To fix the cancel button problem, either remove the button ids or change them to be unique (e.g. btnFooIOS and btnFooAndroid). This doesn't fix the searching though.
       <Alloy>
       	<NavigationWindow id="welcomeNav" platform="ios">
       		<Window title="Modal">
       			<Button id="btnFoo" title="Show Contacts" platform="ios" onClick="exports.showContacts" />
       			<Button id="btnFoo" title="Show Contacts" platform="android" onClick="exports.showContacts" />
       		</Window>
       	</NavigationWindow>
       </Alloy>
       
  5. Tim Poulsen 2014-01-21

    To answer Daniel's question, I don't believe this behavior could be a bug in the SDK because it doesn't support platform-specific components in the way Alloy does. The app below works properly whether you assign an id to the button or not, which is about the best I can do to simulate the situation in traditional code.
       function showContacts(e) {
           Ti.Contacts.showContacts({
               cancel: function (e) {
                   Ti.API.info('Cancel clicked');
               }
           });
       };
       
       var win = Titanium.UI.createWindow({  
           backgroundColor:'#fff'
       });
       var btn = Ti.UI.createButton({
           title: 'Show Modal'
       });
       btn.addEventListener('click', function(e){
           var childwin = Titanium.UI.createWindow({
               title: 'Modal'
           });
           var btn1 = Ti.UI.createButton({
               title: 'Show Contacts',
               id: 'btnFoo'
           });
           btn1.addEventListener('click', showContacts);
           childwin.add(btn1);
           var welcomeNav = Titanium.UI.iOS.createNavigationWindow({
              window: childwin
           });
           welcomeNav.open({
               modal: true,
               animated: true
           });
       });
       
       win.add(btn);
       
       win.open();
       
  6. Tony Lukasavage 2014-01-21

    PR: https://github.com/appcelerator/alloy/pull/303 test app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-667 Functional test is to follow the instructions defined above in the comments. In addition, you can check the attached test app with the following steps:

    run the app

    click the shows contacts button

    ensure that each click of the button shows only one messages in the console log.

    Prior to this fix, each message would be printed twice.
  7. Paras Mishra 2014-06-19

    Verified using Tony's steps , console logs are printed once, Also verified using code on iOS and Android
       <Alloy>
           <Window fullscreen="true" backgroundColor="white">
               <Button id="theOneTrueButton" platform="ios">Click me if you dare</Button>
               <Button id="theOneTrueButton" platform="android">Click me if you dare</Button>
           </Window>
       </Alloy>
       
    Verified fix on: Device : iPhone 5s , iOS version : 7.1.1 SDK: 3.3.0.v20140617161713 CLI version : 3.3.0-rc OS : MAC OSX 10.9.2 Alloy: 1.4.0-rc ACS: 1.0.14 npm:1.3.2 LiveView: 1.0.4 Appcelerator Studio, build: 3.3.0.201406171619 titanium-code-processor: 1.1.1 XCode : 5.1.1

JSON Source