From a45eda099fc12c9fb17bbc755fa06d102f967efc Mon Sep 17 00:00:00 2001 From: maxli Date: Wed, 25 Oct 2023 21:26:19 +0800 Subject: [PATCH 1/7] fix(android): update props reuse null view object --- .../hippy/uimanager/ControllerManager.java | 6 +---- .../uimanager/ControllerUpdateManger.java | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 17 deletions(-) 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 942c73d2b73..d67d77df63c 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 @@ -18,13 +18,11 @@ import static com.tencent.renderer.NativeRenderException.ExceptionCode.ADD_CHILD_VIEW_FAILED_ERR; import static com.tencent.renderer.NativeRenderException.ExceptionCode.REMOVE_CHILD_VIEW_FAILED_ERR; -import static com.tencent.renderer.NativeRenderer.SCREEN_SNAPSHOT_ROOT_ID; import static com.tencent.renderer.node.RenderNode.FLAG_ALREADY_UPDATED; import static com.tencent.renderer.node.RenderNode.FLAG_UPDATE_LAYOUT; import android.view.View; import android.view.ViewGroup; -import android.view.ViewParent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.openhippy.pool.BasePool.PoolType; @@ -35,7 +33,6 @@ import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.modules.Promise; -import com.tencent.mtt.hippy.utils.UIThreadUtils; import com.tencent.mtt.hippy.views.custom.HippyCustomPropsController; import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewController; import com.tencent.mtt.hippy.views.image.HippyImageViewController; @@ -57,7 +54,6 @@ import com.tencent.mtt.hippy.views.webview.HippyWebViewController; import com.tencent.renderer.NativeRender; import com.tencent.renderer.NativeRenderException; -import com.tencent.renderer.NativeRendererManager; import com.tencent.renderer.Renderer; import com.tencent.renderer.node.RenderNode; import com.tencent.renderer.node.VirtualNode; @@ -71,7 +67,7 @@ public class ControllerManager { @NonNull private final ControllerRegistry mControllerRegistry; @NonNull - private final ControllerUpdateManger, View> mControllerUpdateManger; + private final ControllerUpdateManger> mControllerUpdateManger; @NonNull private final Map> mPreCreateViewPools = new HashMap<>(); @NonNull diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java index 3eb4e306e4d..2865c3862e9 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java @@ -38,7 +38,6 @@ import com.tencent.renderer.utils.PropertyUtils.PropertyMethodHolder; import com.tencent.renderer.node.RenderNode; -import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; @@ -47,7 +46,7 @@ import java.util.Map; import java.util.Set; -public class ControllerUpdateManger { +public class ControllerUpdateManger { private static final Map, Map> sViewPropsMethodMap = new HashMap<>(); private static final Map sComponentPropsMethodMap = new HashMap<>(); @@ -191,12 +190,12 @@ private void invokePropMethod(@NonNull Object obj, @NonNull Object arg1, } } - private void handleCustomProps(T t, G g, @NonNull String key, + private void handleCustomProps(T t, @Nullable View g, @NonNull String key, @NonNull Map props) { - boolean hasCustomMethodHolder = false; - if (!(g instanceof View)) { + if (g == null) { return; } + boolean hasCustomMethodHolder = false; Object customProps = props.get(key); if (mCustomPropsController != null && mCustomPropsController instanceof HippyCustomPropsController) { @@ -214,11 +213,11 @@ private void handleCustomProps(T t, G g, @NonNull String key, } if (!hasCustomMethodHolder && t instanceof HippyViewController) { //noinspection unchecked - ((HippyViewController) t).setCustomProp((View) g, key, customProps); + ((HippyViewController) t).setCustomProp(g, key, customProps); } } - protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nullable G view, + protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nullable View view, @Nullable Map props, boolean skipComponentProps) { if (props == null || props.isEmpty()) { return; @@ -238,18 +237,20 @@ protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nul } PropertyMethodHolder methodHolder = methodHolderMap.get(key); if (methodHolder != null) { - Object arg = (view == null) ? node.createView(true) : view; - if (arg != null) { - invokePropMethod(controller, arg, props, key, methodHolder); + if (view == null) { + view = node.createView(true); + } + if (view != null) { + invokePropMethod(controller, view, props, key, methodHolder); } } else { // Background color is a property supported by both view and component, if the // host view of a node has already been created, we need to set this property // separately on the view, otherwise the background color setting for non // flattened elements will not take effect. - if (key.equals(NodeProps.BACKGROUND_COLOR) && view instanceof View + if (key.equals(NodeProps.BACKGROUND_COLOR) && view != null && !(view instanceof FlatViewGroup)) { - ((View) view).setBackgroundColor( + view.setBackgroundColor( MapUtils.getIntValue(props, NodeProps.BACKGROUND_COLOR, Color.TRANSPARENT)); } else if (!handleComponentProps(node, key, props, skipComponentProps)) { From ecf6c8a263c82ec2887319e238e57c01d4ca6c3c Mon Sep 17 00:00:00 2001 From: zealotchen Date: Wed, 25 Oct 2023 21:44:03 +0800 Subject: [PATCH 2/7] fix(vue): fix not update style diff crash --- driver/js/packages/hippy-vue/src/renderer/native/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/js/packages/hippy-vue/src/renderer/native/index.js b/driver/js/packages/hippy-vue/src/renderer/native/index.js index 82c18710a37..e9ecacd3ec7 100644 --- a/driver/js/packages/hippy-vue/src/renderer/native/index.js +++ b/driver/js/packages/hippy-vue/src/renderer/native/index.js @@ -666,7 +666,7 @@ function updateChild(parentNode, notUpdateStyle = false) { let eventNode; let printedNode; if (notUpdateStyle) { - nativeNode = getNativeNode(rootViewId, parentNode, refInfo); + nativeNode = getNativeNode(rootViewId, parentNode); } else { [nativeNode, eventNode, printedNode] = renderToNative(rootViewId, parentNode); } From 57628bf404f495e0d8ad92d086ce223fe6f427df Mon Sep 17 00:00:00 2001 From: ruifanyuan Date: Wed, 25 Oct 2023 18:30:08 +0800 Subject: [PATCH 3/7] fix(perf): enable perflog output in debug mode only --- framework/ios/base/bridge/HippyBridge.mm | 12 ++++++------ modules/footstone/include/footstone/logging.h | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index 3e82c52130a..a864e4bf0d2 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -191,7 +191,7 @@ - (instancetype)initWithDelegate:(id)delegate _valid = YES; _bundlesQueue = [[HippyBundleOperationQueue alloc] init]; _startTime = footstone::TimePoint::SystemNow(); - HP_PERF_LOG("HippyBridge init begin, self:%p", self); + HippyLogInfo(@"HippyBridge init begin, self:%p", self); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rootViewContentDidAppear:) name:HippyContentDidAppearNotification object:nil]; HippyExecuteOnMainThread(^{ @@ -208,7 +208,7 @@ - (instancetype)initWithDelegate:(id)delegate [HippyBridge setCurrentBridge:self]; [self loadPendingVendorBundleURLIfNeeded]; - HP_PERF_LOG("HippyBridge init end, self:%p", self); + HippyLogInfo(@"HippyBridge init end, self:%p", self); } return self; } @@ -414,7 +414,7 @@ - (void)loadBundleURL:(NSURL *)bundleURL } return; } - HP_PERF_LOG("Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); + HippyLogInfo(@"Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); [_bundleURLs addObject:bundleURL]; dispatch_async(HippyBridgeQueue(), ^{ [self beginLoadingBundle:bundleURL completion:completion]; @@ -452,7 +452,7 @@ - (void)beginLoadingBundle:(NSURL *)bundleURL return; } [strongSelf executeJSCode:script sourceURL:bundleURL onCompletion:^(id result, NSError *error) { - HP_PERF_LOG("End loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); + HippyLogInfo(@"End loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); if (completion) { completion(bundleURL, error); @@ -509,7 +509,7 @@ - (void)loadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary *)props { HippyAssert(_moduleName, @"module name must not be null"); HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],Running application %@ (%@)", _moduleName, props); - HP_PERF_LOG("Begin loading instance for HippyBridge(%p)", self); + HippyLogInfo(@"Begin loading instance for HippyBridge(%p)", self); NSDictionary *param = @{@"name": _moduleName, @"id": rootTag, @"params": props ?: @{}, @@ -517,7 +517,7 @@ - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDicti footstone::value::HippyValue value = [param toHippyValue]; std::shared_ptr domValue = std::make_shared(value); self.javaScriptExecutor.pScope->LoadInstance(domValue); - HP_PERF_LOG("End loading instance for HippyBridge(%p)", self); + HippyLogInfo(@"End loading instance for HippyBridge(%p)", self); } - (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params { diff --git a/modules/footstone/include/footstone/logging.h b/modules/footstone/include/footstone/logging.h index 91637a34282..9687cde3adf 100644 --- a/modules/footstone/include/footstone/logging.h +++ b/modules/footstone/include/footstone/logging.h @@ -215,7 +215,16 @@ bool ShouldCreateLogMessage(LogSeverity severity); #define HP_CSTR_NOT_NULL( p ) (p ? p : "") + +#ifdef DEBUG + +// enable perf log output in debug mode only #define HP_PERF_LOG(format, ...) \ footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \ ##__VA_ARGS__) +#else + +#define HP_PERF_LOG(format, ...) + +#endif From 0f51c5d7e6c586935d6d8f53c895d1f13e5d050f Mon Sep 17 00:00:00 2001 From: maxli Date: Thu, 26 Oct 2023 18:18:04 +0800 Subject: [PATCH 4/7] fix(android): send onSizeChanged message to js --- .../mtt/hippy/HippyEngineManagerImpl.java | 16 ++++++++++++++ .../com/tencent/mtt/hippy/HippyRootView.java | 22 +++++++------------ .../com/tencent/renderer/FrameworkProxy.java | 2 ++ .../com/tencent/renderer/NativeRender.java | 2 +- .../com/tencent/renderer/NativeRenderer.java | 11 ++++++++-- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java index 927a40945db..80618c83ed5 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java @@ -231,6 +231,22 @@ public void onFirstViewAdded() { } } + @Override + public void onSizeChanged(int rootId, int w, int h, int ow, int oh) { + if (mEngineContext != null) { + HippyModuleManager manager = mEngineContext.getModuleManager(); + if (manager != null) { + HippyMap hippyMap = new HippyMap(); + hippyMap.pushDouble("width", PixelUtil.px2dp(w)); + hippyMap.pushDouble("height", PixelUtil.px2dp(h)); + hippyMap.pushDouble("oldWidth", PixelUtil.px2dp(ow)); + hippyMap.pushDouble("oldHeight", PixelUtil.px2dp(oh)); + manager.getJavaScriptModule(EventDispatcher.class) + .receiveNativeEvent("onSizeChanged", hippyMap); + } + } + } + @Override public void updateDimension(int width, int height, boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) { 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 6d3190ad8cf..172900ead5a 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 @@ -23,6 +23,7 @@ import android.view.ViewTreeObserver; import android.widget.FrameLayout; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.tencent.mtt.hippy.dom.node.NodeProps; @@ -84,14 +85,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { } @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - if (w != oldw || h != oldh) { - getGlobalLayoutListener().checkUpdateDimension(w, h, false, false); - NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); - if (nativeRenderer != null) { - nativeRenderer.onSizeChanged(getId(), w, h); - } + protected void onSizeChanged(int w, int h, int ow, int oh) { + super.onSizeChanged(w, h, ow, oh); + NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); + if ((w != ow || h != oh) && nativeRenderer != null) { + nativeRenderer.updateDimension(w, h, false, false); + nativeRenderer.onSizeChanged(getId(), w, h, ow, oh); } } @@ -156,14 +155,9 @@ private void sendOrientationChangeEvent(int orientation) { private void checkUpdateDimension(boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) { - checkUpdateDimension(-1, -1, shouldUseScreenDisplay, systemUiVisibilityChanged); - } - - private void checkUpdateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged) { NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); if (nativeRenderer != null) { - nativeRenderer.updateDimension(width, height, shouldUseScreenDisplay, + nativeRenderer.updateDimension(-1, -1, shouldUseScreenDisplay, systemUiVisibilityChanged); } } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java index 70e082fc61d..c9557957d04 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java @@ -51,4 +51,6 @@ public interface FrameworkProxy { void updateDimension(int width, int height, boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged); + + void onSizeChanged(int rootId, int w, int h, int ow, int oh); } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java index 28362919b3a..b0671b18669 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java @@ -93,7 +93,7 @@ VirtualNode createVirtualNode(int rootId, int id, int pid, int index, @NonNull S void onFirstViewAdded(); - void onSizeChanged(int rootId, int width, int height); + void onSizeChanged(int rootId, int width, int height, int oldWidth, int oldHeight); void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync); 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 d8dc78ec43a..8d598e96c88 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 @@ -351,11 +351,18 @@ public void onRuntimeInitialized(final int rootId) { }); } - @Override - public void onSizeChanged(int rootId, int w, int h) { + private void onSizeChanged(int rootId, int w, int h) { mRenderProvider.onSizeChanged(rootId, w, h); } + @Override + public void onSizeChanged(int rootId, int w, int h, int ow, int oh) { + if (mFrameworkProxy != null) { + mFrameworkProxy.onSizeChanged(rootId, w, h, ow, oh); + } + onSizeChanged(rootId, w, h); + } + @Override public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync) { mRenderProvider.onSizeChanged(rootId, nodeId, width, height, isSync); From f672a4451ae4c4635cfb2b468c6a674067b70a0d Mon Sep 17 00:00:00 2001 From: zealotchen Date: Mon, 30 Oct 2023 12:49:42 +0800 Subject: [PATCH 5/7] fix(dom): fix skip style diff update style map null --- dom/src/dom/dom_node.cc | 11 +++++++++++ dom/src/dom/root_node.cc | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dom/src/dom/dom_node.cc b/dom/src/dom/dom_node.cc index 701db433487..ffebb72fe65 100644 --- a/dom/src/dom/dom_node.cc +++ b/dom/src/dom/dom_node.cc @@ -611,6 +611,13 @@ std::ostream& operator<<(std::ostream& os, const RefInfo& ref_info) { return os; } +std::ostream& operator<<(std::ostream& os, const DiffInfo& diff_info) { + os << "{"; + os << "\"skip_style_diff\": " << diff_info.skip_style_diff << ", "; + os << "}"; + return os; +} + std::ostream& operator<<(std::ostream& os, const DomNode& dom_node) { os << "{"; os << "\"id\": " << dom_node.id_ << ", "; @@ -637,10 +644,14 @@ std::ostream& operator<<(std::ostream& os, const DomNode& dom_node) { std::ostream& operator<<(std::ostream& os, const DomInfo& dom_info) { auto dom_node = dom_info.dom_node; auto ref_info = dom_info.ref_info; + auto diff_info = dom_info.diff_info; os << "{"; if (ref_info != nullptr) { os << "\"ref info\": " << *ref_info << ", "; } + if (diff_info != nullptr) { + os << "\"diff info\": " << *diff_info << ", "; + } if (dom_node != nullptr) { os << "\"dom node\": " << *dom_node << ", "; } diff --git a/dom/src/dom/root_node.cc b/dom/src/dom/root_node.cc index 5032eb5bdf7..290c0e954dd 100644 --- a/dom/src/dom/root_node.cc +++ b/dom/src/dom/root_node.cc @@ -157,7 +157,9 @@ void RootNode::UpdateDomNodes(std::vector>&& nodes) { if (!ext_update->empty()) { diff_value->insert(ext_update->begin(), ext_update->end()); } - dom_node->SetStyleMap(node_info->dom_node->GetStyleMap()); + if (!skip_style_diff) { + dom_node->SetStyleMap(node_info->dom_node->GetStyleMap()); + } dom_node->SetExtStyleMap(node_info->dom_node->GetExtStyle()); dom_node->SetDiffStyle(diff_value); From b93d175fdf4e3a4a6cb0b33934570bea52092855 Mon Sep 17 00:00:00 2001 From: maxli Date: Mon, 30 Oct 2023 16:55:12 +0800 Subject: [PATCH 6/7] fix(android): should create view if has custom props --- .../openhippy/example/ExampleAPIProvider.kt | 4 +- .../example/ExampleCustomPropsController.kt | 39 +++++++++++++++++++ .../uimanager/ControllerUpdateManger.java | 38 +++++++++++------- 3 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleCustomPropsController.kt diff --git a/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleAPIProvider.kt b/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleAPIProvider.kt index 8ff63b8053a..2064f77e7b3 100644 --- a/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleAPIProvider.kt +++ b/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleAPIProvider.kt @@ -44,6 +44,6 @@ class ExampleAPIProvider : HippyAPIProvider { * register View controller for JavaScript */ override fun getControllers(): List>> { - return emptyList() + return arrayListOf(ExampleCustomPropsController::class.java) } -} \ No newline at end of file +} diff --git a/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleCustomPropsController.kt b/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleCustomPropsController.kt new file mode 100644 index 00000000000..c67b24aef65 --- /dev/null +++ b/framework/examples/android-demo/src/main/java/com/openhippy/example/ExampleCustomPropsController.kt @@ -0,0 +1,39 @@ +/* + * 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.openhippy.example + +import android.view.View +import com.tencent.mtt.hippy.annotation.HippyController +import com.tencent.mtt.hippy.annotation.HippyControllerProps +import com.tencent.mtt.hippy.common.HippyMap +import com.tencent.mtt.hippy.utils.LogUtils +import com.tencent.mtt.hippy.views.custom.HippyCustomPropsController + +@HippyController(name = HippyCustomPropsController.CLASS_NAME) +class ExampleCustomPropsController : HippyCustomPropsController() { + + val TAG = "ExampleCustomPropsController" + + @HippyControllerProps(name = "pageParams", defaultType = HippyControllerProps.MAP) + fun setDtPageParams(view: View, params: HippyMap?) { + LogUtils.d(TAG, "setDtPageParams id " + view.id + ", params " + params) + } + + @HippyControllerProps(name = "elementParams", defaultType = HippyControllerProps.MAP) + fun setDtElementParams(view: View, params: HippyMap?) { + LogUtils.d(TAG, "setDtElementParams id " + view.id + ", params " + params) + } +} diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java index 2865c3862e9..954dfc1c328 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java @@ -190,13 +190,8 @@ private void invokePropMethod(@NonNull Object obj, @NonNull Object arg1, } } - private void handleCustomProps(T t, @Nullable View g, @NonNull String key, - @NonNull Map props) { - if (g == null) { - return; - } - boolean hasCustomMethodHolder = false; - Object customProps = props.get(key); + @Nullable + private PropertyMethodHolder getCustomPropsMethodHolder(@NonNull String key) { if (mCustomPropsController != null && mCustomPropsController instanceof HippyCustomPropsController) { Class cls = mCustomPropsController.getClass(); @@ -205,16 +200,22 @@ private void handleCustomProps(T t, @Nullable View g, @NonNull String key, methodHolderMap = new HashMap<>(); findViewPropsMethod(cls, methodHolderMap); } - PropertyMethodHolder methodHolder = methodHolderMap.get(key); + return methodHolderMap.get(key); + } + return null; + } + + private void handleCustomProps(T t, @Nullable View view, @NonNull String key, + @NonNull Map props, @Nullable PropertyMethodHolder methodHolder) { + if (view != null) { + Object customProps = props.get(key); if (methodHolder != null) { - invokePropMethod(mCustomPropsController, g, props, key, methodHolder); - hasCustomMethodHolder = true; + invokePropMethod(mCustomPropsController, view, props, key, methodHolder); + } else if (t instanceof HippyViewController) { + //noinspection unchecked + ((HippyViewController) t).setCustomProp(view, key, customProps); } } - if (!hasCustomMethodHolder && t instanceof HippyViewController) { - //noinspection unchecked - ((HippyViewController) t).setCustomProp(g, key, customProps); - } } protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nullable View view, @@ -254,7 +255,14 @@ protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nul MapUtils.getIntValue(props, NodeProps.BACKGROUND_COLOR, Color.TRANSPARENT)); } else if (!handleComponentProps(node, key, props, skipComponentProps)) { - handleCustomProps(controller, view, key, props); + PropertyMethodHolder customMethodHolder = getCustomPropsMethodHolder(key); + if (customMethodHolder != null && view == null) { + // If the host has a custom attribute that needs to be processed, this element cannot be + // flattened, otherwise, if the view is empty, custom attributes will not be passed through + // to custom props controller. + view = node.createView(true); + } + handleCustomProps(controller, view, key, props, customMethodHolder); } } } From f2ba451797e17956dbec0d94c0bd9f0863afcd4e Mon Sep 17 00:00:00 2001 From: ruifanyuan Date: Mon, 30 Oct 2023 15:32:38 +0800 Subject: [PATCH 7/7] fix(android): fix compile issue in AS release mode --- dom/src/dom/root_node.cc | 12 +++++------- driver/js/src/modules/scene_builder_module.cc | 6 +++--- modules/footstone/include/footstone/logging.h | 9 +++++++-- renderer/native/ios/renderer/HippyUIManager.mm | 10 +++++----- renderer/native/ios/renderer/NativeRenderManager.mm | 4 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/dom/src/dom/root_node.cc b/dom/src/dom/root_node.cc index 290c0e954dd..06459ad6f4e 100644 --- a/dom/src/dom/root_node.cc +++ b/dom/src/dom/root_node.cc @@ -278,21 +278,19 @@ void RootNode::CallFunction(uint32_t id, const std::string& name, const DomArgum } void RootNode::SyncWithRenderManager(const std::shared_ptr& render_manager) { - HP_PERF_LOG("RootNode::SyncWithRenderManager"); - unsigned long cnt = dom_operations_.size(); + TDF_PERF_DO_STMT_AND_LOG(unsigned long domCnt = dom_operations_.size(); , "RootNode::SyncWithRenderManager"); FlushDomOperations(render_manager); - HP_PERF_LOG("RootNode::FlushDomOperations Done, dom op count:%lld", cnt); - cnt = event_operations_.size(); + TDF_PERF_DO_STMT_AND_LOG(unsigned long evCnt = event_operations_.size(); , "RootNode::FlushDomOperations Done, dom op count:%lld", domCnt); FlushEventOperations(render_manager); - HP_PERF_LOG("RootNode::FlushEventOperations Done, event op count:%d",cnt); + TDF_PERF_LOG("RootNode::FlushEventOperations Done, event op count:%d", evCnt); DoAndFlushLayout(render_manager); - HP_PERF_LOG("RootNode::DoAndFlushLayout Done"); + TDF_PERF_LOG("RootNode::DoAndFlushLayout Done"); auto dom_manager = dom_manager_.lock(); if (dom_manager) { dom_manager->RecordDomEndTimePoint(); } render_manager->EndBatch(GetWeakSelf()); - HP_PERF_LOG("RootNode::SyncWithRenderManager End"); + TDF_PERF_LOG("RootNode::SyncWithRenderManager End"); } void RootNode::AddEvent(uint32_t id, const std::string& event_name) { diff --git a/driver/js/src/modules/scene_builder_module.cc b/driver/js/src/modules/scene_builder_module.cc index 1167b3dd342..661015c0df9 100644 --- a/driver/js/src/modules/scene_builder_module.cc +++ b/driver/js/src/modules/scene_builder_module.cc @@ -600,14 +600,14 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.build()"); + TDF_PERF_LOG("SceneBuilder.build()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.build() exit with error"); + TDF_PERF_LOG("SceneBuilder.build() exit with error"); return nullptr; } SceneBuilder::Build(scope->GetDomManager(), scope->GetRootNode()); - HP_PERF_LOG("SceneBuilder.build() End"); + TDF_PERF_LOG("SceneBuilder.build() End"); return nullptr; }; class_template.functions.emplace_back(std::move(build_func_def)); diff --git a/modules/footstone/include/footstone/logging.h b/modules/footstone/include/footstone/logging.h index 9687cde3adf..cba1b2aa415 100644 --- a/modules/footstone/include/footstone/logging.h +++ b/modules/footstone/include/footstone/logging.h @@ -219,12 +219,17 @@ bool ShouldCreateLogMessage(LogSeverity severity); #ifdef DEBUG // enable perf log output in debug mode only -#define HP_PERF_LOG(format, ...) \ +#define TDF_PERF_LOG(format, ...) \ +footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \ + ##__VA_ARGS__) + +#define TDF_PERF_DO_STMT_AND_LOG( STMT , format , ...) STMT \ footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \ ##__VA_ARGS__) #else -#define HP_PERF_LOG(format, ...) +#define TDF_PERF_LOG(format, ...) +#define TDF_PERF_DO_STMT_AND_LOG(STMT , format, ...) #endif diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 9a0007b820b..a8fdb9d312f 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -677,8 +677,8 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr)rootNode { if (!strongRootNode) { return; } - unsigned int rand = arc4random(); - HP_PERF_LOG("flushUIBlocksOnRootNode(random id:%u", rand); + + TDF_PERF_DO_STMT_AND_LOG(unsigned int rand = arc4random(); , "flushUIBlocksOnRootNode(random id:%u", rand); int32_t rootTag = strongRootNode->GetId(); NSArray *previousPendingUIBlocks = _pendingUIBlocks; @@ -689,7 +689,7 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr)rootNode { dispatch_async(dispatch_get_main_queue(), ^{ __strong __typeof(weakSelf)strongSelf = weakSelf; if (strongSelf) { - HP_PERF_LOG("flushUIBlocksOnRootNode on main thread(random id:%u)",rand); + TDF_PERF_LOG("flushUIBlocksOnRootNode on main thread(random id:%u)",rand); NSDictionary *viewReg = [strongSelf.viewRegistry componentsForRootTag:@(rootTag)]; @try { for (HippyViewManagerUIBlock block in previousPendingUIBlocks) { @@ -698,11 +698,11 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr)rootNode { } @catch (NSException *exception) { HippyLogError(@"Exception thrown while executing UI block: %@", exception); } - HP_PERF_LOG("flushUIBlocksOnRootNode on main thread done, block count:%d(random id:%u)", previousPendingUIBlocks.count, rand); + TDF_PERF_LOG("flushUIBlocksOnRootNode on main thread done, block count:%d(random id:%u)", previousPendingUIBlocks.count, rand); } }); } - HP_PERF_LOG("flushUIBlocksOnRootNode End(random id:%u)",rand); + TDF_PERF_LOG("flushUIBlocksOnRootNode End(random id:%u)",rand); } #pragma mark - diff --git a/renderer/native/ios/renderer/NativeRenderManager.mm b/renderer/native/ios/renderer/NativeRenderManager.mm index 914a2d20125..2f8fb757fd9 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.mm +++ b/renderer/native/ios/renderer/NativeRenderManager.mm @@ -111,10 +111,10 @@ void NativeRenderManager::EndBatch(std::weak_ptr root_node) { @autoreleasepool { - HP_PERF_LOG("NativeRenderManager::EndBatch Begin"); + TDF_PERF_LOG("NativeRenderManager::EndBatch Begin"); HippyAssert(renderImpl_, @"renderImpl_ is null, did you forget to call Initialize()?"); [renderImpl_ batchOnRootNode:root_node]; - HP_PERF_LOG("NativeRenderManager::EndBatch End"); + TDF_PERF_LOG("NativeRenderManager::EndBatch End"); } }