Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16900] Android: Add selected/unselected Tab events for parity with iOS Focus and Blur events

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionDone
Resolution Date2019-01-10T21:21:23.000+0000
Affected Version/sRelease 3.2.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, blur, focus, parity, tab
ReporterMark Mokryn
AssigneeYordan Banev
Created2014-04-20T20:42:57.000+0000
Updated2019-01-10T21:21:27.000+0000

Description

On iOS, the Tab focus and blur events fire for the relevant tabs when a tab is selected. On Android, these events also fire when the window gains or loses focus, such as when the Home button is clicked or when the screen is unlocked. The iOS behavior is the correct one, and should be matched. This is important, since we need a reliable indicator for when a tab is selected and unselected. We currently have no such indicator in Android, thus this is critical. UPDATE: see PR in comment below. The PR added the selected and unselected tab events for Android, while not modifying focus and blur behavior to maintain app compatibility. In iOS, tab focus and blur were simply renamed to selected and unselected. These events function as expected, and have the benefit of being more appropriately named.

Comments

  1. Mark Mokryn 2014-04-21

    Pull request: https://github.com/appcelerator/titanium_mobile/pull/5636 See a detailed explanation in the PR comment. To test the PR: index.xml:
       <Alloy>
       	<TabGroup onBlur="tabGroupBlurred" onFocus="tabGroupFocused">
       		<Tab title="Tab 1" icon="KS_nav_ui.png" onBlur="tabBlurred" onFocus="tabFocused" id="tab1" onSelected="tabSelected" onUnselected="tabUnselected">
       			<Window title="Tab 1" onBlur="windowBlurred" onFocus="windowFocused">
       				<ScrollView>
       					<Label top="10dp">Switch tabs, click home button, lock screen, and watch the console events. Also make sure that keyboard dismissed when new tab selected.</Label>
       					<TextField top="120dp" width="200dp" height="Ti.UI.SIZE" backgroundColor="blue"/>
       					<Button top="180dp" title="Open Window" onClick="openWin"/>
       				</ScrollView>
       			</Window>
       		</Tab>
       		<Tab title="Tab 2" icon="KS_nav_views.png">
       			<Window title="Tab 2">
       				<Label>I am Window 2</Label>
       			</Window>
       		</Tab>
       	</TabGroup>
       </Alloy>
       
    index.js
       function tabSelected(){
       	Ti.API.info('tab selected');
       }
       
       function tabUnselected(){
       	Ti.API.info('tab unselected');
       }
       
       function tabBlurred(){
       	Ti.API.info('tab blurred');
       }
       
       function tabFocused(){
       	Ti.API.info('tab focused');
       }
       
       function windowBlurred(){
       	Ti.API.info('window blurred');
       }
       
       function windowFocused(){
       	Ti.API.info('window focused');
       }
       
       function tabGroupBlurred(){
       	Ti.API.info('TabGroup blurred');
       }
       
       function tabGroupFocused(){
       	Ti.API.info('TabGroup focused');
       }
       
       function openWin() {
       	var win = Ti.UI.createWindow({backgroundColor: 'blue'});
       	$.tab1.open(win);
       }
       $.index.open();
       
  2. Mark Mokryn 2014-04-24

    Any feedback from Appcelerator on this? Thanks.
  3. Ritu Agrawal 2014-04-30

    Moving this parity fix PR to engineering for further evaluation and prioritization.
  4. Mark Mokryn 2014-04-30

    I just submitted a new PR for swipe tabs: https://github.com/appcelerator/titanium_mobile/pull/5651 which includes this functionality for Android, so you may close this ticket if that PR is accepted. I would just suggest that in iOS Tab.focus/blur be renamed to selected/unselected to match Android.
  5. Yordan Banev 2018-10-11

    The described behavior works as expected and is retained after the refactoring. The ticket can be closed once the new TabGroup gets merged.
  6. Samir Mohammed 2018-12-12

  7. Joshua Quick 2019-01-10

    The "selected" and "unselected" events were added back in Titanium 3.6.0. We've verified that Titanium 8.0.0 maintains this behavior.

JSON Source