viezel / NappDrawer

A side drawer navigation container view controller for Appcelerator Titanium.
MIT License
247 stars 128 forks source link

Actionbar home click not work #180

Open PietroGranati opened 9 years ago

PietroGranati commented 9 years ago

$.drawer.addEventListener('open', onNavDrawerWinOpen);

function onNavDrawerWinOpen(evt) { this.removeEventListener('open', onNavDrawerWinOpen);

if(this.getActivity()) {
    // need to explicitly use getXYZ methods
    var actionBar = this.getActivity().getActionBar();

    if (actionBar) {
        // Now we can do stuff to the actionbar  
        actionBar.setTitle('Menu');

        // show an angle bracket next to the home icon,
        // indicating to users that the home icon is tappable
        actionBar.setDisplayHomeAsUp(true);
        actionBar.setHomeButtonEnabled(true);

        // toggle the left window when the home icon is selected

        actionBar.setOnHomeIconItemSelected(function() {
            Ti.API.info("CLICK");
            $.drawer.toggleLeftWindow();
       });
    }
}    

}

Ti Api info never show in console

fabiomlferreira commented 9 years ago

I think this stop working site api level 21, I have the same problem I want to set the hamburger icon and make it toggle the side menu, but I can't find any solution on Android.

@PietroGranati do you found any solution?

manumaticx commented 9 years ago

@invaderhd just came across this through https://github.com/ricardoalcocer/actionbarextras/issues/87

Try updating to 1.1.6 if you are using 4.1.0.GA This should be fixed here #173

/cc @PietroGranati

Brian-McBride commented 9 years ago

@manumaticx Your drawer is a great fix, but I have a client that went a bit crazy because they hated the actionbar on top of the drawer. Since Titanium does not support the new ToolBar widget, I need to go back to this.

I'd love to know if anyone got the onclick listener working in this module...

rwuttke commented 9 years ago

Not sure if this will help, but I had a similar problem.

Added

hamburgerIcon : true

and my menus all came back.

fabiomlferreira commented 9 years ago

@rwuttke you added hamburgerIcon: true where?

You add it to the drawer? This icon handle click events?

Please show a portion of your code.

PietroGranati commented 9 years ago

@rwuttke Where did you put that? @invaderhd Nope no solution

rwuttke commented 9 years ago

Sorry guys for being way to terse.

In the creation of the napp drawer itself. Add that as an attribute, or you can call .setHamburgerIcon(true) on the window you created.

var NappDrawerModule = require('dk.napp.drawer');
var mainWindow = NappDrawerModule.createDrawer({
    fullscreen:false, 
    leftWindow: leftMenuView,
    centerWindow: centerView,
    rightWindow: rightMenuView,
    fading: 0.2, // 0-1
    parallaxAmount: 0.2, //0-1
    shadowWidth:"40dp", 
    leftDrawerWidth: "200dp",
    rightDrawerWidth: "200dp",
    animationMode: NappDrawerModule.ANIMATION_NONE,
    closeDrawerGestureMode: NappDrawerModule.CLOSE_MODE_MARGIN,
    openDrawerGestureMode: NappDrawerModule.OPEN_MODE_ALL,
    orientationModes: [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT],
    hamburgerIcon : true // Add this line
});
fabiomlferreira commented 9 years ago

@rwuttke and only with this code the hamburger icon handle the click automatically and open and close the drawer?

In my app I manage to add the hamburger icon but it won't do nothing on click.

rwuttke commented 9 years ago

Well you would still need the event handlers, this was just to show what I added to the creation.

I had code similar to the OP, and the setOnHomeIconItemSelected was not being fired, adding this in just worked, the event was fired.

actionBar.setOnHomeIconItemSelected(function() {
    Ti.API.info("CLICK");
    $.drawer.toggleLeftWindow();
});

The Ti.API.info should be in the log and the left window should toggle.

If you have the code for creating the options menu and such, this should just start working as well, ie the menu items, or icons if you are using them, should appear and the click events should be fired.

fabiomlferreira commented 9 years ago

@rwuttke It work!! Thank you

I have to change this:

actionBar.onHomeIconItemSelected = function(e) {
     Ti.API.info("Home icon clicked!");
     $.drawer.openLeftWindow();
};

to to your example:

actionBar.setOnHomeIconItemSelected(function() {
       Ti.API.info("Home icon clicked!");
       $.drawer.openLeftWindow();
});

This is really a strange problem but it works now.

fabiomlferreira commented 9 years ago

@rwuttke Can you try to open one app then open the app that you are developing without close the other app only minimize and check if the hamburger icon receive the click.

In my case if I open the app the app without anything open on android the click if fired if I have multiple apps opened I don't get any click event. Can someone confirm this?

I think I need to change to other module this module is driving me crazy

rwuttke commented 9 years ago

@invaderhd I have no problems with that, I can change between apps, come back and the hamburger is working fine.

fabiomlferreira commented 9 years ago

@rwuttke My problem it not changing between app if for example you open your app, then open other app for example chrome, then only your app and open it again, is in this point that my hamburger stop working.

Since I'm unable to get this completly fix I decided to use https://github.com/manumaticx/Ti.DrawerLayout, we only need to add this to the style

drawerLayout: true

and everything works great on android.

ghost commented 8 years ago

O thanks god! HamburgerIcon : true save wasting one week researching about menu problem.