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 padding for TextInput #3611

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 @@ -50,6 +50,7 @@
import com.tencent.renderer.NativeRender;
import com.tencent.renderer.NativeRenderException;
import com.tencent.renderer.NativeRendererManager;
import com.tencent.renderer.component.text.TextRenderSupplier;
import com.tencent.renderer.node.TextVirtualNode;
import com.tencent.renderer.utils.ArrayUtils;

Expand Down Expand Up @@ -87,14 +88,14 @@ protected View createViewImpl(Context context) {
protected void updateExtra(@NonNull View view, Object object) {
super.updateExtra(view, object);

// if (object instanceof TextExtra) {
// TextExtra textExtra = (TextExtra) object;
// HippyTextInput hippyTextInput = (HippyTextInput) view;
// hippyTextInput.setPadding((int) Math.ceil(textExtra.mLeftPadding),
// (int) Math.ceil(textExtra.mTopPadding),
// (int) Math.ceil(textExtra.mRightPadding),
// (int) Math.ceil(textExtra.mBottomPadding));
// }
if (object instanceof TextRenderSupplier) {
TextRenderSupplier supplier = (TextRenderSupplier) object;
HippyTextInput hippyTextInput = (HippyTextInput) view;
hippyTextInput.setPadding((int) Math.ceil(supplier.leftPadding),
(int) Math.ceil(supplier.topPadding),
(int) Math.ceil(supplier.rightPadding),
(int) Math.ceil(supplier.bottomPadding));
}
}

@HippyControllerProps(name = NodeProps.FONT_SIZE, defaultType = HippyControllerProps.NUMBER, defaultNumber = 14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ public void updateExtra(@Nullable Object object) {
component.setTextLayout(object);
setNodeFlag(FLAG_UPDATE_EXTRA);
}
mExtra = object;
}

public boolean isDeleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public boolean updateEventListener(int rootId, int nodeId, @NonNull Map<String,
public TextRenderSupplier updateLayout(int rootId, int nodeId, float width,
Map<String, Object> layoutInfo) {
VirtualNode node = getVirtualNode(rootId, nodeId);
if (!(node instanceof TextVirtualNode) || node.mParent != null) {
if (!(node instanceof TextVirtualNode || node instanceof TextInputVirtualNode) || node.mParent != null) {
return null;
}
float leftPadding = 0;
Expand All @@ -159,12 +159,17 @@ public TextRenderSupplier updateLayout(int rootId, int nodeId, float width,
// just ignore this exception
LogUtils.w(TAG, "VirtualNode updateLayout get padding exception: " + e.getMessage());
}
Layout layout = ((TextVirtualNode) node)
.createLayout((width - leftPadding - rightPadding), FlexMeasureMode.EXACTLY);
// Layout has update here, not need to rebuild in end batch, so remove node ref from mUpdateNodes.
List<VirtualNode> updateNodes = mUpdateNodes.get(rootId);
if (updateNodes != null) {
updateNodes.remove(node);
final Layout layout;
if (node instanceof TextVirtualNode) {
layout = ((TextVirtualNode) node)
.createLayout((width - leftPadding - rightPadding), FlexMeasureMode.EXACTLY);
// Layout has update here, not need to rebuild in end batch, so remove node ref from mUpdateNodes.
List<VirtualNode> updateNodes = mUpdateNodes.get(rootId);
if (updateNodes != null) {
updateNodes.remove(node);
}
} else {
layout = null;
}
return new TextRenderSupplier(layout, leftPadding, topPadding,
rightPadding, bottomPadding);
Expand Down