Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26274] Android: Drawer hamburger menu disappears on click

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-08-24T01:19:06.000+0000
Affected Version/sRelease 7.4.0, Release 7.3.0, Release 7.2.0
Fix Version/sRelease 7.5.0
ComponentsAndroid
Labelsn/a
ReporterHans Knöchel
AssigneeGary Mathews
Created2018-08-07T20:02:46.000+0000
Updated2018-08-24T01:19:10.000+0000

Description

While trying to get a reproducible case for memory-issues, I found another issue where when clicking the hamburger menu of a drawer layout will hide it and does not make it come back. Test-Case:
var window = Ti.UI.createWindow({ backgroundColor: 'white', theme: 'Theme.AppCompat.NoTitleBar', exitOnClose: false });

var btn = Ti.UI.createButton({
	title: 'Trigger'
});

btn.addEventListener('click', function() {
	var window2 = Ti.UI.createWindow({  title: 'Test' });
	var left = Ti.UI.createView({ backgroundColor: 'red' });
	var center = Ti.UI.createView({ backgroundColor: 'blue' });

	var button2 = Ti.UI.createButton({ title: 'Close'});
	left.add(button2);

	button2.addEventListener('click', function () {
		drawer.closeLeft();
		window.open();
		window2.close();
	})

	var drawer = Ti.UI.Android.createDrawerLayout({
		centerView: center,
		leftView: left
	});
	window2.add(drawer);
	window2.open();
	window.close();
});

window.add(btn);
window.open();
*Work-Around:* The solution is to set up the hamburger button on the ActionBar yourself like this...
window.addEventListener("open", function(e) {
	var actionBar = window.activity.actionBar;
	if (actionBar) {
		actionBar.displayHomeAsUp = true;
		actionBar.homeButtonEnabled = true;
		actionBar.onHomeIconItemSelected = function(e) {
			// Handle the hamburger button click here...
		};
	}
});
We document this here... https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.ActionBar

Comments

  1. Joshua Quick 2018-08-08

    I think the real issue here is that adding the native DrawerLayout to the window automatically adds the hamburger button to the ActionBar and it's mishandled from there. Perhaps the DrawerLayout should not automatically add the button since we don't know which drawer (left, center, or right) to slide-out out.
  2. Gary Mathews 2018-08-09

    master: https://github.com/appcelerator/titanium_mobile/pull/10243
  3. Josh Longton 2018-08-14

    *Closing ticket.* No longer disappears when clicked and is only shown when specified actionBar.displayHomeAsUp = true; The fix is present in SDK: {noformat} 7.4.0.v20180813131247 {noformat} *ENV* {noformat} Appc NPM: 4.2.13 Appc CLI: 7.0.4 Ti CLI: 5.1.1 Node: 8.9.4 NPM: 6.3.0 {noformat} *Test case* {noformat} var window = Ti.UI.createWindow({ backgroundColor: 'white', theme: 'Theme.AppCompat.NoTitleBar', exitOnClose: false }); var btn = Ti.UI.createButton({ title: 'Trigger' }); btn.addEventListener('click', function() { var window2 = Ti.UI.createWindow({ title: 'Test' }); var left = Ti.UI.createView({ backgroundColor: 'red' }); var center = Ti.UI.createView({ backgroundColor: 'blue' }); var button2 = Ti.UI.createButton({ title: 'Close'}); left.add(button2); button2.addEventListener('click', function () { drawer.closeLeft(); window.open(); window2.close(); }) var drawer = Ti.UI.Android.createDrawerLayout({ centerView: center, leftView: left }); // hamburger menu should only show when this is uncommented /*window2.addEventListener('open', function(){ var activity = window2.getActivity(), actionBar = activity.getActionBar(); if (actionBar) { actionBar.displayHomeAsUp = false; actionBar.onHomeIconItemSelected = function() { drawer.toggleLeft(); }; } });*/ window2.add(drawer); window2.open(); window.close(); }); window.add(Ti.UI.createTableView({ data: [{ title: 'Test' }], footerView: btn })); window.open(); {noformat}

JSON Source