From a7da8ecba52f06b8397c77d0082500059112fc83 Mon Sep 17 00:00:00 2001 From: maxli Date: Tue, 14 Dec 2021 18:04:24 +0800 Subject: [PATCH] feat(android): native render provider to c dom refactor(android): adjust some class name of native render refactor(android): adjust some class name of native render refactor(android): add updateRootSize interface for provider --- .../tencent/mtt/hippy/HippyEngineContext.java | 14 -- .../mtt/hippy/HippyEngineManagerImpl.java | 82 +------- .../mtt/hippy/bridge/HippyCoreAPI.java | 7 - .../uimanager/UIManagerModule.java | 99 --------- .../android/src/main/jni/src/bridge/entry.cc | 4 +- .../hippy/support/IFrameworkProxy.java | 2 - ...ererProxy.java => INativeRenderProxy.java} | 16 +- .../tencent/mtt/hippy/common/HippyMap.java | 4 + .../widget/HippyRecyclerExtension.java | 6 +- .../widget/HippyRecyclerPool.java | 6 +- .../com/tencent/mtt/hippy/HippyRootView.java | 12 +- .../com/tencent/mtt/hippy/dom/DomManager.java | 44 ++-- .../tencent/mtt/hippy/dom/node/DomNode.java | 6 +- .../mtt/hippy/dom/node/HippyImageSpan.java | 6 +- .../dom/node/HippyNativeGestureSpan.java | 10 +- .../tencent/mtt/hippy/dom/node/TextNode.java | 8 +- .../hippy/uimanager/ControllerManager.java | 6 +- .../hippy/uimanager/ControllerRegistry.java | 6 +- .../mtt/hippy/uimanager/DiffUtils.java | 2 +- .../hippy/uimanager/HippyViewController.java | 12 +- .../mtt/hippy/uimanager/HippyViewEvent.java | 12 +- .../uimanager/NativeGestureDispatcher.java | 56 ++--- .../mtt/hippy/uimanager/RenderManager.java | 60 +++--- .../mtt/hippy/utils/HippyViewUtil.java | 10 +- .../custom/HippyCustomPropsController.java | 10 +- .../hippylist/HippyRecyclerListAdapter.java | 6 +- .../views/hippylist/HippyRecyclerView.java | 6 +- .../HippyRecyclerViewController.java | 8 +- .../hippylist/HippyRecyclerViewWrapper.java | 10 +- .../mtt/hippy/views/image/HippyImageView.java | 10 +- .../views/image/HippyImageViewController.java | 6 +- .../hippy/views/list/HippyListAdapter.java | 6 +- .../mtt/hippy/views/list/HippyListView.java | 12 +- .../hippy/views/modal/HippyModalHostView.java | 20 +- .../scroll/HippyScrollViewEventHelper.java | 10 +- .../mtt/hippy/views/text/HippyTextView.java | 16 +- .../hippy/views/textinput/HippyTextInput.java | 10 +- .../hippy/views/textinput/TextInputNode.java | 6 +- .../views/view/HippyViewGroupController.java | 4 +- .../waterfalllist/HippyWaterfallView.java | 12 +- ...NativeRenderer.java => INativeRender.java} | 12 +- .../renderer/INativeRenderDelegate.java | 33 +++ ...rContext.java => NativeRenderContext.java} | 5 +- .../renderer/NativeRenderException.java | 36 ++++ .../renderer/NativeRenderProvider.java | 150 ++++++++++++++ .../com/tencent/renderer/NativeRenderer.java | 194 ++++++------------ .../renderer/NativeRendererDelegate.java | 103 ---------- .../renderer/NativeRendererManager.java | 6 +- .../renderer/serialization/Deserializer.java | 85 +++++--- 49 files changed, 551 insertions(+), 715 deletions(-) delete mode 100644 framework/js/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/uimanager/UIManagerModule.java rename modules/hippy_support/src/main/java/com/tencent/hippy/support/{INativeRendererProxy.java => INativeRenderProxy.java} (77%) rename renderer/native/android/src/main/java/com/tencent/renderer/{INativeRenderer.java => INativeRender.java} (88%) create mode 100644 renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderDelegate.java rename renderer/native/android/src/main/java/com/tencent/renderer/{NativeRendererContext.java => NativeRenderContext.java} (88%) create mode 100644 renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderException.java create mode 100644 renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderProvider.java delete mode 100644 renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererDelegate.java diff --git a/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineContext.java b/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineContext.java index c7833070703..0f6f63285ed 100644 --- a/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineContext.java +++ b/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineContext.java @@ -56,20 +56,6 @@ public interface HippyEngineContext { void onRuntimeInitialized(long runtimeId); - void createNode(int rootId, HippyArray hippyArray); - - void updateNode(int rootId, HippyArray updateArray); - - void deleteNode(int rootId, HippyArray deleteArray); - - void callUIFunction(HippyArray hippyArray, Promise promise); - - void measureInWindow(int id, Promise promise); - - void startBatch(); - - void endBatch(); - int getEngineId(); int getRootId(); diff --git a/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java b/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java index 32202634f17..655d68708e6 100644 --- a/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java +++ b/framework/js/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java @@ -20,11 +20,10 @@ import android.os.Looper; import android.os.Message; import android.text.TextUtils; - import android.view.ViewGroup; import com.tencent.hippy.support.HippyBaseController; import com.tencent.hippy.support.IJSFrameworkProxy; -import com.tencent.hippy.support.INativeRendererProxy; +import com.tencent.hippy.support.INativeRenderProxy; import com.tencent.mtt.hippy.adapter.device.HippyDeviceAdapter; import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.dom.DomManager; @@ -59,7 +58,6 @@ import java.io.InputStream; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; @SuppressWarnings({"deprecation", "unused"}) @@ -285,24 +283,6 @@ public String getBundlePath() { return null; } - @Override - public void onSizeChanged(int w, int h, int oldw, int oldh) { - if (mEngineContext == null) { - return; - } - - HippyModuleManager moduleManager = mEngineContext.getModuleManager(); - if (moduleManager != null) { - HippyMap hippyMap = new HippyMap(); - hippyMap.pushDouble("width", PixelUtil.px2dp(w)); - hippyMap.pushDouble("height", PixelUtil.px2dp(h)); - hippyMap.pushDouble("oldWidth", PixelUtil.px2dp(oldw)); - hippyMap.pushDouble("oldHeight", PixelUtil.px2dp(oldh)); - moduleManager.getJavaScriptModule(EventDispatcher.class) - .receiveNativeEvent("onSizeChanged", hippyMap); - } - } - @Override public void dispatchUIComponentEvent(int id, String eventName, Object params) { if (mEngineContext.getModuleManager().getJavaScriptModule(EventDispatcher.class) != null) { @@ -642,8 +622,6 @@ private void internalLoadInstance(ModuleLoadParams loadParams) { } int rootId = rootView.getId(); - mEngineContext.onInstanceLoad(); - HippyMap launchParams = loadParams.jsParams; if (!mDebugMode) { if (jsBundleLoader != null) { @@ -730,7 +708,7 @@ public class HippyEngineContextImpl implements HippyEngineContext, HippyInstance private String componentName; private final HippyModuleManager mModuleManager; private final HippyBridgeManager mBridgeManager; - private INativeRendererProxy nativeRendererProxy; + private INativeRenderProxy nativeRendererProxy; volatile CopyOnWriteArrayList mEngineLifecycleEventListeners; public HippyEngineContextImpl() @@ -741,7 +719,7 @@ public HippyEngineContextImpl() mServerHost, mGroupId, mThirdPartyAdapter, v8InitParams); try { Class nativeRendererClass = Class.forName("com.tencent.renderer.NativeRenderer"); - nativeRendererProxy = (INativeRendererProxy)(nativeRendererClass.newInstance()); + nativeRendererProxy = (INativeRenderProxy)(nativeRendererClass.newInstance()); List> controllers = null; for (HippyAPIProvider hippyPackage : mAPIProviders) { if (controllers == null) { @@ -837,9 +815,7 @@ public void removeEngineLifecycleEventListener(HippyEngineLifecycleEventListener @Override public void onInstanceLoad() { - if (nativeRendererProxy != null) { - nativeRendererProxy.onInstanceLoad(); - } + } @Override @@ -908,57 +884,7 @@ public ViewGroup getRootView() { return rootView; } - @Override - public void createNode(int rootId, HippyArray hippyArray) { - if (nativeRendererProxy != null) { - nativeRendererProxy.createNode(rootId, hippyArray); - } - } - - @Override - public void updateNode(int rootId, HippyArray updateArray) { - if (nativeRendererProxy != null) { - nativeRendererProxy.updateNode(rootId, updateArray); - } - } - - @Override - public void deleteNode(int rootId, HippyArray deleteArray) { - if (nativeRendererProxy != null) { - nativeRendererProxy.deleteNode(rootId, deleteArray); - } - } - - @Override - public void callUIFunction(HippyArray hippyArray, Promise promise) { - if (nativeRendererProxy != null) { - nativeRendererProxy.callUIFunction(hippyArray, promise); - } - } - - @Override - public void measureInWindow(int id, Promise promise) { - if (nativeRendererProxy != null) { - nativeRendererProxy.measureInWindow(id, promise); - } - } - - @Override - public void startBatch() { - if (nativeRendererProxy != null) { - nativeRendererProxy.startBatch(); - } - } - - @Override - public void endBatch() { - if (nativeRendererProxy != null) { - nativeRendererProxy.endBatch(); - } - } - public ViewGroup createRootView(Context context) { - assert nativeRendererProxy != null; rootView = nativeRendererProxy.createRootView(context); return rootView; } diff --git a/framework/js/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyCoreAPI.java b/framework/js/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyCoreAPI.java index dafc32758ca..f78d703275d 100644 --- a/framework/js/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyCoreAPI.java +++ b/framework/js/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyCoreAPI.java @@ -37,7 +37,6 @@ import com.tencent.mtt.hippy.modules.nativemodules.network.WebSocketModule; import com.tencent.mtt.hippy.modules.nativemodules.storage.StorageModule; import com.tencent.mtt.hippy.modules.nativemodules.timer.TimerModule; -import com.tencent.mtt.hippy.modules.nativemodules.uimanager.UIManagerModule; import com.tencent.mtt.hippy.modules.nativemodules.utils.UtilsModule; import com.tencent.mtt.hippy.uimanager.HippyViewController; import com.tencent.mtt.hippy.utils.LogUtils; @@ -91,12 +90,6 @@ public HippyNativeModuleBase get() { return new ExceptionModule(context); } }); - modules.put(UIManagerModule.class, new Provider() { - @Override - public HippyNativeModuleBase get() { - return new UIManagerModule(context); - } - }); modules.put(AnimationModule.class, new Provider() { @Override public HippyNativeModuleBase get() { diff --git a/framework/js/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/uimanager/UIManagerModule.java b/framework/js/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/uimanager/UIManagerModule.java deleted file mode 100644 index 2e26fb91a77..00000000000 --- a/framework/js/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/uimanager/UIManagerModule.java +++ /dev/null @@ -1,99 +0,0 @@ -/* Tencent is pleased to support the open source community by making Hippy available. - * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed 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.tencent.mtt.hippy.modules.nativemodules.uimanager; - -import com.tencent.mtt.hippy.HippyEngineContext; -import com.tencent.mtt.hippy.annotation.HippyMethod; -import com.tencent.mtt.hippy.annotation.HippyNativeModule; -import com.tencent.mtt.hippy.common.HippyArray; -import com.tencent.mtt.hippy.common.HippyMap; -import com.tencent.mtt.hippy.modules.Promise; -import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase; - -@SuppressWarnings({"deprecation", "unused"}) -@HippyNativeModule(name = UIManagerModule.CLASS_NAME, thread = HippyNativeModule.Thread.DOM) -public class UIManagerModule extends HippyNativeModuleBase { - - public static final String CLASS_NAME = "UIManagerModule"; - - final String OPTION_TYPE = "optionType"; - final String OPTION_TYPE_CREATE_NODE = "createNode"; - final String OPTION_TYPE_UPDATE_NODE = "updateNode"; - final String OPTION_TYPE_DELETE_NODE = "deleteNode"; - final String OPTION_TYPE_PARAM = "param"; - - public UIManagerModule(HippyEngineContext context) { - super(context); - } - - @HippyMethod(name = "createNode") - public void createNode(int rootId, HippyArray hippyArray) { - mContext.createNode(rootId, hippyArray); - } - - - @HippyMethod(name = "updateNode") - public void updateNode(int rootId, HippyArray updateArray) { - mContext.updateNode(rootId, updateArray); - } - - @HippyMethod(name = "deleteNode") - public void deleteNode(int rootId, HippyArray deleteArray) { - mContext.deleteNode(rootId, deleteArray); - } - - @HippyMethod(name = "flushBatch") - public void flushBatch(int rootId, HippyArray hippyArray) { - if (hippyArray != null && hippyArray.size() > 0) { - int len = hippyArray.size(); - for (int i = 0; i < len; i++) { - HippyMap hippyMap = hippyArray.getMap(i); - String optionType = (String) hippyMap.get(OPTION_TYPE); - switch (optionType) { - case OPTION_TYPE_CREATE_NODE: - createNode(rootId, (HippyArray) hippyMap.get(OPTION_TYPE_PARAM)); - break; - case OPTION_TYPE_UPDATE_NODE: - updateNode(rootId, (HippyArray) hippyMap.get(OPTION_TYPE_PARAM)); - break; - case OPTION_TYPE_DELETE_NODE: - deleteNode(rootId, (HippyArray) hippyMap.get(OPTION_TYPE_PARAM)); - break; - } - } - } - } - - @HippyMethod(name = "callUIFunction") - public void callUIFunction(HippyArray hippyArray, Promise promise) { - mContext.callUIFunction(hippyArray, promise); - } - - @HippyMethod(name = "measureInWindow") - public void measureInWindow(int id, Promise promise) { - mContext.measureInWindow(id, promise); - } - - @HippyMethod(name = "startBatch") - public void startBatch() { - mContext.startBatch(); - } - - @HippyMethod(name = "endBatch") - public void endBatch() { - mContext.endBatch(); - } -} diff --git a/framework/js/android/src/main/jni/src/bridge/entry.cc b/framework/js/android/src/main/jni/src/bridge/entry.cc index 0008072c0e2..0665c21361a 100644 --- a/framework/js/android/src/main/jni/src/bridge/entry.cc +++ b/framework/js/android/src/main/jni/src/bridge/entry.cc @@ -74,8 +74,8 @@ REGISTER_JNI("com/tencent/mtt/hippy/bridge/HippyBridgeImpl", // NOLINT(cert-err5 "(JZLcom/tencent/mtt/hippy/bridge/NativeCallback;)V", DestroyInstance) -REGISTER_JNI("com/tencent/renderer/NativeRendererDelegate", - "onCreateNativeRendererDelegate", +REGISTER_JNI("com/tencent/renderer/NativeRenderProvider", + "onCreateNativeRenderProvider", "(J)V", CreateNativeRenderDelegate) diff --git a/modules/hippy_support/src/main/java/com/tencent/hippy/support/IFrameworkProxy.java b/modules/hippy_support/src/main/java/com/tencent/hippy/support/IFrameworkProxy.java index 6a720bccbd3..6a2d751211a 100644 --- a/modules/hippy_support/src/main/java/com/tencent/hippy/support/IFrameworkProxy.java +++ b/modules/hippy_support/src/main/java/com/tencent/hippy/support/IFrameworkProxy.java @@ -18,7 +18,5 @@ public interface IFrameworkProxy { void onFirstViewAdded(); - void onSizeChanged(int w, int h, int oldw, int oldh); - void handleNativeException(Exception exception, boolean haveCaught); } diff --git a/modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRendererProxy.java b/modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRenderProxy.java similarity index 77% rename from modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRendererProxy.java rename to modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRenderProxy.java index 123b0e7c32a..b368b8c8dbb 100644 --- a/modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRendererProxy.java +++ b/modules/hippy_support/src/main/java/com/tencent/hippy/support/INativeRenderProxy.java @@ -23,7 +23,7 @@ import java.util.List; -public interface INativeRendererProxy extends HippyInstanceLifecycleEventListener { +public interface INativeRenderProxy extends HippyInstanceLifecycleEventListener { void init(int instanceId, List> controllers, boolean isDebugMode, ViewGroup rootView); @@ -40,18 +40,4 @@ void init(int instanceId, List> controllers Object getDomManagerObject(); Object getRenderManagerObject(); - - void createNode(int rootId, HippyArray hippyArray); - - void updateNode(int rootId, HippyArray updateArray); - - void deleteNode(int rootId, HippyArray deleteArray); - - void callUIFunction(HippyArray hippyArray, Promise promise); - - void measureInWindow(int id, Promise promise); - - void startBatch(); - - void endBatch(); } diff --git a/modules/hippy_support/src/main/java/com/tencent/mtt/hippy/common/HippyMap.java b/modules/hippy_support/src/main/java/com/tencent/mtt/hippy/common/HippyMap.java index 803b42385e3..bf427e97d6f 100644 --- a/modules/hippy_support/src/main/java/com/tencent/mtt/hippy/common/HippyMap.java +++ b/modules/hippy_support/src/main/java/com/tencent/mtt/hippy/common/HippyMap.java @@ -38,6 +38,10 @@ public HippyMap() { mDatas = new HashMap<>(); } + public HippyMap(HashMap map) { + mDatas = map; + } + public HashMap getInternalMap() { return mDatas; } diff --git a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerExtension.java b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerExtension.java index ebdd24dc2f4..78c420c58ff 100644 --- a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerExtension.java +++ b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerExtension.java @@ -23,17 +23,17 @@ import com.tencent.mtt.hippy.uimanager.RenderNode; import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewHolder; import com.tencent.mtt.hippy.views.hippylist.NodePositionHelper; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.util.ArrayList; public class HippyRecyclerExtension extends RecyclerView.ViewCacheExtension { - private final INativeRenderer hpContext; + private final INativeRender hpContext; private final NodePositionHelper nodePositionHelper; private HippyRecyclerViewBase recyclerView; private int currentPosition; - public HippyRecyclerExtension(HippyRecyclerViewBase recyclerView, INativeRenderer hpContext, + public HippyRecyclerExtension(HippyRecyclerViewBase recyclerView, INativeRender hpContext, NodePositionHelper nodePositionHelper) { this.nodePositionHelper = nodePositionHelper; this.recyclerView = recyclerView; diff --git a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerPool.java b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerPool.java index e80828d5bee..49b646b63b3 100644 --- a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerPool.java +++ b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyRecyclerPool.java @@ -22,17 +22,17 @@ import com.tencent.mtt.hippy.uimanager.RenderNode; import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewHolder; import com.tencent.mtt.hippy.views.hippylist.NodePositionHelper; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; public class HippyRecyclerPool extends RecyclerView.RecycledViewPool { private final View recyclerView; private final HippyRecyclerExtension viewCacheExtension; - private final INativeRenderer hpContext; + private final INativeRender hpContext; private final NodePositionHelper nodePositionHelper; private IHippyViewAboundListener viewAboundListener; - public HippyRecyclerPool(INativeRenderer hpContext, View recyclerView, + public HippyRecyclerPool(INativeRender hpContext, View recyclerView, HippyRecyclerExtension viewCacheExtension, NodePositionHelper nodePositionHelper) { this.nodePositionHelper = nodePositionHelper; this.hpContext = hpContext; diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java index 3a7fc91b5c1..51874ef82e5 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java @@ -32,8 +32,8 @@ import com.tencent.mtt.hippy.utils.DimensionsUtil; import com.tencent.mtt.hippy.utils.LogUtils; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; @@ -47,7 +47,7 @@ public class HippyRootView extends FrameLayout { protected boolean firstViewAdded = false; public HippyRootView(Context context, int instanceId, int rootId) { - super(new NativeRendererContext(context, instanceId)); + super(new NativeRenderContext(context, instanceId)); this.instanceId = instanceId; setId(rootId); @@ -62,7 +62,7 @@ public void onViewAdded(View child) { if (!firstViewAdded) { firstViewAdded = true; - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.onFirstViewAdded(); } @@ -92,7 +92,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { if (w != oldw || h != oldh) { getGlobalLayoutListener().checkUpdateDimension(w, h, false, false); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.onSizeChanged(w, h, oldw, oldh); } @@ -207,7 +207,7 @@ private void checkUpdateDimension(int windowWidth, int windowHeight, } boolean shouldRevise = (windowHeight < 0 || dimensionW == dimensionH) ? true : false; - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.updateDimension(shouldRevise, dimensionMap, shouldUseScreenDisplay, systemUiVisibilityChanged); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/DomManager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/DomManager.java index 168a81de0a9..67386fe3f1c 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/DomManager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/DomManager.java @@ -32,7 +32,7 @@ import com.tencent.mtt.hippy.utils.PixelUtil; import com.tencent.mtt.hippy.utils.UIThreadUtils; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Iterator; @@ -56,12 +56,12 @@ public class DomManager { final RenderManager mRenderManager; volatile CopyOnWriteArrayList mActionInterceptors; final LayoutHelper mLayoutHelper; - private final WeakReference nativeRendererWeakReference; + private final WeakReference nativeRendererWeakReference; private volatile boolean mIsDestroyed = false; private volatile boolean mEnginePaused = false; private BatchListener mBatchListener; - public DomManager(INativeRenderer context) { + public DomManager(INativeRender context) { nativeRendererWeakReference = new WeakReference<>(context); mNodeRegistry = new DomNodeRegistry(); @@ -294,14 +294,14 @@ public void exec() { } } - addUITask(new IDomExecutor() { - @Override - public void exec() { - mRenderManager - .createNode(hippyRootView, id, nativeParentNode.getId(), childIndex.mIndex, - className, newProps); - } - }); +// addUITask(new IDomExecutor() { +// @Override +// public void exec() { +// mRenderManager +// .createNode(hippyRootView, id, nativeParentNode.getId(), childIndex.mIndex, +// className, newProps); +// } +// }); } } else { LogUtils.d("DomManager", "Create Node DomManager Parent IS Null"); @@ -420,17 +420,17 @@ private void changeJustLayout2View(final DomNode node, final HippyMap hippyMap, final ViewIndex viewIndex = findNativeViewIndex(reallyParent, node, 0); - if (!node.isVirtual()) { - addUITask(new IDomExecutor() { - @Override - public void exec() { - mRenderManager - .createNode(hippyRootView, node.getId(), reallyParent.getId(), viewIndex.mIndex, - node.getViewClass(), - hippyMap); - } - }); - } +// if (!node.isVirtual()) { +// addUITask(new IDomExecutor() { +// @Override +// public void exec() { +// mRenderManager +// .createNode(hippyRootView, node.getId(), reallyParent.getId(), viewIndex.mIndex, +// node.getViewClass(), +// hippyMap); +// } +// }); +// } //step2: move child final ArrayList moveIds = new ArrayList<>(); node.markUpdated(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/DomNode.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/DomNode.java index 45835e81d0f..11f6df54b23 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/DomNode.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/DomNode.java @@ -16,7 +16,7 @@ package com.tencent.mtt.hippy.dom.node; import com.tencent.mtt.hippy.common.HippyMap; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import com.tencent.smtt.flexbox.FlexNode; @SuppressWarnings("deprecation") @@ -192,10 +192,10 @@ public boolean isJustLayout() { } - public void layoutBefore(INativeRenderer nativeRenderer) { + public void layoutBefore(INativeRender nativeRenderer) { } - public void layoutAfter(INativeRenderer nativeRenderer) { + public void layoutAfter(INativeRender nativeRenderer) { } public final int getId() { diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyImageSpan.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyImageSpan.java index c4ea92bd996..5401ca74287 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyImageSpan.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyImageSpan.java @@ -39,7 +39,7 @@ import com.tencent.mtt.hippy.views.image.HippyImageView.ImageEvent; import com.tencent.mtt.supportui.adapters.image.IDrawableTarget; import com.tencent.mtt.supportui.adapters.image.IImageLoaderAdapter; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.lang.ref.WeakReference; import java.lang.reflect.Field; @@ -59,13 +59,13 @@ public class HippyImageSpan extends ImageSpan { private int mImageLoadState = STATE_UNLOAD; private int mVerticalAlignment; private final IImageLoaderAdapter mImageAdapter; - private final INativeRenderer nativeRenderer; + private final INativeRender nativeRenderer; private Movie mGifMovie = null; private int mGifProgress = 0; private long mGifLastPlayTime = -1; public HippyImageSpan(Drawable d, String source, ImageNode node, - IImageLoaderAdapter imageAdapter, INativeRenderer nativeRenderer) { + IImageLoaderAdapter imageAdapter, INativeRender nativeRenderer) { super(d, source, node.getVerticalAlignment()); this.nativeRenderer = nativeRenderer; mImageNodeWeakRefrence = new WeakReference<>(node); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyNativeGestureSpan.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyNativeGestureSpan.java index f23f62b7e78..c3be4dbf21a 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyNativeGestureSpan.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/HippyNativeGestureSpan.java @@ -25,8 +25,8 @@ import android.view.ViewConfiguration; import com.tencent.mtt.hippy.uimanager.NativeGestureDispatcher; import com.tencent.mtt.hippy.uimanager.NativeGestureProcessor; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.util.ArrayList; @@ -46,7 +46,7 @@ public class HippyNativeGestureSpan implements NativeGestureProcessor.Callback { private NativeGestureProcessor mGestureProcessor; private Handler mHandler; - private INativeRenderer nativeRenderer; + private INativeRender nativeRenderer; private final boolean mIsVirtual; @@ -77,8 +77,8 @@ public boolean handleTouchEvent(View view, MotionEvent event) { public boolean handleDispatchTouchEvent(View view, MotionEvent event) { if (nativeRenderer == null) { final Context context = view.getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); } } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java index d11d32a7e67..ba6ee6c8cbe 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java @@ -39,7 +39,7 @@ import com.tencent.mtt.supportui.adapters.image.IDrawableTarget; import com.tencent.mtt.supportui.adapters.image.IImageLoaderAdapter; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -400,11 +400,11 @@ public void setNumberOfLines(int numberOfLines) { } protected HippyFontScaleAdapter mFontScaleAdapter; - protected INativeRenderer nativeRenderer; + protected INativeRender nativeRenderer; protected IImageLoaderAdapter mImageAdapter; @Override - public void layoutBefore(INativeRenderer nativeRenderer) { + public void layoutBefore(INativeRender nativeRenderer) { super.layoutBefore(nativeRenderer); this.nativeRenderer = nativeRenderer; @@ -614,7 +614,7 @@ public long measure(FlexNodeAPI node, float width, } }; - public void layoutAfter(INativeRenderer nativeRenderer) { + public void layoutAfter(INativeRender nativeRenderer) { if (!isVirtual() && nativeRenderer != null) { LogUtils.d("TextNode", "measure:layoutAfter" + " w: " + getLayoutWidth() + " h: " + getLayoutHeight()); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java index fd8c0e450c4..2a1e120cad3 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java @@ -39,19 +39,19 @@ import com.tencent.mtt.hippy.views.scroll.HippyHorizontalScrollView; import com.tencent.mtt.hippy.views.view.HippyViewGroupController; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.lang.reflect.Field; import java.util.List; @SuppressWarnings({"deprecation", "unchecked", "rawtypes", "unused"}) public class ControllerManager { - final INativeRenderer nativeRenderer; + final INativeRender nativeRenderer; final ControllerRegistry mControllerRegistry; final ControllerUpdateManger mControllerUpdateManger; final SparseArray mPreCacheView = new SparseArray<>(); - public ControllerManager(INativeRenderer nativeRenderer, List> controllers) { + public ControllerManager(INativeRender nativeRenderer, List> controllers) { this.nativeRenderer = nativeRenderer; mControllerRegistry = new ControllerRegistry(nativeRenderer); mControllerUpdateManger = new ControllerUpdateManger(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java index 35838648213..b960ed07c0f 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java @@ -18,7 +18,7 @@ import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.util.HashMap; import java.util.Map; @@ -27,9 +27,9 @@ public class ControllerRegistry { private final SparseArray mViews; // store all views here private final SparseArray mRoots; // store all root views here private final Map mControllers; // store all viewManager instance here - final INativeRenderer nativeRenderer; + final INativeRender nativeRenderer; - public ControllerRegistry(INativeRenderer nativeRenderer) { + public ControllerRegistry(INativeRender nativeRenderer) { mViews = new SparseArray<>(); mRoots = new SparseArray<>(); mControllers = new HashMap<>(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/DiffUtils.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/DiffUtils.java index 868c678b67f..bb141b0049c 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/DiffUtils.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/DiffUtils.java @@ -22,7 +22,7 @@ import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.utils.LogUtils; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.util.ArrayList; import java.util.List; import java.util.Set; diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java index e202f50009f..8c1b718498e 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java @@ -38,8 +38,8 @@ import com.tencent.mtt.supportui.views.IGradient; import com.tencent.mtt.supportui.views.IShadow; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.io.File; import java.util.ArrayList; @@ -57,7 +57,7 @@ public abstract class HippyViewController extend private boolean bUserChageFocus = false; @SuppressWarnings("deprecation") - public View createView(ViewGroup rootView, int id, INativeRenderer nativeRenderer, + public View createView(ViewGroup rootView, int id, INativeRender nativeRenderer, String className, HippyMap initialProps) { View view = null; @@ -698,9 +698,9 @@ public View getChildAt(T viewGroup, int i) { return null; } - protected String getInnerPath(NativeRendererContext context, String path) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + protected String getInnerPath(NativeRenderContext context, String path) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); //hpfile://./assets/file_banner02.jpg if (path != null && path.startsWith("hpfile://")) { diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewEvent.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewEvent.java index c8061a3c020..9c7e021a81d 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewEvent.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewEvent.java @@ -17,8 +17,8 @@ import android.view.View; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; public class HippyViewEvent { @@ -30,14 +30,14 @@ public HippyViewEvent(String eventName) { } public void send(View view, Object param) { - if (view != null && view.getContext() instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)view.getContext()).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (view != null && view.getContext() instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)view.getContext()).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); send(view.getId(), nativeRenderer, param); } } - public void send(int id, INativeRenderer nativeRenderer, Object param) { + public void send(int id, INativeRender nativeRenderer, Object param) { if (nativeRenderer != null) { nativeRenderer.dispatchUIComponentEvent(id, mEventName, param); } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/NativeGestureDispatcher.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/NativeGestureDispatcher.java index 47133c62143..0ac1e4af003 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/NativeGestureDispatcher.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/NativeGestureDispatcher.java @@ -24,8 +24,8 @@ import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.utils.LogUtils; import com.tencent.mtt.hippy.utils.PixelUtil; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.util.HashSet; @@ -48,13 +48,13 @@ public void onClick(final View view) { } final Context context = view.getContext(); - if (context instanceof NativeRendererContext) { + if (context instanceof NativeRenderContext) { view.postDelayed(new Runnable() { @Override public void run() { int tagId = view.getId(); - int instanceId = ((NativeRendererContext) context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + int instanceId = ((NativeRenderContext) context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); handleClick(view, nativeRenderer, tagId, false); } }, TAP_TIMEOUT); @@ -70,13 +70,13 @@ public boolean onLongClick(final View view) { } final Context context = view.getContext(); - if (context instanceof NativeRendererContext) { + if (context instanceof NativeRenderContext) { view.postDelayed(new Runnable() { @Override public void run() { int tagId = view.getId(); - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); handleLongClick(nativeRenderer, tagId); } }, TAP_TIMEOUT); @@ -94,10 +94,10 @@ public void onViewAttachedToWindow(View view) { } final Context context = view.getContext(); - if (context instanceof NativeRendererContext) { + if (context instanceof NativeRenderContext) { int tagId = view.getId(); - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); handleAttachedToWindow(nativeRenderer, tagId); } } @@ -122,10 +122,10 @@ public void onViewDetachedFromWindow(View view) { } final Context context = view.getContext(); - if (context instanceof NativeRendererContext) { + if (context instanceof NativeRenderContext) { int tagId = view.getId(); - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); handleDetachedFromWindow(nativeRenderer, tagId); } } @@ -134,12 +134,12 @@ public void onViewDetachedFromWindow(View view) { private final View mTargetView; private HashSet mGestureTypes = null; private NativeGestureProcessor mGestureProcessor; - private INativeRenderer nativeRenderer; + private INativeRender nativeRenderer; public NativeGestureDispatcher(View view) { mTargetView = view; - if (view != null && view.getContext() instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)view.getContext()).getInstanceId(); + if (view != null && view.getContext() instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)view.getContext()).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); } } @@ -160,7 +160,7 @@ public static View.OnAttachStateChangeListener getOnDetachedFromWindowListener() return mOnDetachedFromWindowListener; } - public static void handleClick(View target, INativeRenderer nativeRenderer, int tagId, + public static void handleClick(View target, INativeRender nativeRenderer, int tagId, boolean isCustomEvent) { if (nativeRenderer != null) { HippyMap params = new HippyMap(); @@ -170,7 +170,7 @@ public static void handleClick(View target, INativeRenderer nativeRenderer, int } } - public static void handleLongClick(INativeRenderer nativeRenderer, int tagId) { + public static void handleLongClick(INativeRender nativeRenderer, int tagId) { if (nativeRenderer != null) { HippyMap params = new HippyMap(); params.pushString(KEY_EVENT_NAME, NodeProps.ON_LONG_CLICK); @@ -179,19 +179,19 @@ public static void handleLongClick(INativeRenderer nativeRenderer, int tagId) { } } - public static void handleAttachedToWindow(INativeRenderer nativeRenderer, int tagId) { + public static void handleAttachedToWindow(INativeRender nativeRenderer, int tagId) { if (nativeRenderer != null) { nativeRenderer.dispatchUIComponentEvent(tagId, NodeProps.ON_ATTACHED_TO_WINDOW, null); } } - public static void handleDetachedFromWindow(INativeRenderer nativeRenderer, int tagId) { + public static void handleDetachedFromWindow(INativeRender nativeRenderer, int tagId) { if (nativeRenderer != null) { nativeRenderer.dispatchUIComponentEvent(tagId, NodeProps.ON_DETACHED_FROM_WINDOW, null); } } - public static void handlePressIn(INativeRenderer nativeRenderer, int tagId) { + public static void handlePressIn(INativeRender nativeRenderer, int tagId) { if (nativeRenderer != null) { HippyMap params = new HippyMap(); params.pushString(KEY_EVENT_NAME, NodeProps.ON_PRESS_IN); @@ -200,7 +200,7 @@ public static void handlePressIn(INativeRenderer nativeRenderer, int tagId) { } } - public static void handlePressOut(INativeRenderer nativeRenderer, int tagId) { + public static void handlePressOut(INativeRender nativeRenderer, int tagId) { if (nativeRenderer != null) { HippyMap params = new HippyMap(); params.pushString(KEY_EVENT_NAME, NodeProps.ON_PRESS_OUT); @@ -209,7 +209,7 @@ public static void handlePressOut(INativeRenderer nativeRenderer, int tagId) { } } - public static void handleTouchDown(INativeRenderer nativeRenderer, int mTagId, float x, float y, + public static void handleTouchDown(INativeRender nativeRenderer, int mTagId, float x, float y, int viewId) { if (nativeRenderer != null) { int[] viewCoords = new int[2]; @@ -223,7 +223,7 @@ public static void handleTouchDown(INativeRenderer nativeRenderer, int mTagId, f } } - public static void handleTouchMove(INativeRenderer nativeRenderer, int mTagId, float x, float y, + public static void handleTouchMove(INativeRender nativeRenderer, int mTagId, float x, float y, int viewId) { if (nativeRenderer != null) { int[] viewCoords = new int[2]; @@ -237,7 +237,7 @@ public static void handleTouchMove(INativeRenderer nativeRenderer, int mTagId, f } } - public static void handleTouchEnd(INativeRenderer nativeRenderer, int mTagId, float x, float y, + public static void handleTouchEnd(INativeRender nativeRenderer, int mTagId, float x, float y, int viewId) { if (nativeRenderer != null) { int[] viewCoords = new int[2]; @@ -251,7 +251,7 @@ public static void handleTouchEnd(INativeRenderer nativeRenderer, int mTagId, fl } } - public static void handleTouchCancel(INativeRenderer nativeRenderer, int mTagId, float x, float y, + public static void handleTouchCancel(INativeRender nativeRenderer, int mTagId, float x, float y, int viewId) { if (nativeRenderer != null) { int[] viewCoords = new int[2]; @@ -265,7 +265,7 @@ public static void handleTouchCancel(INativeRenderer nativeRenderer, int mTagId, } } - private static void getLocationInWindow(INativeRenderer nativeRenderer, int id, int[] viewCoords) { + private static void getLocationInWindow(INativeRender nativeRenderer, int id, int[] viewCoords) { if (id >= 0) { View view = nativeRenderer.getRenderManager().getControllerManager().findView(id); if (view != null) { diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java index 735bd35097f..cd98572c6c2 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java @@ -15,22 +15,24 @@ */ package com.tencent.mtt.hippy.uimanager; +import static com.tencent.renderer.NativeRenderException.INVALID_NODE_DATA_ERR; + +import com.tencent.mtt.hippy.views.modal.HippyModalHostManager; +import com.tencent.renderer.NativeRenderException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import android.text.TextUtils; import android.util.SparseArray; - import android.view.ViewGroup; import com.tencent.hippy.support.HippyBaseController; -import com.tencent.mtt.hippy.HippyRootView; import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.common.HippyMap; import com.tencent.mtt.hippy.dom.node.DomNode; import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.modules.Promise; import com.tencent.mtt.hippy.utils.LogUtils; - -import com.tencent.renderer.INativeRenderer; -import java.util.ArrayList; -import java.util.List; +import com.tencent.renderer.INativeRender; @SuppressWarnings({"deprecation", "unused"}) public class RenderManager { @@ -45,7 +47,7 @@ public class RenderManager { final ControllerManager mControllerManager; - public RenderManager(INativeRenderer nativeRenderer, List> controllers) { + public RenderManager(INativeRender nativeRenderer, List> controllers) { mControllerManager = new ControllerManager(nativeRenderer, controllers); } @@ -66,40 +68,34 @@ public void destroy() { getControllerManager().destroy(); } - public void createNode(ViewGroup hippyRootView, int id, int pId, int childIndex, - String className, HippyMap props) { - LogUtils.d("RenderManager", - "createNode ID " + id + " mParentId " + pId + " index " + childIndex + "className" - + className); - - RenderNode parentNode = mNodes.get(pId); - + public void createNode(ViewGroup rootView, int id, int pid, int index, + String className, HashMap props) { + HippyMap localProps = new HippyMap(props); boolean isLazy = mControllerManager.isControllerLazy(className); - RenderNode uiNode = mControllerManager - .createRenderNode(id, props, className, hippyRootView, isLazy || parentNode.mIsLazyLoad); - - mNodes.put(id, uiNode); + RenderNode parentNode = mNodes.get(pid); + if (parentNode == null) { + throw new NativeRenderException(INVALID_NODE_DATA_ERR, + "parentNode is null: " + "id=" + id + ", pId=" + pid); + } + RenderNode node = mControllerManager.createRenderNode(id, localProps, className, + rootView, isLazy || parentNode.mIsLazyLoad); + mNodes.put(id, node); mPreIsLazy.remove(id); - - parentNode.addChild(uiNode, childIndex); - + parentNode.addChild(node, index); addUpdateNodeIfNeeded(parentNode); - - addUpdateNodeIfNeeded(uiNode); + addUpdateNodeIfNeeded(node); } - public void addUpdateNodeIfNeeded(RenderNode renderNode) { - if (!mUIUpdateNodes.contains(renderNode)) { - if (null != renderNode) { - mUIUpdateNodes.add(renderNode); - } + public void addUpdateNodeIfNeeded(RenderNode node) { + if (!mUIUpdateNodes.contains(node)) { + mUIUpdateNodes.add(node); } } - void addNullUINodeIfNeeded(RenderNode renderNode) { - if (!mNullUIUpdateNodes.contains(renderNode)) { - mNullUIUpdateNodes.add(renderNode); + void addNullUINodeIfNeeded(RenderNode node) { + if (!mNullUIUpdateNodes.contains(node)) { + mNullUIUpdateNodes.add(node); } } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/utils/HippyViewUtil.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/utils/HippyViewUtil.java index f9e1a4edcaf..8e6281a7edb 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/utils/HippyViewUtil.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/utils/HippyViewUtil.java @@ -20,16 +20,16 @@ import com.tencent.mtt.hippy.uimanager.RenderNode; import com.tencent.mtt.supportui.views.recyclerview.RecyclerViewItem; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; public class HippyViewUtil { public static RenderNode getRenderNode(View view) { Context context = view.getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)view.getContext()).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)view.getContext()).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); //noinspection ConstantConditions if (nativeRenderer != null) { return nativeRenderer.getRenderManager().getRenderNode(getNodeId(view)); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/custom/HippyCustomPropsController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/custom/HippyCustomPropsController.java index 5d29c94a27c..d4825766ada 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/custom/HippyCustomPropsController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/custom/HippyCustomPropsController.java @@ -18,8 +18,8 @@ import com.tencent.mtt.hippy.annotation.HippyController; import com.tencent.mtt.hippy.uimanager.HippyViewController; import com.tencent.mtt.hippy.uimanager.RenderNode; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import android.content.Context; @@ -45,9 +45,9 @@ protected void onSetDTElementBizLeafIdentifier(View view) { } Context context = view.getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)view.getContext()).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)view.getContext()).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); //noinspection ConstantConditions if (nativeRenderer == null) { return; diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java index 834d28f98b6..0058df7cf00 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java @@ -34,14 +34,14 @@ import com.tencent.mtt.hippy.views.list.IRecycleItemTypeChange; import com.tencent.mtt.hippy.views.refresh.HippyPullHeaderView; import com.tencent.mtt.nxeasy.recyclerview.helper.skikcy.IStickyItemsProvider; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.util.ArrayList; public class HippyRecyclerListAdapter extends Adapter implements IRecycleItemTypeChange, IStickyItemsProvider, IItemLayoutParams { - protected final INativeRenderer hpContext; + protected final INativeRender hpContext; protected final HRCV hippyRecyclerView; protected final HippyItemTypeHelper hippyItemTypeHelper; protected int positionToCreateHolder; @@ -49,7 +49,7 @@ public class HippyRecyclerListAdapter extends protected PullHeaderEventHelper headerEventHelper; protected PreloadHelper preloadHelper; - public HippyRecyclerListAdapter(HRCV hippyRecyclerView, INativeRenderer hpContext) { + public HippyRecyclerListAdapter(HRCV hippyRecyclerView, INativeRender hpContext) { this.hpContext = hpContext; this.hippyRecyclerView = hippyRecyclerView; hippyItemTypeHelper = new HippyItemTypeHelper(hippyRecyclerView); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java index b3dafa1fcb8..34f4ac00ac0 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java @@ -32,12 +32,12 @@ import com.tencent.mtt.nxeasy.recyclerview.helper.skikcy.IHeaderAttachListener; import com.tencent.mtt.nxeasy.recyclerview.helper.skikcy.IHeaderHost; import com.tencent.mtt.nxeasy.recyclerview.helper.skikcy.StickyHeaderHelper; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; public class HippyRecyclerView extends HippyRecyclerViewBase implements IHeaderAttachListener, IHippyViewAboundListener { - protected INativeRenderer nativeRenderer; + protected INativeRender nativeRenderer; protected ADP listAdapter; protected boolean isEnableScroll = true; //使能ListView的滚动功能 protected StickyHeaderHelper stickyHeaderHelper; //支持吸顶 @@ -84,7 +84,7 @@ public void setHeaderHost(IHeaderHost headerHost) { this.headerHost = headerHost; } - public void setNativeRenderer(INativeRenderer nativeRenderer) { + public void setNativeRenderer(INativeRender nativeRenderer) { this.nativeRenderer = nativeRenderer; } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java index bf54a6a65e8..2d46d3bca1b 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java @@ -29,8 +29,8 @@ import com.tencent.mtt.hippy.uimanager.HippyViewController; import com.tencent.mtt.hippy.uimanager.ListViewRenderNode; import com.tencent.mtt.hippy.uimanager.RenderNode; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; @HippyController(name = HippyRecyclerViewController.CLASS_NAME) @@ -83,8 +83,8 @@ public static HippyRecyclerView initDefault(Context context, HippyMap iniProps, layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); } recyclerView.setLayoutManager(layoutManager); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); recyclerView.setNativeRenderer(NativeRendererManager.getNativeRenderer(instanceId)); } recyclerView.initRecyclerView(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewWrapper.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewWrapper.java index 1b901001c81..f7ff8e1c640 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewWrapper.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewWrapper.java @@ -29,15 +29,15 @@ import com.tencent.mtt.hippy.uimanager.NativeGestureDispatcher; import com.tencent.mtt.hippy.uimanager.RenderNode; import com.tencent.mtt.nxeasy.recyclerview.helper.skikcy.IHeaderHost; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; public class HippyRecyclerViewWrapper extends FrameLayout implements HippyViewBase, IHeaderHost { - protected INativeRenderer hpContext = null; + protected INativeRender hpContext = null; protected HRCV recyclerView; private NativeGestureDispatcher nativeGestureDispatcher; @@ -45,8 +45,8 @@ public HippyRecyclerViewWrapper(@NonNull Context context, HRCV recyclerView) { super(context); this.recyclerView = recyclerView; addView(recyclerView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); hpContext = NativeRendererManager.getNativeRenderer(instanceId); } HippyRecyclerExtension cacheExtension = new HippyRecyclerExtension(recyclerView, hpContext, diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageView.java index 4cd322e15c2..15b64e3a8d6 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageView.java @@ -45,8 +45,8 @@ import com.tencent.mtt.supportui.views.asyncimage.AsyncImageView; import com.tencent.mtt.supportui.views.asyncimage.BackgroundDrawable; import com.tencent.mtt.supportui.views.asyncimage.ContentDrawable; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.util.Arrays; @@ -116,13 +116,13 @@ public enum ImageEvent { private OnLoadStartEvent mOnLoadStartEvent; private final boolean[] mShouldSendImageEvent; private Rect mNinePatchRect; - private INativeRenderer nativeRenderer; + private INativeRender nativeRenderer; public HippyImageView(Context context) { super(context); mShouldSendImageEvent = new boolean[ImageEvent.values().length]; - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { setImageAdapter(nativeRenderer.getImageLoaderAdapter()); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageViewController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageViewController.java index 91fdd9d4d6a..82a9e936e81 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageViewController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/image/HippyImageViewController.java @@ -27,7 +27,7 @@ import android.graphics.Color; import android.view.View; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.NativeRenderContext; @SuppressWarnings({"deprecation", "unused"}) @HippyController(name = HippyImageViewController.CLASS_NAME) @@ -65,7 +65,7 @@ public void setImageType(HippyImageView hippyImageView, String type) { @SuppressWarnings("unused") @HippyControllerProps(name = "src", defaultType = HippyControllerProps.STRING) public void setUrl(HippyImageView hippyImageView, String url) { - hippyImageView.setUrl(getInnerPath((NativeRendererContext)hippyImageView.getContext(), url)); + hippyImageView.setUrl(getInnerPath((NativeRenderContext)hippyImageView.getContext(), url)); } @SuppressWarnings("unused") @@ -110,7 +110,7 @@ public void setBackgroundColor(HippyImageView view, int backgroundColor) { @HippyControllerProps(name = "defaultSource", defaultType = HippyControllerProps.STRING) public void setDefaultSource(HippyImageView hippyImageView, String defaultSource) { hippyImageView.setHippyViewDefaultSource( - getInnerPath((NativeRendererContext)hippyImageView.getContext(), defaultSource)); + getInnerPath((NativeRenderContext)hippyImageView.getContext(), defaultSource)); } @SuppressWarnings("unused") diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListAdapter.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListAdapter.java index a0e5ffcb911..b6d3c72c01a 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListAdapter.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListAdapter.java @@ -28,14 +28,14 @@ import com.tencent.mtt.hippy.views.refresh.HippyPullFooterView; import com.tencent.mtt.hippy.views.refresh.HippyPullHeaderView; import com.tencent.mtt.supportui.views.recyclerview.*; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; import java.util.ArrayList; @SuppressWarnings("deprecation") public class HippyListAdapter extends RecyclerAdapter implements IRecycleItemTypeChange { - protected final INativeRenderer nativeRenderer; + protected final INativeRender nativeRenderer; private RecyclerViewBase.Recycler mRecycler; private HippyViewEvent onEndReachedEvent; private HippyViewEvent onLoadMoreEvent; @@ -43,7 +43,7 @@ public class HippyListAdapter extends RecyclerAdapter implements IRecycleItemTyp // harryguo: 给hippy sdk提供API:设置提前预加载的条目数量,默认为0 private int mPreloadItemNum = 0; - public HippyListAdapter(RecyclerView recyclerView, INativeRenderer nativeRenderer) { + public HippyListAdapter(RecyclerView recyclerView, INativeRender nativeRenderer) { super(recyclerView); this.nativeRenderer = nativeRenderer; } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListView.java index 43bb3fd05f7..a736125846a 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/list/HippyListView.java @@ -31,8 +31,8 @@ import com.tencent.mtt.supportui.views.recyclerview.RecyclerAdapter; import com.tencent.mtt.supportui.views.recyclerview.RecyclerView; import com.tencent.mtt.supportui.views.recyclerview.RecyclerViewItem; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import android.content.Context; @@ -95,11 +95,11 @@ public class HippyListView extends RecyclerView implements HippyViewBase { private OnScrollFlingStartedEvent mOnScrollFlingStartedEvent; private OnScrollFlingEndedEvent mOnScrollFlingEndedEvent; private OnScrollEvent mOnScrollEvent; - private INativeRenderer nativeRenderer; + private INativeRender nativeRenderer; private void init(Context context, int orientation) { - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); } this.setLayoutManager(new LinearLayoutManager(context, orientation, false)); @@ -122,7 +122,7 @@ public HippyListView(Context context) { } protected RecyclerAdapter createAdapter(RecyclerView hippyRecyclerView, - INativeRenderer nativeRenderer) { + INativeRender nativeRenderer) { return new HippyListAdapter(hippyRecyclerView, nativeRenderer); } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java index 8ca07a95b84..9fcd3cab192 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java @@ -42,8 +42,8 @@ import com.tencent.mtt.hippy.utils.LogUtils; import com.tencent.mtt.hippy.views.view.HippyViewGroup; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.lang.reflect.Field; import java.util.ArrayList; @@ -69,7 +69,7 @@ public void onInstancePause() { @Override public void onInstanceDestroy() { - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.removeInstanceLifecycleEventListener(this); } @@ -103,9 +103,9 @@ public interface OnRequestCloseListener { public HippyModalHostView(Context context) { super(context); mAniType = STYLE_THEME_FULL_SCREEN_DIALOG; - if (context instanceof NativeRendererContext) { - instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.addInstanceLifecycleEventListener(this); } @@ -250,7 +250,7 @@ public void setDialogBar(boolean isDarkIcon) { } private boolean isActivityFinishing() { - NativeRendererContext nativeRendererContext = (NativeRendererContext)getContext(); + NativeRenderContext nativeRendererContext = (NativeRenderContext)getContext(); Context context = nativeRendererContext.getBaseContext(); if (!(context instanceof Activity)) { @@ -329,8 +329,8 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { mOnRequestCloseListener.onRequestClose(dialog); return true; } else { - if (((NativeRendererContext)getContext()).getBaseContext() instanceof Activity) { - Activity currentActivity = (Activity)((NativeRendererContext)getContext()) + if (((NativeRenderContext)getContext()).getBaseContext() instanceof Activity) { + Activity currentActivity = (Activity)((NativeRenderContext)getContext()) .getBaseContext(); if (currentActivity != null) { return currentActivity.onKeyUp(keyCode, event); @@ -465,7 +465,7 @@ protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { getChildAt(0).getTop() + h); } - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { final int id = getChildAt(0).getId(); nativeRenderer.updateModalHostNodeSize(id, w, h); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/scroll/HippyScrollViewEventHelper.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/scroll/HippyScrollViewEventHelper.java index b4bda63be92..85aeb8a41fb 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/scroll/HippyScrollViewEventHelper.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/scroll/HippyScrollViewEventHelper.java @@ -20,8 +20,8 @@ import com.tencent.mtt.hippy.common.HippyMap; import com.tencent.mtt.hippy.utils.PixelUtil; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; @SuppressWarnings({"deprecation", "unused"}) @@ -85,9 +85,9 @@ protected static void emitScrollEvent(ViewGroup view, String scrollEventType) { event.pushMap("layoutMeasurement", layoutMeasurement); Context context = view.getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)view.getContext()).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)view.getContext()).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); //noinspection ConstantConditions if (nativeRenderer != null) { nativeRenderer.dispatchUIComponentEvent(view.getId(), scrollEventType, event); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/text/HippyTextView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/text/HippyTextView.java index e4dc9fc20f4..24fae67d3d1 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/text/HippyTextView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/text/HippyTextView.java @@ -35,8 +35,8 @@ import com.tencent.mtt.hippy.views.common.CommonBackgroundDrawable; import com.tencent.mtt.hippy.views.common.CommonBorder; import com.tencent.mtt.hippy.views.list.HippyRecycler; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; @SuppressWarnings({"unused"}) @@ -83,9 +83,9 @@ public void setId(int id) { super.setId(id); Context context = getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { DomNode node = nativeRenderer.getDomManager().getNode(id); if (node instanceof TextNode) { @@ -162,9 +162,9 @@ protected void onDraw(Canvas canvas) { } } catch (Throwable e) { Context context = getContext(); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); - INativeRenderer nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); + INativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); if (nativeRenderer != null) { nativeRenderer.handleNativeException(new RuntimeException("hippyTextView onDraw" + e.getMessage()), true); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/HippyTextInput.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/HippyTextInput.java index 5e07c886bef..58d1a739a35 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/HippyTextInput.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/HippyTextInput.java @@ -48,8 +48,8 @@ import android.widget.TextView; import androidx.appcompat.widget.AppCompatEditText; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.lang.reflect.Field; @@ -58,7 +58,7 @@ public class HippyTextInput extends AppCompatEditText implements HippyViewBase, TextView.OnEditorActionListener, View.OnFocusChangeListener { private CommonBackgroundDrawable mReactBackgroundDrawable; - INativeRenderer nativeRenderer = null; + INativeRender nativeRenderer = null; boolean mHasAddWatcher = false; private String mPreviousText; TextWatcher mTextWatcher = null; @@ -75,8 +75,8 @@ public class HippyTextInput extends AppCompatEditText implements HippyViewBase, public HippyTextInput(Context context) { super(context); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext) context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext) context).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/TextInputNode.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/TextInputNode.java index 18359ae5f66..fe4b1f973c7 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/TextInputNode.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/textinput/TextInputNode.java @@ -29,7 +29,7 @@ import com.tencent.mtt.hippy.dom.node.TextNode; import com.tencent.mtt.hippy.utils.ContextHolder; import com.tencent.mtt.hippy.utils.PixelUtil; -import com.tencent.renderer.INativeRenderer; +import com.tencent.renderer.INativeRender; @SuppressWarnings({"deprecation", "unused"}) public class TextInputNode extends TextNode implements FlexNodeAPI.MeasureFunction { @@ -49,7 +49,7 @@ public void updateProps(HippyMap props) { } @Override - public void layoutBefore(INativeRenderer nativeRenderer) { + public void layoutBefore(INativeRender nativeRenderer) { if (mEditText == null) { mEditText = new EditText(ContextHolder.getAppContext()); @@ -66,7 +66,7 @@ public void layoutBefore(INativeRenderer nativeRenderer) { } @Override - public void layoutAfter(INativeRenderer nativeRenderer) { + public void layoutAfter(INativeRender nativeRenderer) { // 不能删 } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/view/HippyViewGroupController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/view/HippyViewGroupController.java index 920222e5b30..46898cf3280 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/view/HippyViewGroupController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/view/HippyViewGroupController.java @@ -25,7 +25,7 @@ import com.tencent.mtt.hippy.utils.PixelUtil; import com.tencent.mtt.hippy.views.image.HippyImageView; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.NativeRenderContext; import java.util.WeakHashMap; @SuppressWarnings({"unused"}) @@ -61,7 +61,7 @@ public void setOverflow(HippyViewGroup hippyViewGroup, String overflow) { @HippyControllerProps(name = NodeProps.BACKGROUND_IMAGE, defaultType = HippyControllerProps.STRING) public void setBackgroundImage(HippyViewGroup hippyViewGroup, String url) { - hippyViewGroup.setUrl(getInnerPath((NativeRendererContext)hippyViewGroup.getContext(), url)); + hippyViewGroup.setUrl(getInnerPath((NativeRenderContext)hippyViewGroup.getContext(), url)); } @HippyControllerProps(name = NodeProps.BACKGROUND_SIZE, defaultType = HippyControllerProps.STRING, defaultString = "origin") diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/waterfalllist/HippyWaterfallView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/waterfalllist/HippyWaterfallView.java index e1318f5aa96..b138773a5bc 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/waterfalllist/HippyWaterfallView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/waterfalllist/HippyWaterfallView.java @@ -42,8 +42,8 @@ import com.tencent.mtt.supportui.views.recyclerview.RecyclerView; import com.tencent.mtt.supportui.views.recyclerview.RecyclerViewBase; import com.tencent.mtt.supportui.views.recyclerview.Scroller; -import com.tencent.renderer.INativeRenderer; -import com.tencent.renderer.NativeRendererContext; +import com.tencent.renderer.INativeRender; +import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; import java.util.ArrayList; @@ -54,7 +54,7 @@ public class HippyWaterfallView extends HippyListView implements HippyViewBase, static final String TAG = "HippyWaterfallView"; HippyWaterfallAdapter mAdapter; - private INativeRenderer nativeRenderer; + private INativeRender nativeRenderer; private NativeGestureDispatcher mGestureDispatcher; private Runnable mDispatchLayout = null; @@ -81,8 +81,8 @@ public class HippyWaterfallView extends HippyListView implements HippyViewBase, public HippyWaterfallView(Context context) { super(context); - if (context instanceof NativeRendererContext) { - int instanceId = ((NativeRendererContext)context).getInstanceId(); + if (context instanceof NativeRenderContext) { + int instanceId = ((NativeRenderContext)context).getInstanceId(); nativeRenderer = NativeRendererManager.getNativeRenderer(instanceId); } @@ -100,7 +100,7 @@ public HippyWaterfallView(Context context) { @Override protected HippyWaterfallAdapter createAdapter(RecyclerView hippyRecyclerView, - INativeRenderer nativeRenderer) { + INativeRender nativeRenderer) { return new HippyWaterfallAdapter(this); } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/INativeRender.java similarity index 88% rename from renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderer.java rename to renderer/native/android/src/main/java/com/tencent/renderer/INativeRender.java index 41640c8ecc9..987d3c7d86c 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/INativeRender.java @@ -18,14 +18,12 @@ import android.view.ViewGroup; import com.tencent.mtt.hippy.HippyInstanceLifecycleEventListener; import com.tencent.mtt.hippy.adapter.font.HippyFontScaleAdapter; -import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.common.HippyMap; import com.tencent.mtt.hippy.dom.DomManager; -import com.tencent.mtt.hippy.modules.Promise; import com.tencent.mtt.hippy.uimanager.RenderManager; import com.tencent.mtt.supportui.adapters.image.IImageLoaderAdapter; -public interface INativeRenderer { +public interface INativeRender { RenderManager getRenderManager(); DomManager getDomManager(); @@ -60,12 +58,4 @@ void updateDimension(boolean shouldRevise, HippyMap dimension, void removeInstanceLifecycleEventListener(HippyInstanceLifecycleEventListener listener); void handleNativeException(Exception exception, boolean haveCaught); - - void createNode(HippyArray hippyArray); - - void updateNode(HippyArray updateArray); - - void deleteNode(HippyArray deleteArray); - - } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderDelegate.java b/renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderDelegate.java new file mode 100644 index 00000000000..794e641e66f --- /dev/null +++ b/renderer/native/android/src/main/java/com/tencent/renderer/INativeRenderDelegate.java @@ -0,0 +1,33 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed 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.tencent.renderer; + +import java.util.ArrayList; + +public interface INativeRenderDelegate { + + void createNode(ArrayList list); + + void updateNode(ArrayList list); + + void deleteNode(ArrayList list); + + void startBatch(); + + void endBatch(); + + void handleRenderException(Exception exception); +} diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererContext.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderContext.java similarity index 88% rename from renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererContext.java rename to renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderContext.java index 4d44295b285..2a3cf409a32 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererContext.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderContext.java @@ -18,9 +18,10 @@ import android.content.Context; import android.content.ContextWrapper; -public final class NativeRendererContext extends ContextWrapper { +public final class NativeRenderContext extends ContextWrapper { private int instanceId; - public NativeRendererContext(Context context, int instanceId) { + + public NativeRenderContext(Context context, int instanceId) { super(context); this.instanceId = instanceId; } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderException.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderException.java new file mode 100644 index 00000000000..7b004d1cb6a --- /dev/null +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderException.java @@ -0,0 +1,36 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed 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.tencent.renderer; + +import org.w3c.dom.DOMException; + +public class NativeRenderException extends DOMException { + public NativeRenderException(short code, String message) { + super(code, message); + this.code = code; + } + + /** + * If get an invalid or illegal node data from C dom manager, + * such as node id or parent id is negative number + */ + public static final short INVALID_NODE_DATA_ERR = 100; + + /** + * If get an exception of Deserialize node data from C dom manager + */ + public static final short DESERIALIZER_DATA_ERR = 101; +} diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderProvider.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderProvider.java new file mode 100644 index 00000000000..2f979a840af --- /dev/null +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderProvider.java @@ -0,0 +1,150 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed 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.tencent.renderer; + +import com.tencent.mtt.hippy.serialization.nio.reader.BinaryReader; +import com.tencent.mtt.hippy.serialization.nio.reader.SafeHeapReader; +import com.tencent.mtt.hippy.serialization.string.InternalizedStringTable; +import com.tencent.mtt.hippy.utils.UIThreadUtils; +import com.tencent.renderer.serialization.Deserializer; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +public class NativeRenderProvider { + private final INativeRenderDelegate renderDelegate; + private final Deserializer deserializer; + private BinaryReader safeHeapReader; + + public NativeRenderProvider(INativeRenderDelegate renderDelegate, long runtimeId) { + this.renderDelegate = renderDelegate; + deserializer = new Deserializer(null, new InternalizedStringTable()); + onCreateNativeRenderProvider(runtimeId); + } + + public void destroy() { + deserializer.getStringTable().release(); + } + + /** + * Deserialize dom node data wrap by ByteBuffer + * just support heap buffer reader, direct buffer reader not fit for dom data + * + * @param buffer The byte array from c DOM wrap by ByteBuffer + * @return The ArrayList of deserialize result + */ + private ArrayList bytesToArgument(ByteBuffer buffer) { + Object paramsObj = null; + try { + final BinaryReader binaryReader; + if (safeHeapReader == null) { + safeHeapReader = new SafeHeapReader(); + } + binaryReader = safeHeapReader; + binaryReader.reset(buffer); + deserializer.setReader(binaryReader); + deserializer.reset(); + deserializer.readHeader(); + paramsObj = deserializer.readValue(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + if (renderDelegate != null) { + renderDelegate.handleRenderException(new RuntimeException(throwable)); + } + } + + return (paramsObj instanceof ArrayList) ? (ArrayList)paramsObj : new ArrayList(); + } + + public void createNode(byte[] buffer) { + final ArrayList list = bytesToArgument(ByteBuffer.wrap(buffer)); + UIThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + if (renderDelegate == null) { + return; + } + try { + renderDelegate.createNode(list); + } catch (Exception exception) { + exception.printStackTrace(); + renderDelegate.handleRenderException(exception); + } + } + }); + } + + public void updateNode(byte[] buffer) { + final ArrayList list = bytesToArgument(ByteBuffer.wrap(buffer)); + UIThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + if (renderDelegate == null) { + return; + } + try { + renderDelegate.updateNode(list); + } catch (Exception exception) { + exception.printStackTrace(); + renderDelegate.handleRenderException(exception); + } + } + }); + } + + public void deleteNode(byte[] buffer) { + final ArrayList list = bytesToArgument(ByteBuffer.wrap(buffer)); + UIThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + if (renderDelegate == null) { + return; + } + try { + renderDelegate.deleteNode(list); + } catch (Exception exception) { + exception.printStackTrace(); + renderDelegate.handleRenderException(exception); + } + } + }); + } + + public void startBatch() { + UIThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + if (renderDelegate != null) { + renderDelegate.startBatch(); + } + } + }); + } + + public void endBatch() { + UIThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + if (renderDelegate != null) { + renderDelegate.endBatch(); + } + } + }); + } + + public native void onCreateNativeRenderProvider(long runtimeId); + + public native void updateRootSize(int width, int height); +} diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java index b645be1eeca..cc2e391de89 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java @@ -15,38 +15,37 @@ */ package com.tencent.renderer; +import static com.tencent.renderer.NativeRenderException.INVALID_NODE_DATA_ERR; + import android.content.Context; import android.view.ViewGroup; +import com.tencent.mtt.hippy.utils.LogUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; import com.tencent.hippy.support.HippyBaseController; import com.tencent.hippy.support.IFrameworkProxy; import com.tencent.hippy.support.IJSFrameworkProxy; -import com.tencent.hippy.support.INativeRendererProxy; +import com.tencent.hippy.support.INativeRenderProxy; import com.tencent.mtt.hippy.HippyInstanceLifecycleEventListener; import com.tencent.mtt.hippy.HippyRootView; import com.tencent.mtt.hippy.adapter.font.HippyFontScaleAdapter; -import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.common.HippyMap; import com.tencent.mtt.hippy.common.ThreadExecutor; import com.tencent.mtt.hippy.dom.DomManager; -import com.tencent.mtt.hippy.modules.Promise; -import com.tencent.mtt.hippy.uimanager.HippyCustomViewCreator; import com.tencent.mtt.hippy.uimanager.RenderManager; -import com.tencent.mtt.hippy.utils.PixelUtil; import com.tencent.mtt.supportui.adapters.image.IImageLoaderAdapter; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; - -public class NativeRenderer implements INativeRenderer, INativeRendererProxy { - final String ID = "id"; - final String PID = "pId"; - final String INDEX = "index"; - final String NAME = "name"; - final String PROPS = "props"; - final String TAG_NAME = "tagName"; +public class NativeRenderer implements INativeRender, INativeRenderProxy, INativeRenderDelegate { + public static final String TAG = "NativeRenderer"; + private final String ID = "id"; + private final String PID = "pId"; + private final String INDEX = "index"; + private final String NAME = "name"; + private final String PROPS = "props"; private static final int ROOT_VIEW_TAG_INCREMENT = 10; private static final AtomicInteger ID_COUNTER = new AtomicInteger(0); @@ -57,7 +56,7 @@ public class NativeRenderer implements INativeRenderer, INativeRendererProxy { private DomManager domManager; private HippyRootView rootView; private IFrameworkProxy frameworkProxy; - private NativeRendererDelegate delegate; + private NativeRenderProvider renderProvider; volatile CopyOnWriteArrayList instanceLifecycleEventListeners; @Override @@ -126,9 +125,13 @@ public void handleNativeException(Exception exception, boolean haveCaught) { } } + @Override + public void handleRenderException(Exception exception) { + handleNativeException(exception, true); + } + @Override public void setFrameworkProxy(IFrameworkProxy proxy) { - assert proxy != null; frameworkProxy = proxy; } @@ -148,9 +151,9 @@ public void run() { if (renderManager != null) { renderManager.destroy(); } - if (delegate != null) { - delegate.destroy(); - delegate = null; + if (renderProvider != null) { + renderProvider.destroy(); + renderProvider = null; } if (instanceLifecycleEventListeners != null) { instanceLifecycleEventListeners.clear(); @@ -162,8 +165,12 @@ public void run() { @Override public ViewGroup createRootView(Context context) { - assert context != null; + if (context == null) { + return null; + } rootView = new HippyRootView(context, instanceId, rootId); + renderManager.createRootNode(rootId); + renderManager.addRootView(rootView); return rootView; } @@ -206,26 +213,10 @@ public void onFirstViewAdded(){ @Override public void onSizeChanged(int w, int h, int oldw, int oldh) { - HippyMap hippyMap = new HippyMap(); - hippyMap.pushDouble("width", PixelUtil.px2dp(w)); - hippyMap.pushDouble("height", PixelUtil.px2dp(h)); - hippyMap.pushDouble("oldWidth", PixelUtil.px2dp(oldw)); - hippyMap.pushDouble("oldHeight", PixelUtil.px2dp(oldh)); - if(frameworkProxy != null) { - frameworkProxy.onSizeChanged(w, h, oldw, oldh); - } - - ThreadExecutor threadExecutor = getJSEngineThreadExecutor(); - if (threadExecutor != null) { - final int width = w; - final int height = h; - final int rootId = rootView.getId(); - threadExecutor.postOnDomThread(new Runnable() { - @Override - public void run() { - getDomManager().updateNodeSize(rootId, width, height); - } - }); + if (renderProvider != null) { + LogUtils.d(TAG, "onSizeChanged: w=" + w + ", h=" + h + ", oldw=" + + oldw + ", oldh=" + oldh); + renderProvider.updateRootSize(w, h); } } @@ -267,21 +258,7 @@ public void dispatchNativeGestureEvent(HippyMap params) { @Override public void onInstanceLoad() { - assert rootView != null; - ThreadExecutor threadExecutor = getJSEngineThreadExecutor(); - if (threadExecutor != null && rootView != null) { - final int rootId = rootView.getId(); - final int width = rootView.getWidth(); - final int height = rootView.getHeight(); - threadExecutor.postOnDomThread(new Runnable() { - @Override - public void run() { - getDomManager().createRootNode(rootId, width, height); - } - }); - } - renderManager.addRootView(rootView); } @Override @@ -313,7 +290,7 @@ public void onInstanceDestroy() { @Override public void onRuntimeInitialized(long runtimeId) { - delegate = new NativeRendererDelegate(this, runtimeId); + renderProvider = new NativeRenderProvider(this, runtimeId); } @Override @@ -332,103 +309,48 @@ public void removeInstanceLifecycleEventListener(HippyInstanceLifecycleEventList } @Override - public void createNode(int rootID, HippyArray hippyArray) { - if (hippyArray != null && rootView != null && domManager != null) { - int len = hippyArray.size(); - for (int i = 0; i < len; i++) { - HippyMap nodeArray = hippyArray.getMap(i); - int tag = ((Number)nodeArray.get(ID)).intValue(); - int pTag = ((Number)nodeArray.get(PID)).intValue(); - int index = ((Number)nodeArray.get(INDEX)).intValue(); - if (tag < 0 || pTag < 0 || index < 0) { - throw new IllegalArgumentException( - "createNode invalid value: " + "id=" + tag + ", pId=" + pTag + ", index=" + index); - } - - String className = (String) nodeArray.get(NAME); - String tagName = (String) nodeArray.get(TAG_NAME); - HippyMap props = (HippyMap) nodeArray.get(PROPS); - domManager.createNode(rootView, rootID, tag, pTag, index, className, tagName, props); - } + public void createNode(ArrayList nodeList) { + if (nodeList == null || rootView == null) { + return; } - } - - @Override - public void updateNode(int rootID, HippyArray updateArray) { - if (updateArray != null && updateArray.size() > 0 && rootView != null - && domManager != null) { - int len = updateArray.size(); - for (int i = 0; i < len; i++) { - HippyMap nodemap = updateArray.getMap(i); - int id = ((Number)nodemap.get(ID)).intValue(); - if (id < 0) { - throw new IllegalArgumentException("updateNode invalid value: " + "id=" + id); - } - HippyMap props = (HippyMap) nodemap.get(PROPS); - domManager.updateNode(id, props, rootView); + for (int i = 0; i < nodeList.size(); i++) { + Object object = nodeList.get(i); + if (!(object instanceof HashMap)) { + throw new NativeRenderException(INVALID_NODE_DATA_ERR, + "createNode invalid value: " + "object=" + object); } - } - } - - @Override - public void deleteNode(int rootId, HippyArray delete) { - if (delete != null && delete.size() > 0 && domManager != null) { - int len = delete.size(); - for (int i = 0; i < len; i++) { - HippyMap nodemap = delete.getMap(i); - int id = ((Number)nodemap.get(ID)).intValue(); - if (id < 0) { - throw new IllegalArgumentException("deleteNode invalid value: " + "id=" + id); - } - domManager.deleteNode(id); + HashMap node = (HashMap)object; + int id = ((Number)node.get(ID)).intValue(); + int pid = ((Number)node.get(PID)).intValue(); + int index = ((Number)node.get(INDEX)).intValue(); + if (id < 0 || pid < 0 || index < 0) { + throw new NativeRenderException(INVALID_NODE_DATA_ERR, + "createNode invalid value: " + "id=" + id + ", pId=" + pid + ", index=" + index); } + String className = (String) node.get(NAME); + HashMap props = (HashMap) node.get(PROPS); + renderManager.createNode(rootView, id, pid, index, className, props); } } @Override - public void callUIFunction(HippyArray hippyArray, Promise promise) { - if (hippyArray != null && hippyArray.size() > 0 && domManager != null) { - int id = hippyArray.getInt(0); - String functionName = hippyArray.getString(1); - HippyArray array = hippyArray.getArray(2); - domManager.dispatchUIFunction(id, functionName, array, promise); - } - } - - @Override - public void measureInWindow(int id, Promise promise) { - if (domManager != null) { - domManager.measureInWindow(id, promise); - } - } - - @Override - public void startBatch() { - if (domManager != null) { - domManager.renderBatchStart(); - } - } + public void updateNode(ArrayList nodeList) { - @Override - public void endBatch() { - if (domManager != null) { - domManager.renderBatchEnd(); - } } @Override - public void createNode(HippyArray hippyArray) { + public void deleteNode(ArrayList nodeList) { } @Override - public void updateNode(HippyArray updateArray) { + public void startBatch() { } @Override - public void deleteNode(HippyArray deleteArray) { - + public void endBatch() { + renderManager.batch(); } public ThreadExecutor getJSEngineThreadExecutor() { diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererDelegate.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererDelegate.java deleted file mode 100644 index a2a1c5d85da..00000000000 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererDelegate.java +++ /dev/null @@ -1,103 +0,0 @@ -/* Tencent is pleased to support the open source community by making Hippy available. - * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed 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.tencent.renderer; - -import com.tencent.mtt.hippy.common.HippyArray; -import com.tencent.mtt.hippy.serialization.nio.reader.BinaryReader; -import com.tencent.mtt.hippy.serialization.nio.reader.SafeHeapReader; -import com.tencent.mtt.hippy.serialization.string.InternalizedStringTable; -import com.tencent.mtt.hippy.utils.LogUtils; -import com.tencent.mtt.hippy.utils.UIThreadUtils; -import com.tencent.renderer.serialization.Deserializer; -import java.nio.ByteBuffer; - -public class NativeRendererDelegate { - private final INativeRenderer nativeRenderer; - private final Deserializer deserializer; - private BinaryReader safeHeapReader; - - public NativeRendererDelegate(INativeRenderer nativeRenderer, long runtimeId) { - this.nativeRenderer = nativeRenderer; - deserializer = new Deserializer(null, new InternalizedStringTable()); - onCreateNativeRendererDelegate(runtimeId); - } - - public void destroy() { - deserializer.getStringTable().release(); - } - - private HippyArray bytesToArgument(ByteBuffer buffer) { - Object paramsObj = null; - try { - final BinaryReader binaryReader; - if (safeHeapReader == null) { - safeHeapReader = new SafeHeapReader(); - } - binaryReader = safeHeapReader; - binaryReader.reset(buffer); - deserializer.setReader(binaryReader); - deserializer.reset(); - deserializer.readHeader(); - paramsObj = deserializer.readValue(); - } catch (Throwable throwable) { - throwable.printStackTrace(); - LogUtils.e("compatible.Deserializer", "Error Parsing Buffer", throwable); - if (nativeRenderer != null) { - nativeRenderer.handleNativeException(new RuntimeException(throwable), true); - } - } - - return (paramsObj instanceof HippyArray) ? (HippyArray)paramsObj : new HippyArray(); - } - - public void createNode(byte[] buffer) { - final HippyArray hippyArray = bytesToArgument(ByteBuffer.wrap(buffer)); - UIThreadUtils.runOnUiThread(new Runnable() { - @Override - public void run() { - if (nativeRenderer != null) { - nativeRenderer.createNode(hippyArray); - } - } - }); - } - - public void updateNode(byte[] buffer) { - final HippyArray hippyArray = bytesToArgument(ByteBuffer.wrap(buffer)); - UIThreadUtils.runOnUiThread(new Runnable() { - @Override - public void run() { - if (nativeRenderer != null) { - nativeRenderer.updateNode(hippyArray); - } - } - }); - } - - public void deleteNode(byte[] buffer) { - final HippyArray hippyArray = bytesToArgument(ByteBuffer.wrap(buffer)); - UIThreadUtils.runOnUiThread(new Runnable() { - @Override - public void run() { - if (nativeRenderer != null) { - nativeRenderer.deleteNode(hippyArray); - } - } - }); - } - - public native void onCreateNativeRendererDelegate(long runtimeId); -} diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererManager.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererManager.java index 219f23514ab..6aead9a5ce8 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererManager.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRendererManager.java @@ -18,9 +18,9 @@ import java.util.concurrent.ConcurrentHashMap; public class NativeRendererManager { - private static final ConcurrentHashMap nativeRendererMap = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap nativeRendererMap = new ConcurrentHashMap<>(); - public static void addNativeRendererInstance(Integer instanceId, INativeRenderer nativeRenderer) { + public static void addNativeRendererInstance(Integer instanceId, INativeRender nativeRenderer) { nativeRendererMap.put(instanceId, nativeRenderer); } @@ -28,7 +28,7 @@ public static void removeNativeRendererInstance(Integer instanceId) { nativeRendererMap.remove(instanceId); } - public static INativeRenderer getNativeRenderer(Integer instanceId) { + public static INativeRender getNativeRenderer(Integer instanceId) { return nativeRendererMap.get(instanceId); } } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/serialization/Deserializer.java b/renderer/native/android/src/main/java/com/tencent/renderer/serialization/Deserializer.java index 3d418c80764..2fb992a0b2c 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/serialization/Deserializer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/serialization/Deserializer.java @@ -15,8 +15,8 @@ */ package com.tencent.renderer.serialization; -import com.tencent.mtt.hippy.common.HippyArray; -import com.tencent.mtt.hippy.common.HippyMap; +import static com.tencent.renderer.NativeRenderer.TAG; + import com.tencent.mtt.hippy.serialization.exception.DataCloneOutOfRangeException; import com.tencent.mtt.hippy.exception.UnexpectedException; import com.tencent.mtt.hippy.serialization.PrimitiveValueDeserializer; @@ -24,7 +24,7 @@ import com.tencent.mtt.hippy.serialization.StringLocation; import com.tencent.mtt.hippy.serialization.nio.reader.BinaryReader; import com.tencent.mtt.hippy.serialization.string.StringTable; - +import com.tencent.mtt.hippy.utils.LogUtils; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; @@ -34,7 +34,6 @@ */ @SuppressWarnings("unused") public class Deserializer extends PrimitiveValueDeserializer { - public Deserializer(BinaryReader reader) { this(reader, null); } @@ -80,19 +79,37 @@ protected String readJSString(StringLocation location, Object relatedKey) { } @Override - protected HippyMap readJSObject() { - //HashMap map = new HashMap<>(); - HippyMap map = new HippyMap(); + protected HashMap readJSObject() { + HashMap map = new HashMap<>(); assignId(map); - int read = readProperties(map); - int expected = (int)reader.getVarint(); + int read = readObjectProperties(map); + int expected = (int) reader.getVarint(); if (read != expected) { throw new UnexpectedException("unexpected number of properties"); } return map; } - private int readProperties(HippyMap map) { + /** + * dense array from dom value not support array properties, + * but should read value until END_DENSE_JS_ARRAY, otherwise will get unexpected length. + */ + private int readArrayProperties() { + final StringLocation keyLocation = StringLocation.DENSE_ARRAY_KEY; + final StringLocation valueLocation = StringLocation.DENSE_ARRAY_ITEM; + + SerializationTag tag; + int count = 0; + while ((tag = readTag()) != SerializationTag.END_DENSE_JS_ARRAY) { + count++; + Object key = readValue(tag, keyLocation, null); + Object value = readValue(valueLocation, key); + LogUtils.d(TAG, "readArrayProperties: key" + key + ", value=" + value); + } + return count; + } + + private int readObjectProperties(HashMap map) { final StringLocation keyLocation = StringLocation.OBJECT_KEY; final StringLocation valueLocation = StringLocation.OBJECT_VALUE; @@ -101,20 +118,19 @@ private int readProperties(HippyMap map) { while ((tag = readTag()) != SerializationTag.END_JS_OBJECT) { count++; Object key = readValue(tag, keyLocation, null); - if (key instanceof String) { - Object value = readValue(valueLocation, key); - map.pushObject((String)key, value); + Object value = readValue(valueLocation, key); + if (key instanceof String || key instanceof Integer) { + map.put(key.toString(), value); } else { - throw new AssertionError("Object key is not of String"); + throw new AssertionError("Object key is not of String nor Integer type"); } } return count; } @Override - protected HippyMap readJSMap() { - //HashMap map = new HashMap<>(); - HippyMap map = new HippyMap(); + protected HashMap readJSMap() { + HashMap map = new HashMap<>(); assignId(map); SerializationTag tag; int read = 0; @@ -122,13 +138,9 @@ protected HippyMap readJSMap() { read++; Object key = readValue(tag, StringLocation.MAP_KEY, null); Object value = readValue(StringLocation.MAP_VALUE, key); - if (key == null) { - map.pushObject(null, value); - } else { - map.pushObject(key.toString(), value); - } + map.put(key, value); } - int expected = (int)reader.getVarint(); + int expected = (int) reader.getVarint(); if (2 * read != expected) { throw new UnexpectedException("unexpected number of entries"); } @@ -136,22 +148,27 @@ protected HippyMap readJSMap() { } @Override - protected HippyArray readDenseArray() { - int length = (int)reader.getVarint(); - if (length < 0) { - throw new DataCloneOutOfRangeException(length); + protected ArrayList readDenseArray() { + int totalLength = (int)reader.getVarint(); + if (totalLength < 0) { + throw new DataCloneOutOfRangeException(totalLength); } - //ArrayList array = new ArrayList(length); - HippyArray array = new HippyArray(); + ArrayList array = new ArrayList(totalLength); assignId(array); - for (int i = 0; i < length; i++) { + for (int i = 0; i < totalLength; i++) { SerializationTag tag = readTag(); - Object object = readValue(tag, StringLocation.DENSE_ARRAY_ITEM, i); - array.setObject(i, object); + if (tag != SerializationTag.THE_HOLE) { + array.add(readValue(tag, StringLocation.DENSE_ARRAY_ITEM, i)); + } } - int read = (int)reader.getVarint(); - if (length != read) { + int propsLength = readArrayProperties(); + int expected = (int) reader.getVarint(); + if (propsLength != expected) { + throw new UnexpectedException("unexpected number of properties"); + } + expected = (int) reader.getVarint(); + if (totalLength != expected) { throw new AssertionError("length ambiguity"); } return array;