From 850c479516a22a9ec50f340fedae7f5046027bb6 Mon Sep 17 00:00:00 2001 From: Wenhai Lin Date: Thu, 12 May 2016 14:26:28 +0800 Subject: [PATCH] Sync Bug fix: 1. HttpClient: remove Content-Type limitation 2.VideoPlayer/WebView: hide system native control when the Node leaves the 'stage' --- native/cocos/network/HttpClient-apple.mm | 5 ----- native/cocos/ui/UIVideoPlayer-android.cpp | 17 ++++++++++++++- native/cocos/ui/UIVideoPlayer-ios.mm | 25 +++++++++++++++++------ native/cocos/ui/UIVideoPlayer.h | 2 ++ native/cocos/ui/UIWebView-inl.h | 17 ++++++++++++++- native/cocos/ui/UIWebView.h | 3 +++ 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/native/cocos/network/HttpClient-apple.mm b/native/cocos/network/HttpClient-apple.mm index d4114a3305..5f02256e18 100644 --- a/native/cocos/network/HttpClient-apple.mm +++ b/native/cocos/network/HttpClient-apple.mm @@ -166,11 +166,6 @@ static int processTask(HttpClient* client, HttpRequest* request, NSString* reque //if request type is post or put,set header and data if([requestType isEqual: @"POST"] || [requestType isEqual: @"PUT"]) { - if ([requestType isEqual: @"PUT"]) - { - [nsrequest setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"]; - } - char* requestDataBuffer = request->getRequestData(); if (nullptr != requestDataBuffer && 0 != request->getRequestDataSize()) { diff --git a/native/cocos/ui/UIVideoPlayer-android.cpp b/native/cocos/ui/UIVideoPlayer-android.cpp index be16a41b72..fc2cb72a0f 100644 --- a/native/cocos/ui/UIVideoPlayer-android.cpp +++ b/native/cocos/ui/UIVideoPlayer-android.cpp @@ -234,12 +234,27 @@ void VideoPlayer::setVisible(bool visible) { cocos2d::ui::Widget::setVisible(visible); - if (! _videoURL.empty()) + if (!visible || isRunning()) { JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, visible); } } +void VideoPlayer::onEnter() +{ + Widget::onEnter(); + if (isVisible() && ! _videoURL.empty()) + { + JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, true); + } +} + +void VideoPlayer::onExit() +{ + Widget::onExit(); + JniHelper::callStaticVoidMethod(videoHelperClassName, "setVideoVisible", _videoPlayerIndex, false); +} + void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback) { _eventCallback = callback; diff --git a/native/cocos/ui/UIVideoPlayer-ios.mm b/native/cocos/ui/UIVideoPlayer-ios.mm index 6783b621e0..01417589f8 100644 --- a/native/cocos/ui/UIVideoPlayer-ios.mm +++ b/native/cocos/ui/UIVideoPlayer-ios.mm @@ -45,7 +45,7 @@ using namespace cocos2d::experimental::ui; - (void) resume; - (void) stop; - (void) seekTo:(float) sec; -- (void) setVisible:(bool) visible; +- (void) setVisible:(BOOL) visible; - (void) setKeepRatioEnabled:(bool) enabled; - (void) setFullScreenEnabled:(bool) enabled; - (bool) isFullScreenEnabled; @@ -207,7 +207,7 @@ using namespace cocos2d::experimental::ui; } } --(void) setVisible:(bool)visible +-(void) setVisible:(BOOL)visible { if (self.moviePlayer != NULL) { [self.moviePlayer.view setHidden:!visible]; @@ -347,6 +347,19 @@ void VideoPlayer::setFullScreenEnabled(bool enabled) [((UIVideoViewWrapperIos*)_videoView) setFullScreenEnabled:enabled]; } +void VideoPlayer::onEnter() +{ + Widget::onEnter(); + if (isVisible()) + [((UIVideoViewWrapperIos*)_videoView) setVisible:YES]; +} + +void VideoPlayer::onExit() +{ + Widget::onExit(); + [((UIVideoViewWrapperIos*)_videoView) setVisible:NO]; +} + void VideoPlayer::setKeepAspectRatioEnabled(bool enable) { if (_keepAspectRatioEnabled != enable) @@ -405,10 +418,10 @@ void VideoPlayer::setVisible(bool visible) { cocos2d::ui::Widget::setVisible(visible); - if (! _videoURL.empty()) - { - [((UIVideoViewWrapperIos*)_videoView) setVisible:visible]; - } + if (!visible) + [((UIVideoViewWrapperIos*)_videoView) setVisible:NO]; + else if(isRunning()) + [((UIVideoViewWrapperIos*)_videoView) setVisible:YES]; } void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback) diff --git a/native/cocos/ui/UIVideoPlayer.h b/native/cocos/ui/UIVideoPlayer.h index 71d1673008..79ebddaa2e 100644 --- a/native/cocos/ui/UIVideoPlayer.h +++ b/native/cocos/ui/UIVideoPlayer.h @@ -172,6 +172,8 @@ namespace experimental{ virtual void onPlayEvent(int event); virtual void setVisible(bool visible) override; virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override; + virtual void onEnter() override; + virtual void onExit() override; protected: virtual cocos2d::ui::Widget* createCloneInstance() override; diff --git a/native/cocos/ui/UIWebView-inl.h b/native/cocos/ui/UIWebView-inl.h index 3c28c3adad..5933723a02 100644 --- a/native/cocos/ui/UIWebView-inl.h +++ b/native/cocos/ui/UIWebView-inl.h @@ -136,7 +136,9 @@ namespace experimental{ void WebView::setVisible(bool visible) { Node::setVisible(visible); - _impl->setVisible(visible); + + if(!visible || isRunning()) + _impl->setVisible(visible); } cocos2d::ui::Widget* WebView::createCloneInstance() @@ -196,6 +198,19 @@ namespace experimental{ { return _onJSCallback; } + + void WebView::onEnter() + { + Widget::onEnter(); + if(isVisible()) + _impl->setVisible(true); + } + + void WebView::onExit() + { + Widget::onExit(); + _impl->setVisible(false); + } } // namespace ui } // namespace experimental diff --git a/native/cocos/ui/UIWebView.h b/native/cocos/ui/UIWebView.h index 699e9dafec..75acfa3506 100644 --- a/native/cocos/ui/UIWebView.h +++ b/native/cocos/ui/UIWebView.h @@ -203,6 +203,9 @@ public: * Toggle visibility of WebView. */ virtual void setVisible(bool visible) override; + + virtual void onEnter() override; + virtual void onExit() override; protected: virtual cocos2d::ui::Widget* createCloneInstance() override;