[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[core][Android] Add RenderSuccess callback
Browse files Browse the repository at this point in the history
  • Loading branch information
yxping authored and YorkShen committed Jul 19, 2018
1 parent f98704f commit 498615d
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 13 deletions.
11 changes: 11 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ public int callCreateFinish(String instanceId) {
return errorCode;
}

@Override
public int callRenderSuccess(String instanceId) {
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callRenderSuccess(instanceId);
} catch (Throwable e) {
WXLogUtils.e(TAG, "callCreateFinish throw exception:" + e.getMessage());
}
return errorCode;
}

@Override
public int callAppendTreeCreateFinish(String instanceId, String ref) {
int errorCode = IWXBridge.INSTANCE_RENDERING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,33 @@ public int callCreateFinish(String instanceId) {
return IWXBridge.INSTANCE_RENDERING;
}

public int callRenderSuccess(String instanceId) {
if (WXEnvironment.isApkDebugable() && BRIDGE_LOG_SWITCH) {
mLodBuilder.append("[WXBridgeManager] callRenderSuccess >>>> instanceId:").append(instanceId);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}

if (mDestroyedInstanceId != null && mDestroyedInstanceId.contains(instanceId)) {
return IWXBridge.DESTROY_INSTANCE;
}

try {
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
GraphicActionRenderSuccess action = new GraphicActionRenderSuccess(instanceId);
WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(instanceId, action);
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callRenderSuccess exception: ", e);
WXExceptionUtils.commitCriticalExceptionRT(instanceId,
WXErrorCode.WX_KEY_EXCEPTION_INVOKE, "callCreateFinish",
WXLogUtils.getStackTrace(e), null);
}

return IWXBridge.INSTANCE_RENDERING;
}

public ContentBoxMeasurement getMeasurementFunc(String instanceId, long renderObjectPtr) {
ContentBoxMeasurement contentBoxMeasurement = null;
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ int callUpdateAttrs(String instanceId, String ref,

int callCreateFinish(String instanceId);

int callRenderSuccess(String instanceId);

int callAppendTreeCreateFinish(String instanceId, String ref);

int callHasTransitionPros(String instanceId, String ref, HashMap<String, String> styles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ public void executeAction() {
if (instance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) {
instance.onCreateFinish();
}
instance.onRenderSuccess(mLayoutWidth, mLayoutHeight);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.ui.action;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.ui.component.WXComponent;

public class GraphicActionRenderSuccess extends BasicGraphicAction {

private int mLayoutWidth;
private int mLayoutHeight;

public GraphicActionRenderSuccess(String pageId) {
super(pageId, "");
final WXSDKInstance instance = WXSDKManager.getInstance()
.getWXRenderManager().getWXSDKInstance(pageId);
if (instance == null) {
return;
}
WXComponent component = instance.getRootComponent();
if (null != component) {
this.mLayoutWidth = (int) component.getLayoutWidth();
this.mLayoutHeight = (int) component.getLayoutHeight();
}
}

@Override
public void executeAction() {
final WXSDKInstance instance = WXSDKManager.getInstance()
.getWXRenderManager().getWXSDKInstance(getPageId());
if (instance == null || instance.getContext() == null) {
return;
}

instance.onRenderSuccess(mLayoutWidth, mLayoutHeight);
}

}
3 changes: 2 additions & 1 deletion weex_core/Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(COMMON_SRCS
./core/render/action/render_action_layout.cpp
./core/render/action/render_action_update_attr.cpp
./core/render/action/render_action_update_style.cpp
./core/render/action/render_action_render_success.cpp

./core/layout/layout.cpp
./core/layout/style.cpp
Expand Down Expand Up @@ -111,4 +112,4 @@ endif (ANDROID)

add_library(${WEEXCORE_LIBRARY_NAME} SHARED ${FINAL_ADD_LIBRARY})
target_include_directories(${WEEXCORE_LIBRARY_NAME} PUBLIC .)
target_link_libraries(${WEEXCORE_LIBRARY_NAME} ${FINAL_TARGET_LINK_LIBRARIES})
target_link_libraries(${WEEXCORE_LIBRARY_NAME} ${FINAL_TARGET_LINK_LIBRARIES})
26 changes: 26 additions & 0 deletions weex_core/Source/android/bridge/impl/bridge_impl_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static jmethodID jCallHasTransitionProsMethodId;
static jmethodID jCallUpdateAttrsMethodId;
static jmethodID jCallLayoutMethodId;
static jmethodID jCallCreateFinishMethodId;
static jmethodID jCallRenderSuccessMethodId;
static jmethodID jCallAppendTreeCreateFinishMethodId;
static jmethodID jCallGetMeasurementMethodId;

Expand Down Expand Up @@ -788,6 +789,31 @@ namespace WeexCore {
return flag;
}

int Bridge_Impl_Android::callRenderSuccess(const char* pageId) {

RenderPage *page = RenderManager::GetInstance()->GetPage(pageId);
int64_t startTime = getCurrentTime();

JNIEnv *env = getJNIEnv();

jstring jPageId = getKeyFromCache(env, pageId);

if (jCallRenderSuccessMethodId == NULL)
jCallRenderSuccessMethodId = env->GetMethodID(jBridgeClazz,
"callRenderSuccess",
"(Ljava/lang/String;)I");

int flag = env->CallIntMethod(jThis, jCallRenderSuccessMethodId, jPageId);

if (flag == -1) {
LOGE("instance destroy JFM must stop callRenderSuccess");
}

if (page != nullptr)
page->CallBridgeTime(getCurrentTime() - startTime);
return flag;
}

int Bridge_Impl_Android::callAppendTreeCreateFinish(const char *pageId, const char *ref) {

RenderPage *page = RenderManager::GetInstance()->GetPage(pageId);
Expand Down
2 changes: 2 additions & 0 deletions weex_core/Source/android/bridge/impl/bridge_impl_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ namespace WeexCore {

int callCreateFinish(const char* pageId);

int callRenderSuccess(const char* pageId);

int callAppendTreeCreateFinish(const char* pageId, const char* ref);

int callHasTransitionPros(const char* pageId, const char* ref,
Expand Down
2 changes: 2 additions & 0 deletions weex_core/Source/core/bridge/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ namespace WeexCore {

virtual int callCreateFinish(const char* pageId) = 0;

virtual int callRenderSuccess(const char* pageId) = 0;

virtual int callRemoveElement(const char* pageId, const char* ref) = 0;

virtual int callMoveElement(const char* pageId, const char* ref, const char* parentRef, int index) = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "core/render/action/render_action_render_success.h"
#include "core/manager/weex_core_manager.h"

namespace WeexCore {
RenderActionRenderSuccess::RenderActionRenderSuccess(const std::string& page_id)
: page_id_(page_id) {}

void RenderActionRenderSuccess::ExecuteAction() {
WeexCoreManager::getInstance()->getPlatformBridge()->callRenderSuccess(
page_id_.c_str());
}
} // namespace WeexCore
38 changes: 38 additions & 0 deletions weex_core/Source/core/render/action/render_action_render_success.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef CORE_RENDER_ACTION_RENDER_ACTION_RENDER_SUCCESS_H
#define CORE_RENDER_ACTION_RENDER_ACTION_RENDER_SUCCESS_H

#include <string>
#include "core/render/action/render_action_interface.h"

namespace WeexCore {
class RenderActionRenderSuccess : public RenderAction {
public:
explicit RenderActionRenderSuccess(const std::string &page_id);

void ExecuteAction();

public:
std::string page_id_;
};
} // namespace WeexCore

#endif // CORE_RENDER_ACTION_RENDER_ACTION_RENDER_SUCCESS_H
29 changes: 21 additions & 8 deletions weex_core/Source/core/render/page/render_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
#include "core/render/page/render_page.h"
#include "base/TimeUtils.h"
#include "base/ViewUtils.h"
#include "core/render/page/render_page.h"
#include "core/config/core_environment.h"
#include "core/css/constants_value.h"
#include "core/layout/layout.h"
Expand All @@ -33,6 +33,7 @@
#include "core/render/action/render_action_move_element.h"
#include "core/render/action/render_action_remove_element.h"
#include "core/render/action/render_action_remove_event.h"
#include "core/render/action/render_action_render_success.h"
#include "core/render/action/render_action_update_attr.h"
#include "core/render/action/render_action_update_style.h"
#include "core/render/manager/render_manager.h"
Expand Down Expand Up @@ -372,7 +373,8 @@ bool RenderPage::RemoveEvent(const std::string &ref, const std::string &event) {

render->RemoveEvent(event);

RenderAction *action = new RenderActionRemoveEvent(this->page_id_, ref, event);
RenderAction *action =
new RenderActionRemoveEvent(this->page_id_, ref, event);
PostRenderAction(action);
return true;
}
Expand All @@ -383,14 +385,22 @@ bool RenderPage::CreateFinish() {
}
Batch();
SendCreateFinishAction();
// RenderSuccess means the Dom created after executing script finishes layout
// and render, it will be trigger even though body not yet attaches to parent.
LayoutInner();
SendRenderSuccessAction();
return true;
}

void RenderPage::LayoutInner() {
CalculateLayout();
this->need_layout_.store(false);
set_is_dirty(false);
}

void RenderPage::LayoutImmediately() {
if (is_dirty() && kUseVSync) {
CalculateLayout();
this->need_layout_.store(false);
set_is_dirty(false);
LayoutInner();
}
}

Expand Down Expand Up @@ -556,6 +566,11 @@ void RenderPage::SendCreateFinishAction() {
PostRenderAction(action);
}

void RenderPage::SendRenderSuccessAction() {
RenderAction *action = new RenderActionRenderSuccess(page_id());
PostRenderAction(action);
}

void RenderPage::SendAppendTreeCreateFinish(const std::string &ref) {
RenderAction *action = new RenderActionAppendTreeCreateFinish(page_id(), ref);
PostRenderAction(action);
Expand Down Expand Up @@ -592,9 +607,7 @@ std::vector<int64_t> RenderPage::PrintRenderSuccessLog() {

void RenderPage::Batch() {
if ((kUseVSync && this->need_layout_.load()) || !kUseVSync) {
CalculateLayout();
this->need_layout_.store(false);
set_is_dirty(false);
LayoutInner();
}
}

Expand Down
8 changes: 5 additions & 3 deletions weex_core/Source/core/render/page/render_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ class RenderPage {

void SendCreateFinishAction();

void SendRenderSuccessAction();

void SendAppendTreeCreateFinish(const std::string &ref);

void PostRenderAction(RenderAction *action);

public:
void LayoutInner();

public:
explicit RenderPage(std::string page_id);

~RenderPage();
Expand Down Expand Up @@ -139,8 +142,7 @@ class RenderPage {

void OnRenderPageClose();

public:

public:
inline std::string page_id() { return this->page_id_; }

inline bool is_dirty() { return this->is_dirty_.load(); }
Expand Down

0 comments on commit 498615d

Please sign in to comment.