Skip to content

Commit

Permalink
fix(android): non flattened elements background color (#3352)
Browse files Browse the repository at this point in the history
Co-authored-by: maxli <maxli@tencent.com>
  • Loading branch information
2 people authored and zealotchen0 committed Jul 25, 2023
1 parent 2fcd955 commit 2a7402a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.tencent.mtt.hippy.uimanager;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;
Expand All @@ -28,9 +29,11 @@
import com.tencent.renderer.Renderer;
import com.tencent.renderer.component.Component;
import com.tencent.renderer.component.ComponentController;
import com.tencent.renderer.component.FlatViewGroup;
import com.tencent.renderer.component.image.ImageComponentController;
import com.tencent.renderer.node.TextRenderNode;
import com.tencent.renderer.node.TextVirtualNode;
import com.tencent.renderer.utils.MapUtils;
import com.tencent.renderer.utils.PropertyUtils;
import com.tencent.renderer.utils.PropertyUtils.PropertyMethodHolder;
import com.tencent.renderer.node.RenderNode;
Expand Down Expand Up @@ -210,8 +213,15 @@ protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nul
invokePropMethod(controller, arg, props, key, methodHolder);
}
} else {
if (key.equals(NodeProps.STYLE) && props.get(key) instanceof Map) {
updateProps(node, controller, view, (Map) props.get(key), skipComponentProps);
// 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
&& !(view instanceof FlatViewGroup)) {
((View) view).setBackgroundColor(
MapUtils.getIntValue(props, NodeProps.BACKGROUND_COLOR,
Color.TRANSPARENT));
} else if (!handleComponentProps(node, key, props, skipComponentProps)) {
handleCustomProps(controller, view, key, props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void updateExtra(int rootId, int nodeId, @Nullable Object object) {
node.updateExtra(object);
// The gesture set by the child nodes of the flattened text node will recreate
// the host view, so the parent text node must be added to the update list.
if (node.getGestureEnable() && node.getHostView() == null && node.getParent() != null) {
if (node.checkGestureEnable() && node.getHostView() == null && node.getParent() != null) {
addUpdateNodeIfNeeded(rootId, node.getParent());
}
addUpdateNodeIfNeeded(rootId, node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ public View createView(boolean createNow) {
// regular view node.
if (createNow || !mControllerManager.checkFlatten(mClassName)
|| !mParent.getClassName().equals(HippyViewGroupController.CLASS_NAME)
|| getChildCount() > 0
|| getGestureEnable()) {
|| getChildCount() > 0 || checkGestureEnable()) {
mParent.addChildToPendingList(this);
View view = mControllerManager.createView(this, mPoolInUse);
setHostView(view);
Expand Down Expand Up @@ -735,7 +734,7 @@ public void invalidate() {
}
}

public boolean getGestureEnable() {
public boolean checkGestureEnable() {
return mComponent != null && mComponent.getGestureEnable();
}
}

0 comments on commit 2a7402a

Please sign in to comment.