-
Notifications
You must be signed in to change notification settings - Fork 930
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android, ios): nested rich text support vertical alignment setti…
…ng (#2521) * feat(ios): rich text images support vertical alignment setting * feat(ios): add rich text's vertical align offset support * feat(ios): margin support for nested component in richText * feat(android): add `verticalAlign` for `Image` in rich text * fix(android): backgroundColor not working in nested text * feat(android): add properties for `Image` in rich text `tintColor`, `backgroundColor`, `margin` and `padding` * feat(ios): text in rich text support verticalAlign setting * feat(android): verticalAlign for textnode * feat(android): add backgroundColor in legacy mode * fix(android): baseline align offset wrong * feat(ios): support nested text verticalAlign style setting * fix(android): verticalAlign for boringLayout * chore(docs): add verticalAlign docs * chore(ios): make verticalAlign default value baseline * feat(vue): update text demo * chore(ios): add verticalAlign and update demo * chore(docs): update verticalAlign minimum supported version --------- Co-authored-by: iPel <pel20121221@gmail.com> Co-authored-by: luomy <ozonelmy@163.com> Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
- Loading branch information
1 parent
dcd479f
commit df4d7ea
Showing
23 changed files
with
1,616 additions
and
444 deletions.
There are no files selected for viewing
525 changes: 229 additions & 296 deletions
525
android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/HippyImageSpan.java
Large diffs are not rendered by default.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/HippyVerticalAlignSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* 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.mtt.hippy.dom.node; | ||
|
||
import android.graphics.Paint.FontMetricsInt; | ||
import android.text.TextPaint; | ||
import android.text.style.CharacterStyle; | ||
|
||
/** | ||
* A span that change the vertical align of the text. <strong>Caution:</strong> It depends on the | ||
* TextPaint's FontMetrics, which may be changed by other span, so this span should be added with a | ||
* lowest priority. | ||
*/ | ||
public class HippyVerticalAlignSpan extends CharacterStyle { | ||
|
||
private final FontMetricsInt mReusableFontMetricsInt = new FontMetricsInt(); | ||
private final String mVerticalAlign; | ||
private int mLineTop; | ||
private int mLineBottom; | ||
|
||
public HippyVerticalAlignSpan(String verticalAlign) { | ||
this.mVerticalAlign = verticalAlign; | ||
} | ||
|
||
public void setLineMetrics(int top, int bottom) { | ||
mLineTop = top; | ||
mLineBottom = bottom; | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) { | ||
if (mLineTop != 0 || mLineBottom != 0) { | ||
final FontMetricsInt fmi = mReusableFontMetricsInt; | ||
switch (mVerticalAlign) { | ||
case TextNode.V_ALIGN_TOP: | ||
tp.getFontMetricsInt(fmi); | ||
tp.baselineShift = mLineTop - fmi.top; | ||
break; | ||
case TextNode.V_ALIGN_MIDDLE: | ||
tp.getFontMetricsInt(fmi); | ||
tp.baselineShift = (mLineTop + mLineBottom - fmi.top - fmi.bottom) / 2; | ||
break; | ||
case TextNode.V_ALIGN_BOTTOM: | ||
tp.getFontMetricsInt(fmi); | ||
tp.baselineShift = mLineBottom - fmi.bottom; | ||
break; | ||
case TextNode.V_ALIGN_BASELINE: | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.