scrollview listener take all focus and don't pass underneath

I have two listener : 

local somescrollview = widget.newScrollView

    {

        width = 100,

        height = 100,

        listener = function() return false end

    }

///

Runtime:addEventListener( “touch”, someTouchEvent )

but if touch begin inside scrollview, runtime event never happen

i know scrollview have takeFocus() function. then how to make scrollview lose focus?

I try to return both true or false, but nothing changed

help me TT

What for you need this?

I’m making business app that have four screen.

so I make slide screen. if user swipe left or right on screen, menu get passed to next screen

Runtime event listener do this slide action,

and one of the screen have scrollivew.

I just want to execute function from both scrollView listener and runtime listener.

sorry for my bad english. I add example image for helping understand :

%BE%DB%BC%EE%C6%DB_%BD%C7%C7%E0_%B9%D7_%

five button from bottom and can be slided

Maybe this would be helpful.

thank you for answering.

but I ask about listener, not slidemenu.

I mean, how to occur both listener, from runtime and scrollview’s

um… for example:


local g = display.newGroup()

local scrollview= widget.newScrollView

    {

        width =100,

        height = 100,

        scrollWidth = 100,

        scrollHeight = 100,

        hideBackground = true,

        horizontalScrollDisabled = true,

        listener = function(event)

                print(event)

                return false

        end

    }

g:insert(scrollview)

Runtime:addEventListener( “touch”, function(event)

        print( event )

        return false

end )


if i do this, i only get begin event from runtime listener.

i want to get print form both listener at same time.

I’m so sorry for my bad english TT

First of all. You should never do this:

Runtime:addEventListener( "touch", function(event) print( event ) return false end )

You are using an anonymous function. If you try to remove that listener later you cannot because you don’t have a reference to the original  function. In this case, you have to do:

local function runtimeTouchListener( event )      print(event)      return false end Runtime:addEventListener("touch", runtimeTouchListener)

And we’ve seen problems with touch listeners on the Runtime too.

I also don’t quite see where you need to pass the events around. If I were making this app, I’d use a widget.newTableView for the item list. I would also create my own menu bar that when each entry is tapped, it would push the tableView down by however much height it needed for the menu options. When they are tapped, collapse the menu back and slide the tableView back into place and probably reloaded with your new selections.

I don’t see a need to stack scrollViews on top of each other or get touch events from the Runtime at all.

Rob

Appriciate for answering.

It was very helpful.

but I think scrollview have to able to return true or false to pass event.

not especially this case, I often needed to get scrollview’s event underneath.

and in addition, I have developed javascript, so I often use anonymous function as another function’s argment.

is this occur memory leak or low performance, not only that it can’t remove listener?

Anonymous functions are great except for when adding them as event listeners.

Internally the event listeners are tracked in a table that includes two keys: the event type, i.e. “touch”, “tap”, etc. and the address of the function being added.

If you do:

object:addEventListener(“touch”, function( event ) doSomething=true; end)

An address to the anonymous function is generated and stored in the internal table. You have no access to that address. If you later try and do:

object:removeEventListener(“touch”, function( event ) doSomething=true; end)

That’s a new anonymous function with a different memory address and we can’t find it in the table so it doesn’t get removed. Now for things like touch on an object it’s not a big deal because you can remove the object later. But for Runtime, or “enterFrame” operations, anything you have to remove yourself, it’s a problem. Your ScrollView anonymous function is okay because you won’t ever need to remove it.

ScrollViews have a method called takeFocus (https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html) that can be used to have the ScrollView take the focus if you detect movement in an object inside the scrollView.  I know this works when you  have scrollViews inside of other scrollViews (say one is horizontal only scrolling and the other is vertical only). You might be able to use this to help.

Still I would avoid putting a touch listener on the Runtime.

Rob

What for you need this?

I’m making business app that have four screen.

so I make slide screen. if user swipe left or right on screen, menu get passed to next screen

Runtime event listener do this slide action,

and one of the screen have scrollivew.

I just want to execute function from both scrollView listener and runtime listener.

sorry for my bad english. I add example image for helping understand :

%BE%DB%BC%EE%C6%DB_%BD%C7%C7%E0_%B9%D7_%

five button from bottom and can be slided

Maybe this would be helpful.

thank you for answering.

but I ask about listener, not slidemenu.

I mean, how to occur both listener, from runtime and scrollview’s

um… for example:


local g = display.newGroup()

local scrollview= widget.newScrollView

    {

        width =100,

        height = 100,

        scrollWidth = 100,

        scrollHeight = 100,

        hideBackground = true,

        horizontalScrollDisabled = true,

        listener = function(event)

                print(event)

                return false

        end

    }

g:insert(scrollview)

Runtime:addEventListener( “touch”, function(event)

        print( event )

        return false

end )


if i do this, i only get begin event from runtime listener.

i want to get print form both listener at same time.

I’m so sorry for my bad english TT

First of all. You should never do this:

Runtime:addEventListener( "touch", function(event) print( event ) return false end )

You are using an anonymous function. If you try to remove that listener later you cannot because you don’t have a reference to the original  function. In this case, you have to do:

local function runtimeTouchListener( event )      print(event)      return false end Runtime:addEventListener("touch", runtimeTouchListener)

And we’ve seen problems with touch listeners on the Runtime too.

I also don’t quite see where you need to pass the events around. If I were making this app, I’d use a widget.newTableView for the item list. I would also create my own menu bar that when each entry is tapped, it would push the tableView down by however much height it needed for the menu options. When they are tapped, collapse the menu back and slide the tableView back into place and probably reloaded with your new selections.

I don’t see a need to stack scrollViews on top of each other or get touch events from the Runtime at all.

Rob

Appriciate for answering.

It was very helpful.

but I think scrollview have to able to return true or false to pass event.

not especially this case, I often needed to get scrollview’s event underneath.

and in addition, I have developed javascript, so I often use anonymous function as another function’s argment.

is this occur memory leak or low performance, not only that it can’t remove listener?

Anonymous functions are great except for when adding them as event listeners.

Internally the event listeners are tracked in a table that includes two keys: the event type, i.e. “touch”, “tap”, etc. and the address of the function being added.

If you do:

object:addEventListener(“touch”, function( event ) doSomething=true; end)

An address to the anonymous function is generated and stored in the internal table. You have no access to that address. If you later try and do:

object:removeEventListener(“touch”, function( event ) doSomething=true; end)

That’s a new anonymous function with a different memory address and we can’t find it in the table so it doesn’t get removed. Now for things like touch on an object it’s not a big deal because you can remove the object later. But for Runtime, or “enterFrame” operations, anything you have to remove yourself, it’s a problem. Your ScrollView anonymous function is okay because you won’t ever need to remove it.

ScrollViews have a method called takeFocus (https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html) that can be used to have the ScrollView take the focus if you detect movement in an object inside the scrollView.  I know this works when you  have scrollViews inside of other scrollViews (say one is horizontal only scrolling and the other is vertical only). You might be able to use this to help.

Still I would avoid putting a touch listener on the Runtime.

Rob