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

PageView addEventListener() doesn't work in Android #15325

Closed
lifzgreat opened this issue Mar 28, 2016 · 18 comments
Closed

PageView addEventListener() doesn't work in Android #15325

lifzgreat opened this issue Mar 28, 2016 · 18 comments

Comments

@lifzgreat
Copy link

This works in web but not in Android (posted here but realized that was deprecated). It's possible that it's not necessarily web vs Android but mouse vs touch.

ctor: function () {
    var pageView = new ccui.PageView();

    for (var i = 0; i < 3; ++i) {
        var layout = new ccui.Layout();
        pageView.addPage(layout);
    }

    pageView.addEventListener(this.pageViewScrolled, this);
},

pageViewScrolled: function(sender, type) {
    cc.log("pageView scrolled.");
}
@zilongshanren
Copy link
Member

@lifzgreat The latest v3 has already fixed this issue.

@lifzgreat
Copy link
Author

Is it available on cocos2d-x.org? I had the latest as of not long ago! Or do I need to clone the repo?

@zilongshanren
Copy link
Member

@lifzgreat no, it's not on cocos2d-x.org, you should clone the repo if you want to test it now.

@lifzgreat
Copy link
Author

Ok, I will test it. I will respond with findings here. Thanks for the quick response!

When does the main site get updated with the latest v3 branch?

@zilongshanren
Copy link
Member

@lifzgreat It will happen in the early April, but I can't promise the exactly release date, lots tests need to be done before we officially announce the release to the public.

@lifzgreat
Copy link
Author

Thanks so much! I am cloning now...wish me luck :)

@lifzgreat
Copy link
Author

Ok, I just cloned the newest v3 branch and ran coocs run -p android against the existing project. The PageView's event listener didn't fire. I'm using a PageView from Cocos Studio's UI elements and it works great on web but just not in Android. I can try manually creating the PageView in code again like the code in the initial bug report above.

@zilongshanren
Copy link
Member

@lifzgreat Which project do you test? I have tested js-tests and it works fine.

@lifzgreat
Copy link
Author

I ran it against my personal project. I will test js-tests on Android again to see if it works.

Do I have to create the PageView in code or can I use Cocos Studio?

@zilongshanren
Copy link
Member

@lifzgreat I think both ways should be working... either in code or with CocoStudio.

@lifzgreat
Copy link
Author

Yes sir, it works perfectly in js-tests. I did notice a couple differences:

var root = this._parseUIFile("ccs-res/cocosui/UIEditorTest/UIPageView/pageview_1.json");
var pageView =ccui.helper.seekWidgetByName(root, "PageView_1269");

I've always done:

var root = ccs.load(res.Scene_json);
pageView = root.node.getChildByName("PageView");

Also, js-test has a pageview.json file that looks vastly different than the one that was exported from Cocos Studio for me.

@zilongshanren
Copy link
Member

@lifzgreat
The search method you used should working, the code in js-tests might be more time efficient.
I think the core reason doesn't in here, nor does the pageview.json file..

Maybe you should pay attention to the page turn event callback.

@lifzgreat
Copy link
Author

The callback is incredibly simple so this can't be it, right?

ctor: function() {
    pageView.addEventListener(this.pageScrolled, this);
},
pageScrolled: function(sender, type) {
    cc.log("PageView scrolled.");
}

I'm going to remove the /frameworks/runtime-src/proj.android folder and let it compile everything fresh. Maybe the new v3 I cloned isn't compiling certain pieces because they already existed from an old compile.

@zilongshanren
Copy link
Member

@lifzgreat
I suggest you create a new project with cocos new -l js and add your code to the newly created project.

I don't quite understand how you are using the v3 branch code to do the test...

@lifzgreat
Copy link
Author

Ok, I will do that if this doesn't work. Just for the sake of information, I moved my old cocos2d-x-3.10 folder to cocos2d-x-3.10_OLD and cloned the v3 branch into cocos2d-x-3.10. So it's using all of the new branch to compile. But I will do what you suggested if this next compile doesn't work :)

@lifzgreat
Copy link
Author

As you suggested, I created a new project and imported my code into the newly created project and it worked perfectly.

Thanks so much for the quick responses! I can't wait for the new cocos to come out to the public. What a fantastic framework.

@zilongshanren
Copy link
Member

@lifzgreat 😄 Should I close this issue now?

@lifzgreat
Copy link
Author

Yes sir! Thanks again :)

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

No branches or pull requests

2 participants