Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): support fakeBold for text node #3612

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.tencent.renderer.component.ComponentController;
import com.tencent.renderer.component.FlatViewGroup;
import com.tencent.renderer.component.image.ImageComponentController;
import com.tencent.renderer.component.text.TextComponentController;
import com.tencent.renderer.node.TextRenderNode;
import com.tencent.renderer.node.TextVirtualNode;
import com.tencent.renderer.utils.MapUtils;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class ControllerUpdateManger<T> {
@Nullable
private ImageComponentController mImageComponentController;
@Nullable
private TextComponentController mTextComponentController;
@Nullable
private T mCustomPropsController;

static {
Expand Down Expand Up @@ -120,6 +123,7 @@ public boolean checkComponentProperty(@NonNull String key) {
private static void initComponentPropsMap() {
collectMethodHolder(ComponentController.class, sComponentPropsMethodMap);
collectMethodHolder(ImageComponentController.class, sComponentPropsMethodMap);
collectMethodHolder(TextComponentController.class, sComponentPropsMethodMap);
Method[] methods = TextVirtualNode.class.getMethods();
for (Method method : methods) {
HippyControllerProps controllerProps = method
Expand Down Expand Up @@ -282,6 +286,12 @@ private Object getComponentController(Class<?> cls) {
}
return mImageComponentController;
}
if (cls == TextComponentController.class) {
if (mTextComponentController == null) {
mTextComponentController = new TextComponentController();
}
return mTextComponentController;
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,19 @@ public void createNode(final int rootId, @NonNull List<Object> nodeList)
// If the node has a virtual parent, no need to create corresponding render node,
// but need set the node data to the parent, for render node snapshot.
createNodeTaskList.add(
() -> mRenderManager.onCreateVirtualNode(rootId, nodeId, pid, nodeIndex, node));
() -> mRenderManager.onCreateVirtualNode(rootId, nodeId, pid, nodeIndex,
node));
} else {
createNodeTaskList.add(
() -> mRenderManager.createNode(rootId, nodeId, nodePid, nodeIndex, className,
() -> mRenderManager.createNode(rootId, nodeId, nodePid, nodeIndex,
className,
props));
// Because image and text may be rendered flat, it is not necessary to pre create a view.
if (!className.equals(HippyImageViewController.CLASS_NAME) && !className.equals(
HippyTextViewController.CLASS_NAME)) {
createViewTaskList.add(
() -> mRenderManager.preCreateView(rootId, nodeId, nodePid, className, props));
() -> mRenderManager.preCreateView(rootId, nodeId, nodePid, className,
props));
}
}
}
Expand Down Expand Up @@ -552,8 +555,9 @@ public void updateNode(final int rootId, @NonNull List<Object> nodeList)
VirtualNode parent = mVirtualNodeManager.checkVirtualParent(rootId, nodeId);
if (parent != null) {
final int pid = parent.getId();
taskList.add(() -> mRenderManager.onUpdateVirtualNode(rootId, nodeId, pid, diffProps,
delProps));
taskList.add(
() -> mRenderManager.onUpdateVirtualNode(rootId, nodeId, pid, diffProps,
delProps));
} else {
taskList.add(() -> mRenderManager.updateNode(rootId, nodeId, diffProps, delProps));
}
Expand Down Expand Up @@ -676,6 +680,8 @@ public void updateEventListener(final int rootId, @NonNull List<Object> eventLis
throw new NativeRenderException(INVALID_NODE_DATA_ERR,
TAG + ": updateEventListener: invalid negative id=" + nodeId);
}
LogUtils.d(TAG,
"updateEventListener: id " + nodeId + ", eventProps " + eventProps + "\n ");
mVirtualNodeManager.updateEventListener(rootId, nodeId, eventProps);
taskList.add(() -> mRenderManager.updateEventListener(rootId, nodeId, eventProps));
}
Expand Down Expand Up @@ -716,7 +722,8 @@ public void callUIFunction(final int rootId, final int nodeId, final long callba
// Because call ui function will not follow with end batch,
// can be directly post to the UI thread do execution.
UIThreadUtils.runOnUiThread(
() -> mRenderManager.dispatchUIFunction(rootId, nodeId, functionName, params, promise));
() -> mRenderManager.dispatchUIFunction(rootId, nodeId, functionName, params,
promise));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ public TextDrawable ensureTextDrawable() {
return mTextDrawable;
}

public void setFakeBoldText(boolean isFakeBoldText) {
ensureTextDrawable().setFakeBoldText(isFakeBoldText);
}

public void setGestureEnable(boolean enable) {
if (enable) {
setComponentFlag(FLAG_GESTURE_ENABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public class TextDrawable extends Drawable {

private boolean mTextBold = false;
private boolean mFakeBoldText = false;
private int mCustomTextColor = 0;
private float mLeftPadding;
private float mRightPadding;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void draw(@NonNull Canvas canvas) {
canvas.translate(getTextLayoutOffsetX(), getTextLayoutOffsetY());
Paint paint = mLayout.getPaint();
if (paint != null) {
paint.setFakeBoldText(mTextBold);
paint.setFakeBoldText(mFakeBoldText);
}
mLayout.draw(canvas);
canvas.restore();
Expand All @@ -133,6 +133,10 @@ public void setAlpha(int alpha) {

}

public void setFakeBoldText(boolean isFakeBoldText) {
mFakeBoldText = isFakeBoldText;
}

@Override
public void setColorFilter(ColorFilter colorFilter) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* 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.component.text;

import androidx.annotation.NonNull;
import com.tencent.mtt.hippy.annotation.HippyControllerProps;
import com.tencent.renderer.component.Component;

public class TextComponentController {

@SuppressWarnings("unused")
@HippyControllerProps(name = "fakeBold", defaultType = HippyControllerProps.BOOLEAN)
public void setUrl(@NonNull Component component, boolean isFakeBold) {
component.setFakeBoldText(isFakeBold);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.tencent.renderer.component.ComponentController;
import com.tencent.renderer.component.image.ImageComponent;
import com.tencent.renderer.component.image.ImageComponentController;
import com.tencent.renderer.component.text.TextComponentController;
import com.tencent.renderer.utils.DiffUtils;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -174,7 +175,7 @@ public NativeRender getNativeRender() {

@Nullable
public Component ensureComponentIfNeeded(Class<?> cls) {
if (cls == ComponentController.class) {
if (cls == ComponentController.class || cls == TextComponentController.class) {
if (mComponent == null) {
mComponent = new Component(this);
}
Expand Down
Loading