Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25556] Android: Add gravity to drawerLockMode #9627

Closed
wants to merge 23 commits into from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Nov 25, 2017

JIRA: https://jira.appcelerator.org/browse/TIMOB-25556

Allow to set gravity (left, right) to lock drawer views separately. The current implementation only locks both side at the same time.

Example

var 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 (var i = 0; i < 10; ++i) {
	var lbl1 = Ti.UI.createLabel({
		color: "#fff",
		text: "Item",
		top: 10,
		bottom: 10,
		height: Ti.UI.SIZE
	});
	leftView.add(lbl1);
}

btn2.addEventListener('click', function() {
	if (drawer.getDrawerLockMode().lockMode != Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED) {
		drawer.toggleRight();
	} else {
		// drawer is locked - check gravity
		if (drawer.getDrawerLockMode().gravity != Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT &&
			drawer.getDrawerLockMode().gravity != Titanium.UI.Android.DrawerLayout.GRAVITY_BOTH) {
			// right is not locked
			drawer.toggleRight();
		}
	}
});
btn1.addEventListener('click', function() {
	if (drawer.getDrawerLockMode().lockMode != Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED) {
		drawer.toggleLeft();
	} else {
		// drawer is locked - check gravity
		if (drawer.getDrawerLockMode().gravity != Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT &&
			drawer.getDrawerLockMode().gravity != Titanium.UI.Android.DrawerLayout.GRAVITY_BOTH) {
			// left is not locked
			drawer.toggleLeft();
		}
	}
});
btn3.addEventListener('click', function() {
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
	console.log(drawer.getDrawerLockMode());
});
btn4.addEventListener('click', function() {
	drawer.setDrawerLockMode({
		lockMode: Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
		gravity: Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT
	});
	console.log(drawer.getDrawerLockMode());
});
btn5.addEventListener('click', function() {
	drawer.setDrawerLockMode({
		lockMode: Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
		gravity: Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT
	});
	console.log(drawer.getDrawerLockMode());
});
btn6.addEventListener('click', function() {
	drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED);
	console.log(drawer.getDrawerLockMode());
});

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() {
	var activity = win.getActivity(),
		actionbar = activity.getActionBar();

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

win.add(drawer);
win.open();
  • Update documentation

@m1ga m1ga changed the title [AC-5383] Android: Add gravity to drawerLockMode [TIMOB-25556] Android: Add gravity to drawerLockMode Nov 26, 2017
Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below

@@ -16,6 +16,18 @@ since: "6.2.0"
platforms: [android]

properties:
- name: GRAVITY_LEFT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also document GRAVITY_BOTH ?

layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
if (param instanceof HashMap) {
HashMap<String, Object> drawerParams = (HashMap<String, Object>) param;
if (TiConvert.toInt(drawerParams.get(TiC.PROPERTY_GRAVITY)) == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the constant GRAVITY_BOTH instead of 1

NOTE: you could also use a KrollDict and use getInt(TiC.PROPERTY_GRAVITY) instead of needing to use TiConvert

@build
Copy link
Contributor

build commented Dec 4, 2017

Fails
🚫

🔬 There are library changes, but no changes to the unit tests. That's OK as long as you're refactoring existing code, but will require an admin to merge this PR. Please see README.md#unit-tests for docs on unit testing.

🚫

Tests have failed, see below for more information.

Messages
📖

🎉 Another contribution from our awesome community member, m1ga! Thanks again for helping us make Titanium SDK better. 👍

Tests:

Classname Name Time Error
ios.console #timeEnd 0 file:///Users/build/Library/Develo
ios.console #time 0.004 file:///Users/build/Library/Develo
ios.Error Native exception surfaced 0.001 file:///Users/build/Library/Developer/CoreSimulator/Devices/6D5153ED-8BCB-4C7A-9BAE-94495AFC2E09/data
ios.Titanium.Analytics .optedOut 0.001 file:///Users/build/Library/Devel
ios.Titanium.App Multiple global event listeners (TIMOB-25836) 0.001 [native code]
file:///Users/build/Library/Developer/CoreSimulator/Devices/6D51
ios.Titanium.Media.VideoPlayer Release video player and close window (TIMOB-26033) 10.01 file:///Users/build/Librar
ios.Titanium.Media.VideoPlayer showsControls 0.001 file:///Users/build/Libr
ios.Titanium.Media.VideoPlayer volume 0.001 file:///Users/build/
ios.Titanium.UI #convertUnits() returns 25.4 mm = dpi pixels 0.001 file:///Users/build/Library/Developer/CoreS
ios.Titanium.UI #convertUnits() converts 1 in = dpi pixels 0.001 file:///Users/build/Libr
ios.Titanium.UI #convertUnits() returns Ti.Platform.DisplayCaps.logicalDensityFactory for 1dip to pixels 0.001 file:///Users/build/Library/Developer/
ios.Titanium.UI #convertUnits() returns 2.54cm = dpi pixels 0 file:///Users/build/Library/Developer/CoreS
ios.Titanium.UI #convertUnits() converts 100 unspecified units to px 0.001 file:///Users/build/Library/Developer/Core
ios.Titanium.UI.iOS #createStepper() 0.014 file:///Users/build/Li
ios.Titanium.UI.iOS #constants 0.004 file:///Users/build/Library/Deve
ios.Titanium.UI.iOS.NavigationWindow .navigationWindow 10.005 file:///Users/build/Librar
ios.Titanium.UI.MaskedImage createMaskedImage 0.001 file:///Users/build/Library/D
ios.Titanium.UI.View backgroundGradient (linear) 10.004 file:///Users/build/Librar
ios.Titanium.UI.View backgroundGradient (radial) 10.003 file:///Users/build/Librar
ios.Titanium.UI.WebView .zoomLevel 10.004 file:///Users/build/Librar
ios.Titanium.UI.Window .homeIndicatorAutoHidden 0.001 file:///Users/build/Library/Devel

Generated by 🚫 dangerJS

@hansemannn
Copy link
Collaborator

@m1ga Bootstrap for the unit-test:

ti.ui.android.drawerlayout.addontest.js

/*
 * Appcelerator Titanium Mobile
 * Copyright (c) 2017 by Axway, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
/* eslint-env mocha */
/* global Titanium */
/* eslint no-unused-expressions: "off" */
'use strict';

var should = require('./utilities/assertions');

describe.android('Titanium.UI.Android.DrawerLayout', function () {
 // Add required tests here
});

@m1ga
Copy link
Contributor Author

m1ga commented Jun 23, 2018

Shall I keep the syntax like it is (setDrawerLockMode with custom parameters) or shall I change it separate functions like mentioned above (e.g. setLeftDrawerLockMode)

@build
Copy link
Contributor

build commented Jun 23, 2018

Fails
🚫

🔬 There are library changes, but no changes to the unit tests. That's OK as long as you're refactoring existing code, but will require an admin to merge this PR. Please see README.md#unit-tests for docs on unit testing.

🚫 Tests have failed, see below for more information.
Messages
📖

💾 Here's the generated SDK zipfile.

📖 🎉 Another contribution from our awesome community member, m1ga! Thanks again for helping us make Titanium SDK better. 👍
📖 ❌ 2 tests have failed There are 2 tests failing and 462 skipped out of 3631 total tests.

Tests:

Classname Name Time Error
android.emulator.Titanium.UI.Android.DrawerLayout drawerLockMode 0.002 expected Object { lockMode: 3, gravity: 1 } to equal 3
android.emulator.Titanium.UI.WebView .zoomLevel 0.891 expected 0.25 to equal 1

Generated by 🚫 dangerJS against 75c76db

@m1ga
Copy link
Contributor Author

m1ga commented Jun 27, 2018

I have problem testing the file locally. Is this enough:

/*
 * Appcelerator Titanium Mobile
 * Copyright (c) 2017 by Axway, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
/* eslint-env mocha */
/* global Titanium */
/* eslint no-unused-expressions: "off" */
'use strict';

var should = require('./utilities/assertions');

describe.android('Titanium.UI.Android.DrawerLayout', function () {
   describe.android('drawerLockMode', function () {
       var drawerLayout = Titanium.UI.Android.createDrawerLayout();

       // default
       should(drawerLayout.drawerLockMode).an.Object;
       should(drawerLayout.drawerLockMode.lockMode).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNDEFINED);

       // legacy - both
       drawer.setDrawerLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
       should(drawerLayout.getDrawerLockMode().getLockMode()).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

       drawer.setDrawerLockMode({
           lockMode: Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED,
           gravity: Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT
       });
       should(drawerLayout.getDrawerLockMode().lockMode).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED);
       should(drawerLayout.getDrawerLockMode().gravity).eql(Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT);

       drawer.setDrawerLockMode({
           lockMode: Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
           gravity: Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT
       });
       should(drawerLayout.drawerLockMode.getLockMode()).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
       should(drawerLayout.drawerLockMode.getGravity()).eql(Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT);

       drawer.drawerLockMode.lockMode = Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_OPEN;
       drawer.drawerLockMode.gravity = Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT;
       should(drawerLayout.drawerLockMode.getLockMode()).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_OPEN);
       should(drawerLayout.drawerLockMode.getGravity()).eql(Titanium.UI.Android.DrawerLayout.GRAVITY_LEFT);

       drawer.drawerLockMode.setLockMode(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED);
       drawer.drawerLockMode.setGravity(Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT);
       should(drawerLayout.drawerLockMode.lockMode).eql(Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED);
       should(drawerLayout.drawerLockMode.gravity).eql(Titanium.UI.Android.DrawerLayout.GRAVITY_RIGHT);
   });
});

