titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

feat(android): allow ability to set drawer gravity

Open garymathews opened this issue 5 years ago • 3 comments

  • Implement ability to specify drawer gravity
    • Ti.UI.Android.DrawerLayout.drawerGravity
TEST CASE
const win = Ti.UI.createWindow(),
	leftView = Ti.UI.createView({
		backgroundColor: "#333",
		layout: "vertical"
	}),
	centerView = Ti.UI.createView({
		backgroundColor: "#fff"
	}),
	rightView = Ti.UI.createView({
		backgroundColor: "#333"
	}),
	drawer = Ti.UI.Android.createDrawerLayout({
		leftView: leftView,
		centerView: centerView,
		rightView: rightView
	}),
	menu = Ti.UI.createView({
		layout: "vertical"
	}),
	btn1 = Ti.UI.createButton({
		title: 'Open Left'
	}),
	btn2 = Ti.UI.createButton({
		title: 'Open Right'
	}),
	btn3 = Ti.UI.createButton({
		title: 'Lock All'
	}),
	btn4 = Ti.UI.createButton({
		title: 'Lock Left'
	}),
	btn5 = Ti.UI.createButton({
		title: 'Lock Right'
	}),
	btn6 = Ti.UI.createButton({
		title: 'Unlock All'
	});

for (let i = 0; i < 10; ++i) {
	leftView.add(Ti.UI.createLabel({
        color: "#fff",
        text: "Item",
        top: 10,
        bottom: 10,
        height: Ti.UI.SIZE
    }));
}

btn2.addEventListener('click', function() {
	drawer.toggleRight();
});
btn1.addEventListener('click', function() {
	drawer.toggleLeft();
});
btn3.addEventListener('click', function() {
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
});
btn4.addEventListener('click', function() {
    drawer.setDrawerGravity(Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT);
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
});
btn5.addEventListener('click', function() {
    drawer.setDrawerGravity(Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT);
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
});
btn6.addEventListener('click', function() {
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED);
});

centerView.add(menu);
menu.add(btn1);
menu.add(btn2);
menu.add(btn3);
menu.add(btn4);
menu.add(btn5);
menu.add(btn6);

win.addEventListener('open', function() {
	const activity = win.getActivity(),
		actionbar = activity.getActionBar();

	if (actionbar) {
		actionbar.displayHomeAsUp = true;
		actionbar.onHomeIconItemSelected = function() {
			drawer.toggleLeft();
		};
	}
});

win.add(drawer);
win.open();

JIRA Ticket

garymathews avatar Jun 17 '19 21:06 garymathews

Warnings
:warning:

:mag: Can't find junit reports at ./junit.*.xml, skipping generating JUnit Report.

Messages
:book: :fist: The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.

Generated by :no_entry_sign: dangerJS against 5a4124c9efefd5582c8319e3029bd3211682c85b

build avatar Jun 17 '19 21:06 build

@garymathews think this one should then be closed: https://github.com/appcelerator/titanium_mobile/pull/9627

m1ga avatar Jun 18 '19 05:06 m1ga

@garymathews Noticed the following scenarios using the sample app with this PR:

  1. Lock left side drawer only using "Lock Left" button. The left drawer gets locked. Now press "Lock All". The left drawer remains locked but right drawer doesn't gets locked. (same scenario if you lock Right drawer only first)
  2. When we lock both side drawers one by one but not together then "Unlock All" doesn't unlock both the drawers. For eg: press "Lock Left" the press "Lock Right". Both gets locked successfully. Now press "Unlock All". Only the last locked drawer gets unlocked. If instead we use "Lock All" to lock both side drawers then "Unlock All" unlocks both the drawers. Note: Programmatic open of both side drawers works fine whether we lock them one by one or together.

ssekhri avatar Sep 12 '19 22:09 ssekhri