Skip to content

Commit d015ebc

Browse files
fix: noticebar 垂直滚动初始化时,无法及时展示元素信息 (jdf2e#1576)
Co-authored-by: oasis-cloud <suanbanren@foxmail.com>
1 parent 44fe96b commit d015ebc

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/packages/noticebar/demo.taro.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ const NoticeBarDemo = () => {
6565

6666
<h2>{translated.scrollable}</h2>
6767
<NoticeBar content={translated.textShort} scrollable />
68-
<br />
68+
<br style={{ display: 'block', height: '10px' }} />
6969
<NoticeBar content={translated.text} scrollable={false} />
7070

7171
<h2>{translated.mode}</h2>
7272
<NoticeBar closeable onClick={hello}>
7373
{translated.text}
7474
</NoticeBar>
75-
<br />
75+
<br style={{ display: 'block', height: '10px' }} />
7676
<NoticeBar closeable rightIcon={<CircleClose />} onClick={hello}>
7777
{translated.text}
7878
</NoticeBar>
79-
<br />
79+
<br style={{ display: 'block', height: '10px' }} />
8080
<NoticeBar
8181
leftIcon={
8282
<img

src/packages/noticebar/noticebar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333

3434
.left-icon {
35+
display: flex;
3536
height: $noticebar-left-icon-width;
3637
min-width: $noticebar-left-icon-width;
3738
margin: $noticebar-lefticon-margin;

src/packages/noticebar/noticebar.taro.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export const NoticeBar: FunctionComponent<
119119
childCount,
120120
}
121121
}, [children])
122+
// 滚动消息的总高度
122123
let trackSize = childCount * Number(height)
124+
// 设置最小偏移量(最后一条的偏移位置)
123125
const minOffset = (() => {
124126
if (rect) {
125127
const base = isVertical ? rect.height : rect.width
@@ -134,9 +136,7 @@ export const NoticeBar: FunctionComponent<
134136
scrollList.current = [].concat(childs)
135137
} else {
136138
scrollList.current = [].concat(list)
137-
setTimeout(() => {
138-
startRollEasy()
139-
}, Number(duration))
139+
startRollEasy()
140140
}
141141
} else {
142142
initScrollWrap(content)
@@ -297,11 +297,9 @@ export const NoticeBar: FunctionComponent<
297297

298298
useEffect(() => {
299299
if (isVertical && children) {
300-
setTimeout(() => {
301-
init()
302-
stopAutoPlay()
303-
autoplay()
304-
}, 300)
300+
init()
301+
stopAutoPlay()
302+
autoplay()
305303
}
306304
}, [children, container?.current])
307305

@@ -366,6 +364,9 @@ export const NoticeBar: FunctionComponent<
366364

367365
const getStyle = (moveOffset = offset) => {
368366
const target = innerRef.current
367+
if (!target) {
368+
return
369+
}
369370
let _offset = 0
370371
// 容器高度-元素高度
371372
const val = (rect?.height || 0) - height

src/packages/noticebar/noticebar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ export const NoticeBar: FunctionComponent<
360360

361361
const getStyle = (moveOffset = offset) => {
362362
const target = innerRef.current
363+
if (!target) {
364+
return
365+
}
363366
let _offset = 0
364367
// 容器高度-元素高度
365368
const val = rect.height - height

0 commit comments

Comments
 (0)