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

fix(notice-bar): resolve console error #2470

Merged
merged 3 commits into from
Dec 19, 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
16 changes: 15 additions & 1 deletion src/input/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@
import path from 'path';
import simulate from 'miniprogram-simulate';

const mapper = ['align', 'banner', 'base', 'bordered', 'custom', 'label', 'layout', 'maxlength', 'prefix', 'size', 'special', 'status', 'suffix'];
const mapper = [
'align',
'banner',
'base',
'bordered',
'custom',
'label',
'layout',
'maxlength',
'prefix',
'size',
'special',
'status',
'suffix',
];

describe('Input', () => {
mapper.forEach((demoName) => {
Expand Down
1 change: 1 addition & 0 deletions src/notice-bar/notice-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
}

&__content--vertical {
display: block;
height: @notice-bar-line-height;
line-height: @notice-bar-line-height;

Expand Down
48 changes: 25 additions & 23 deletions src/notice-bar/notice-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,31 @@ export default class NoticeBar extends SuperComponent {
const warpID = `.${name}__content-wrap`;
const nodeID = `.${name}__content`;
getAnimationFrame(this, () => {
Promise.all([getRect(this, nodeID), getRect(this, warpID)]).then(([nodeRect, wrapRect]) => {
const { marquee } = this.properties;

if (nodeRect == null || wrapRect == null || !nodeRect.width || !wrapRect.width) {
return;
}

if (marquee || wrapRect.width < nodeRect.width) {
const speeding = marquee.speed || 50;
const delaying = marquee.delay || 0;
const animationDuration = ((wrapRect.width + nodeRect.width) / speeding) * 1000;
const firstAnimationDuration = (nodeRect.width / speeding) * 1000;
this.setData({
wrapWidth: Number(wrapRect.width),
nodeWidth: Number(nodeRect.width),
animationDuration: animationDuration,
delay: delaying,
loop: marquee.loop - 1,
firstAnimationDuration: firstAnimationDuration,
});
marquee.loop !== 0 && this.startScrollAnimation(true);
}
});
Promise.all([getRect(this, nodeID), getRect(this, warpID)])
.then(([nodeRect, wrapRect]) => {
const { marquee } = this.properties;

if (nodeRect == null || wrapRect == null || !nodeRect.width || !wrapRect.width) {
return;
}

if (marquee || wrapRect.width < nodeRect.width) {
const speeding = marquee.speed || 50;
const delaying = marquee.delay || 0;
const animationDuration = ((wrapRect.width + nodeRect.width) / speeding) * 1000;
const firstAnimationDuration = (nodeRect.width / speeding) * 1000;
this.setData({
wrapWidth: Number(wrapRect.width),
nodeWidth: Number(nodeRect.width),
animationDuration: animationDuration,
delay: delaying,
loop: marquee.loop - 1,
firstAnimationDuration: firstAnimationDuration,
});
marquee.loop !== 0 && this.startScrollAnimation(true);
}
})
.catch(() => {});
});
},

Expand Down
2 changes: 1 addition & 1 deletion src/notice-bar/notice-bar.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
circular="true"
interval="{{interval}}"
display-multiple-items="1"
class="{{classPrefix}}__content--vertical"
class="{{classPrefix}}__content {{classPrefix}}__content--vertical"
bindchange="onChange"
>
<block wx:for="{{content}}" wx:key="index">
Expand Down
13 changes: 12 additions & 1 deletion src/rate/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
import path from 'path';
import simulate from 'miniprogram-simulate';

const mapper = ['action', 'base', 'color', 'count', 'custom', 'custom-prefix', 'show-text', 'size', 'special', 'un-filled'];
const mapper = [
'action',
'base',
'color',
'count',
'custom',
'custom-prefix',
'show-text',
'size',
'special',
'un-filled',
];

describe('Rate', () => {
mapper.forEach((demoName) => {
Expand Down