Skip to content

Commit

Permalink
fix(notice-bar): resolve console error (#2470)
Browse files Browse the repository at this point in the history
* fix(notice-bar): resolve console error

* fix(notice-bar): cannot retrieve the 't-notice-bar__content' node
  • Loading branch information
betavs authored Dec 19, 2023
1 parent 9cdae57 commit 7f9346c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 deletions.
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

0 comments on commit 7f9346c

Please sign in to comment.