@hansemannn hansemannn modified the milestones: 7.4.0, 7.5.0 Aug 24, 2018
@sgtcoolguy sgtcoolguy modified the milestones: 7.5.0, 8.0.0 Sep 18, 2018
@mukherjee2 mukherjee2 modified the milestones: 8.0.0, 8.1.0 Jan 16, 2019
@sgtcoolguy sgtcoolguy modified the milestones: 8.1.0, 8.2.0 Jun 3, 2019
@build
Copy link
Contributor

build commented Jun 7, 2019

Fails
🚫

🔬 There are library changes, but no changes to the unit tests. That's OK as long as you're refactoring existing code, but will require an admin to merge this PR. Please see README.md#unit-tests for docs on unit testing.

🚫 Tests have failed, see below for more information.
Messages
📖

💾 Here's the generated SDK zipfile.

📖 🎉 Another contribution from our awesome community member, m1ga! Thanks again for helping us make Titanium SDK better. 👍
📖 ❌ 2 tests have failed There are 2 tests failing and 464 skipped out of 3615 total tests.

Tests:

ClassnameNameTimeError
android.emulator.Titanium.UI.Android.DrawerLayoutdrawerLockMode0.001
Error: expected Object { lockMode: 3, gravity: 1 } to equal 3
at Assertion.fail (/node_modules/should/cjs/should.js:275:17)
      at Assertion.value (/node_modules/should/cjs/should.js:356:19)
      at Context.<anonymous> (/ti.ui.android.drawerlayout.test.js:107:41)
      at Test.Runnable.run (/ti-mocha.js:4372:37)
      at Runner.runTest (/ti-mocha.js:4759:14)
      at /ti-mocha.js:4836:16
      at next (/ti-mocha.js:4684:18)
      at /ti-mocha.js:4694:11
      at next (/ti-mocha.js:4632:28)
      at /ti-mocha.js:4661:9
android.emulator.Titanium.UI.TabGroupadd Map.View to TabGroup10.014
Error: timeout of 10000ms exceeded
at Titanium.<anonymous> (/ti-mocha.js:4290:23)

Generated by 🚫 dangerJS against 35d589f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants