Merge pull request #15651 from zilongshanren/fixNativeCotnrolIssuesV2

fix UI native control onEnter issue
This commit is contained in:
zilongshanren 2016-05-16 16:58:32 +08:00
commit 9203630583
4 changed files with 105 additions and 90 deletions

View File

@ -234,7 +234,7 @@ void VideoPlayer::setVisible(bool visible)
{
cocos2d::ui::Widget::setVisible(visible);
if (! _videoURL.empty())
if (!visible || isRunning())
{
JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, visible);
}
@ -243,13 +243,16 @@ void VideoPlayer::setVisible(bool visible)
void VideoPlayer::onEnter()
{
Widget::onEnter();
this->setVisible(true);
if (isVisible() && !_videoURL.empty())
{
JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, true);
}
}
void VideoPlayer::onExit()
{
Widget::onExit();
this->setVisible(false);
JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, false);
}
void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback)

View File

@ -46,10 +46,10 @@ using namespace cocos2d::experimental::ui;
- (void) resume;
- (void) stop;
- (void) seekTo:(float) sec;
- (void) setVisible:(bool) visible;
- (void) setKeepRatioEnabled:(bool) enabled;
- (void) setFullScreenEnabled:(bool) enabled;
- (bool) isFullScreenEnabled;
- (void) setVisible:(BOOL) visible;
- (void) setKeepRatioEnabled:(BOOL) enabled;
- (void) setFullScreenEnabled:(BOOL) enabled;
- (BOOL) isFullScreenEnabled;
-(id) init:(void*) videoPlayer;
@ -106,14 +106,14 @@ using namespace cocos2d::experimental::ui;
}
}
-(void) setFullScreenEnabled:(bool) enabled
-(void) setFullScreenEnabled:(BOOL) enabled
{
if (self.moviePlayer != nullptr) {
[self.moviePlayer setFullscreen:enabled animated:(true)];
}
}
-(bool) isFullScreenEnabled
-(BOOL) isFullScreenEnabled
{
if (self.moviePlayer != nullptr) {
return [self.moviePlayer isFullscreen];
@ -208,14 +208,14 @@ using namespace cocos2d::experimental::ui;
}
}
-(void) setVisible:(bool)visible
-(void) setVisible:(BOOL)visible
{
if (self.moviePlayer != NULL) {
[self.moviePlayer.view setHidden:!visible];
}
}
-(void) setKeepRatioEnabled:(bool)enabled
-(void) setKeepRatioEnabled:(BOOL)enabled
{
_keepRatioEnabled = enabled;
if (self.moviePlayer != NULL) {
@ -343,18 +343,6 @@ bool VideoPlayer::isFullScreenEnabled()const
return [((UIVideoViewWrapperIos*)_videoView) isFullScreenEnabled];
}
void VideoPlayer::onEnter()
{
Widget::onEnter();
[((UIVideoViewWrapperIos*)_videoView) setVisible:YES];
}
void VideoPlayer::onExit()
{
Widget::onExit();
[((UIVideoViewWrapperIos*)_videoView) setVisible:NO];
}
void VideoPlayer::setFullScreenEnabled(bool enabled)
{
[((UIVideoViewWrapperIos*)_videoView) setFullScreenEnabled:enabled];
@ -418,10 +406,29 @@ void VideoPlayer::setVisible(bool visible)
{
cocos2d::ui::Widget::setVisible(visible);
if (! _videoURL.empty())
if (!visible)
{
[((UIVideoViewWrapperIos*)_videoView) setVisible:visible];
[((UIVideoViewWrapperIos*)_videoView) setVisible:NO];
}
else if(isRunning())
{
[((UIVideoViewWrapperIos*)_videoView) setVisible:YES];
}
}
void VideoPlayer::onEnter()
{
Widget::onEnter();
if (isVisible())
{
[((UIVideoViewWrapperIos*)_videoView) setVisible: YES];
}
}
void VideoPlayer::onExit()
{
Widget::onExit();
[((UIVideoViewWrapperIos*)_videoView) setVisible: NO];
}
void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback)

View File

@ -137,8 +137,26 @@ namespace experimental{
void WebView::setVisible(bool visible)
{
Node::setVisible(visible);
if (!visible || isRunning())
{
_impl->setVisible(visible);
}
}
void WebView::onEnter()
{
Widget::onEnter();
if(isVisible())
{
_impl->setVisible(true);
}
}
void WebView::onExit()
{
Widget::onExit();
_impl->setVisible(false);
}
cocos2d::ui::Widget* WebView::createCloneInstance()
{
@ -198,18 +216,6 @@ namespace experimental{
return _onJSCallback;
}
void WebView::onEnter()
{
Widget::onEnter();
_impl->setVisible(true);
}
void WebView::onExit()
{
Widget::onExit();
_impl->setVisible(false);
}
} // namespace ui
} // namespace experimental
} //namespace cocos2d

View File

@ -203,7 +203,6 @@ public:
* Toggle visibility of WebView.
*/
virtual void setVisible(bool visible) override;
virtual void onEnter() override;
virtual void onExit() override;