Skip to content

Commit

Permalink
fix(android): update props reuse null view object
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Oct 25, 2023
1 parent 61c41d8 commit a45eda0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -71,7 +67,7 @@ public class ControllerManager {
@NonNull
private final ControllerRegistry mControllerRegistry;
@NonNull
private final ControllerUpdateManger<HippyViewController<?>, View> mControllerUpdateManger;
private final ControllerUpdateManger<HippyViewController<?>> mControllerUpdateManger;
@NonNull
private final Map<Integer, Pool<Integer, View>> mPreCreateViewPools = new HashMap<>();
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +46,7 @@
import java.util.Map;
import java.util.Set;

public class ControllerUpdateManger<T, G> {
public class ControllerUpdateManger<T> {

private static final Map<Class<?>, Map<String, PropertyMethodHolder>> sViewPropsMethodMap = new HashMap<>();
private static final Map<String, PropertyMethodHolder> sComponentPropsMethodMap = new HashMap<>();
Expand Down Expand Up @@ -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<String, Object> 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) {
Expand All @@ -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<String, Object> props, boolean skipComponentProps) {
if (props == null || props.isEmpty()) {
return;
Expand All @@ -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)) {
Expand Down

0 comments on commit a45eda0

Please sign in to comment.