Skip to content

Commit

Permalink
Merge branch 'master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomchan-cxj authored Nov 7, 2022
2 parents b85cb11 + 81ff5cb commit d5d1a54
Show file tree
Hide file tree
Showing 18 changed files with 668 additions and 436 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/project_code_lines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "[project] code lines"

on:
workflow_dispatch:
inputs:
git_ref:
description: 'Git Ref'
type: string
default: 'master'
required: true

jobs:
cloc:
runs-on: ubuntu-latest
steps:
- name: Install
run: sudo apt-get install cloc
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.git_ref }}
lfs: true
- name: Cloc
run: |
cloc . --md | sed -E '1,4d' >> $GITHUB_STEP_SUMMARY
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,23 @@ private StaticLayout truncateLayoutWithNumberOfLine(Layout preLayout, int width,
TextPaint measurePaint = new TextPaint();
measurePaint.set(paint);
int start = preLayout.getLineStart(numberOfLines - 1);
CharSequence formerLines = start > 0 ? origin.subSequence(0, start) : null;
boolean newLine = formerLines != null && formerLines.charAt(formerLines.length() - 1) != '\n';
CharSequence formerLines;
if (start > 0) {
boolean newline = origin.charAt(start - 1) != '\n';
if (origin instanceof Spanned) {
formerLines = new SpannableStringBuilder().append(origin, 0, start);
if (newline) {
((SpannableStringBuilder) formerLines).append('\n');
}
} else {
formerLines = new StringBuilder().append(origin, 0, start);
if (newline) {
((StringBuilder) formerLines).append('\n');
}
}
} else {
formerLines = null;
}
CharSequence lastLine;
if (MODE_HEAD.equals(mEllipsizeMode)) {
float formerTextSize = numberOfLines >= 2 ? getLineHeight(preLayout, numberOfLines - 2) : paint.getTextSize();
Expand All @@ -820,7 +835,9 @@ private StaticLayout truncateLayoutWithNumberOfLine(Layout preLayout, int width,
lastLine = ellipsizeTail(origin, measurePaint, width, start, end);
}
// concat everything
truncated = formerLines == null ? lastLine : TextUtils.concat(formerLines, newLine ? "\n" : "", lastLine);
truncated = formerLines == null ? lastLine : formerLines instanceof SpannableStringBuilder
? ((SpannableStringBuilder) formerLines).append(lastLine)
: ((StringBuilder) formerLines).append(lastLine);
}

return buildStaticLayout(truncated, paint, width);
Expand All @@ -833,8 +850,32 @@ private float getLineHeight(Layout layout, int line) {
private CharSequence ellipsizeHead(CharSequence origin, TextPaint paint, int width, int start) {
start = Math.max(start, TextUtils.lastIndexOf(origin, '\n') + 1);
// "…${last line of the rest part}"
CharSequence tmp = TextUtils.concat(ELLIPSIS, origin.subSequence(start, origin.length()));
return TextUtils.ellipsize(tmp, paint, width, TextUtils.TruncateAt.START);
CharSequence tmp;
if (origin instanceof Spanned) {
tmp = new SpannableStringBuilder()
.append(ELLIPSIS)
.append(origin, start, origin.length());
} else {
tmp = new StringBuilder(ELLIPSIS.length() + origin.length() - start)
.append(ELLIPSIS)
.append(origin, start, origin.length());
}
CharSequence result = TextUtils.ellipsize(tmp, paint, width, TextUtils.TruncateAt.START);
if (result instanceof Spannable) {
// make spans cover the "…"
Spannable sp = (Spannable) result;
int spanStart = ELLIPSIS.length();
Object[] spans = sp.getSpans(spanStart, spanStart, Object.class);
for (Object span : spans) {
if (!(span instanceof ImageSpan) && sp.getSpanStart(span) == spanStart) {
int flag = sp.getSpanFlags(span);
int spanEnd = sp.getSpanEnd(span);
sp.removeSpan(span);
sp.setSpan(span, 0, spanEnd, flag);
}
}
}
return result;
}

private CharSequence ellipsizeMiddle(CharSequence origin, TextPaint paint, int width, int start) {
Expand All @@ -843,7 +884,18 @@ private CharSequence ellipsizeMiddle(CharSequence origin, TextPaint paint, int w
rightStart = TextUtils.lastIndexOf(origin, '\n') + 1;
assert leftEnd < rightStart;
// "${first line of the rest part}…${last line of the rest part}"
CharSequence tmp = TextUtils.concat(origin.subSequence(start, leftEnd), ELLIPSIS, origin.subSequence(rightStart, origin.length()));
CharSequence tmp;
if (origin instanceof Spanned) {
tmp = new SpannableStringBuilder()
.append(origin, start, leftEnd)
.append(ELLIPSIS)
.append(origin, rightStart, origin.length());
} else {
tmp = new StringBuilder(leftEnd - start + ELLIPSIS.length() + origin.length() - rightStart)
.append(origin, start, leftEnd)
.append(ELLIPSIS)
.append(origin, rightStart, origin.length());
}
final int[] outRange = new int[2];
TextUtils.EllipsizeCallback callback = new TextUtils.EllipsizeCallback() {
@Override
Expand All @@ -857,9 +909,13 @@ public void ellipsized(int l, int r) {
int pos0 = leftEnd - start;
int pos1 = pos0 + ELLIPSIS.length();
if (outRange[0] > pos0) {
line = new SpannableStringBuilder(tmp).replace(pos0, outRange[1], ELLIPSIS);
line = tmp instanceof SpannableStringBuilder
? ((SpannableStringBuilder) tmp).replace(pos0, outRange[1], ELLIPSIS)
: ((StringBuilder) tmp).replace(pos0, outRange[1], ELLIPSIS);
} else if (outRange[1] < pos1) {
line = new SpannableStringBuilder(tmp).replace(outRange[0], pos1, ELLIPSIS);
line = tmp instanceof SpannableStringBuilder
? ((SpannableStringBuilder) tmp).replace(outRange[0], pos1, ELLIPSIS)
: ((StringBuilder) tmp).replace(outRange[0], pos1, ELLIPSIS);
}
}
return line;
Expand All @@ -876,7 +932,14 @@ private CharSequence ellipsizeTail(CharSequence origin, TextPaint paint, int wid
--end;
}
// "${first line of the rest part}…"
CharSequence tmp = TextUtils.concat(origin.subSequence(start, end), ELLIPSIS);
CharSequence tmp;
if (origin instanceof Spanned) {
tmp = new SpannableStringBuilder()
.append(origin, start, end).append(ELLIPSIS);
} else {
tmp = new StringBuilder(end - start + ELLIPSIS.length())
.append(origin, start, end).append(ELLIPSIS);
}
return TextUtils.ellipsize(tmp, paint, width, TextUtils.TruncateAt.END);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ private CommonBackgroundDrawable getBackGround() {
}

protected void setTextColor(int textColor) {
if (mLayout != null && mLayout.getText() instanceof SpannableStringBuilder) {
SpannableStringBuilder textSpan = (SpannableStringBuilder) mLayout.getText();
if (mLayout != null && mLayout.getText() instanceof Spannable) {
Spannable textSpan = (Spannable) mLayout.getText();
HippyForegroundColorSpan[] spans = textSpan
.getSpans(0, mLayout.getText().length(), HippyForegroundColorSpan.class);
boolean hasSpans = false;
Expand Down
2 changes: 1 addition & 1 deletion docs/en-us/hippy-vue/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ At present, the basic `Universal`, `Type`, `ID`, `Class`, `Grouping` selectors h

## Scoped & Attribute

> `2.15.0` support Vue `scoped` style.
> `2.15.0` support Vue `scoped` style, `2.15.2` support to merge styles on root element of child component.
> `2.15.1` support `Attribute` selector and Vue `deep` selector.
Expand Down
2 changes: 1 addition & 1 deletion docs/hippy-vue/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HippyVue 提供了 `beforeLoadStyle` 的 Vue options 勾子函数,供开发者

## Scoped & Attribute

> `2.15.0` 版本增加支持 Vue `scoped` 样式能力
> `2.15.0` 版本增加支持 Vue `scoped` 样式能力, `2.15.2` 支持子组件根元素样式合并
> `2.15.1` 版本增加支持 `Attribute` 选择器和 Vue `deep` 深度选择器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
v-if="loaded"
class="async-com-wrapper"
>
<AsyncComponentFromLocal />
<AsyncComponentFromLocal class="async-component-outer-local" />
<AsyncComponentFromHttp />
</div>
</div>
Expand Down Expand Up @@ -55,7 +55,11 @@ export default {
};
</script>

<style>
<style scoped>
.async-component-outer-local {
height: 200px;
width: 300px;
}
#demo-dynamicimport {
flex: 1;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div id="asynccomponent">
<div class="async-component-local">
<text class="async-txt">
我是本地异步组件
</text>
Expand All @@ -15,18 +15,16 @@ export default {
};
</script>

<style>
#asynccomponent {
<style scoped>
.async-component-local {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
height: 200px;
width: 300px;
background-color: #50ca92;
border-radius: 10px;
margin-bottom: 10px;
background-color: #50ca92;
}
.async-txt{
color: black;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
v-if="loaded"
class="async-com-wrapper"
>
<AsyncComponentFromLocal />
<AsyncComponentFromLocal class="async-component-outer-local"/>
<AsyncComponentFromHttp />
</div>
</div>
Expand Down Expand Up @@ -67,7 +67,11 @@ export default defineComponent({
});
</script>

<style>
<style scoped>
.async-component-outer-local {
height: 200px;
width: 300px;
}
#demo-dynamicimport {
flex: 1;
display: flex;
Expand All @@ -92,6 +96,6 @@ export default defineComponent({
line-height: 40px;
}
.async-com-wrapper {
marginTop: 20px
margin-top: 20px
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div
id="async-component-local"
class="local-local"
class="async-component-local"
>
<p class="async-txt">
我是本地异步组件
Expand All @@ -17,15 +16,13 @@ export default defineComponent({
});
</script>

<style>
#async-component-local {
<style scoped>
.async-component-local {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
height: 200px;
width: 300px;
background-color: #50ca92;
border-radius: 10px;
margin-bottom: 10px;
Expand Down
Loading

0 comments on commit d5d1a54

Please sign in to comment.