cocos2d-js icon indicating copy to clipboard operation
cocos2d-js copied to clipboard

Add UIWebView JS Binding

Open MohHeader opened this issue 9 years ago • 11 comments

Here I added the UIWebView api to cocos2d-js Hope it meets your standard and can merge the PR.

Kind regards,

MohHeader avatar Mar 07 '15 09:03 MohHeader

Hi, @MohHeader We really appreciate your contribution !

First of all, UIWebView is not bound because it's still experimental in Cocos2d-x, that means its APIs are not stable, and it's not implemented for all platforms. And most of all, we have other priorities. But we do receive other users claim their requirements for WebView. If you are willing to do this, we will discuss whether it's ok to support UIWebView in Cocos2d-JS on Monday.

Secondly, about PR of bindings, we do have some rules:

  1. No auto bindings codes (everything in frameworks/js-bindings/auto) should be committed, because they are gonna be generated automatically by a robot.
  2. The configuration file changes should be committed instead, that means modifications in tools/tojs.
  3. Cocos2d-JS's API should follow the same style which is different than Cocos2d-x, for example, no create functions should be bound, all constructors and init functions should be bound because we use new construction in JS.

You can refer to this discussion too: http://discuss.cocos2d-x.org/t/how-to-upload-image-within-app-to-server-with-cocos2d-js/19569/11

More specifically, if you are willing to improve your PR, please do the following:

  1. Commit your changes in tools/tojs/cocos2dx_ui.ini instead of all the codes in auto folder.
  2. Create a PR to Cocos2d-x repo and modify the accessibility of UIWebView's constructor to CC_CONSTRUCTOR_ACCESS so that its constructor can be automatically bound with bindings generator.

pandamicro avatar Mar 07 '15 15:03 pandamicro

Hi @pandamicro , It is nice to hear from you.

And for sure I can understand your priorities, :smiley:

I will update the PR, based on your advice ASAP, Looking forward to hear from you regarding Monday's meeting.

Thanks,

MohHeader avatar Mar 07 '15 16:03 MohHeader

Hi, @MohHeader Sorry, we can't bind WebView yet because of a bindings generator problem.

The WebView is only implemented on iOS and Android, but the auto bindings codes are for all platforms, so the bindings of WebView will cause compiling issues on other platforms.

pandamicro avatar Mar 09 '15 03:03 pandamicro

Hi @pandamicro , What about applying the Binding in the Manual folder, may be there we can handle the platforms issue ?

Or do you think that we have just to wait that WebView supports all other platforms ?

May be we can do both ( Move it to the Manual ) and let it stay as an unmerged PR, so that others can benefit from it ?

Thanks :smiley:

MohHeader avatar Mar 09 '15 06:03 MohHeader

Good idea! In this case, you need to wrap all the bindings code of WebView into a if section like this:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

...

#endif

pandamicro avatar Mar 09 '15 07:03 pandamicro

Hi, @MohHeader, I think I found another solution, we need to create another auto binding configuration file for such features (platform oriented). Then the registration function can be wrapped into a target selector macro. We have decided to merge WebView and VideoPlayer in v3.5

pandamicro avatar Mar 10 '15 14:03 pandamicro

@MohHeader

Can you help me try this webpage https://www.anyimg.org/ with your WebView and test it on Android device?

The webpage can loaded properly but the "Pick an image" button not working on my Android device v4.4.4.

But it is working properly on iOS device v.7.1.2

Thanks.

0xJimmyBeh avatar Mar 12 '15 15:03 0xJimmyBeh

Hi @pandamicro , That's great news, for now I will update the PR with the new instructions, ( I know I am late, But it was a very busy week )

Hi @Zinitter Yes sure let me test it. But I think it may have an issue with how android do handle the request to select file. Did you tried the same page using cocos2d-x WebView ? or it will be better if you tried using a normal android project's webview to test it.

MohHeader avatar Mar 13 '15 07:03 MohHeader

Hi @Zinitter I tried to search the issue too, And yes, it looks that it needs a special handling http://stackoverflow.com/questions/5907369/file-upload-in-webview

Note that not some Android versions ( like 4.4.4 ) needs more special handling steps.

May be you will need to create an issue on cocos2d-x github repo.

:)

MohHeader avatar Mar 13 '15 07:03 MohHeader

Hi @MohHeader

Thanks for your help and the info you given!

Currently, i'm learning how to develop with Cocos2d-JS in Cocos Code IDE. So i only tested the page with ccui.WebView in Cocos2d-JS as i not familiar with Cocos2d-X.

However, I tried to open the page in mobile browser of Android device, the button working fine. May be we can reflect this WebView problem on Android to Cocos2d-X.

0xJimmyBeh avatar Mar 13 '15 10:03 0xJimmyBeh

@MohHeader

I tested the webpage with Cocos2d-X v3.4 cpp-tests on Android device. The button is not working.

0xJimmyBeh avatar Mar 13 '15 17:03 0xJimmyBeh