Skip to content

Commit 92b32e4

Browse files
authored
fix: 微信端noticebar循环失效 (#1218)
1 parent 297f532 commit 92b32e4

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

compiled/alipay/src/NoticeBar/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ Component(
9898
marqueeStyle,
9999
});
100100
},
101+
101102
onTransitionEnd() {
102103
const loop = getValueFromProps(this, 'loop');
103104
const trailing = 200;
104105
if (loop) {
105-
setTimeout(() => {
106+
const timer = setTimeout(() => {
106107
this.measureText((state) => {
107108
this.resetMarquee.call(this, state);
108109
});
110+
clearTimeout(timer);
109111
}, trailing);
110112
}
111113
},
@@ -130,7 +132,6 @@ Component(
130132
const { enableMarquee } = this.props;
131133
// 这里更新处理的原因是防止notice内容在动画过程中发生改变。
132134
if (enableMarquee) {
133-
console.log(enableMarquee);
134135
this.measureText((state) => {
135136
this.startMarquee.call(this, state);
136137
});

compiled/wechat/src/NoticeBar/index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,25 @@ Component(NoticeBarDefaultProps, {
6767
}
6868
},
6969
startMarquee: function (state) {
70+
var _this = this;
7071
var loop = getValueFromProps(this, 'loop');
7172
var leading = 500;
7273
var duration = state.duration, overflowWidth = state.overflowWidth, viewWidth = state.viewWidth;
7374
var marqueeScrollWidth = overflowWidth;
7475
if (loop) {
7576
marqueeScrollWidth = overflowWidth + viewWidth;
77+
// 微信的view标签不支持onTransitionEnd,需要这里实现循环
78+
var trailing = 200;
79+
clearTimeout(this.timer);
80+
this.timer = setTimeout(function () {
81+
_this.measureText(function (state) {
82+
_this.resetMarquee.call(_this, state);
83+
_this.measureText(function (state) {
84+
_this.startMarquee.call(_this, state);
85+
});
86+
});
87+
clearTimeout(_this.timer);
88+
}, trailing + duration * 1000);
7689
}
7790
var newMarqueeStyle = "transform: translate3d(".concat(-marqueeScrollWidth, "px, 0, 0); transition: ").concat(duration, "s all linear ").concat(typeof leading === 'number' ? "".concat(leading / 1000, "s") : '0s', ";");
7891
this.setData({
@@ -129,18 +142,6 @@ Component(NoticeBarDefaultProps, {
129142
marqueeStyle: marqueeStyle,
130143
});
131144
},
132-
onTransitionEnd: function () {
133-
var _this = this;
134-
var loop = getValueFromProps(this, 'loop');
135-
var trailing = 200;
136-
if (loop) {
137-
setTimeout(function () {
138-
_this.measureText(function (state) {
139-
_this.resetMarquee.call(_this, state);
140-
});
141-
}, trailing);
142-
}
143-
},
144145
}, {
145146
show: true,
146147
marqueeStyle: '',

src/NoticeBar/index.axml.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export default (
6666
style={`${marqueeStyle} display: ${
6767
enableMarquee ? 'inline-block' : 'block'
6868
}`}
69+
// #if ALIPAY
6970
onTransitionEnd="onTransitionEnd"
71+
// #endif
7072
>
7173
<Slot />
7274
</View>

src/NoticeBar/index.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ Component(
4747
let marqueeScrollWidth = overflowWidth;
4848
if (loop) {
4949
marqueeScrollWidth = overflowWidth + viewWidth;
50+
/// #if WECHAT
51+
// 微信的view标签不支持onTransitionEnd,需要这里实现循环
52+
const trailing = 200;
53+
clearTimeout(this.timer);
54+
this.timer = setTimeout(() => {
55+
this.measureText((state) => {
56+
this.resetMarquee.call(this, state);
57+
this.measureText((state) => {
58+
this.startMarquee.call(this, state);
59+
});
60+
});
61+
clearTimeout(this.timer);
62+
}, trailing + duration * 1000);
63+
/// #endif
5064
}
5165
const newMarqueeStyle = `transform: translate3d(${-marqueeScrollWidth}px, 0, 0); transition: ${duration}s all linear ${
5266
typeof leading === 'number' ? `${leading / 1000}s` : '0s'
@@ -100,17 +114,21 @@ Component(
100114
marqueeStyle,
101115
});
102116
},
117+
118+
/// #if ALIPAY
103119
onTransitionEnd() {
104120
const loop = getValueFromProps(this, 'loop');
105121
const trailing = 200;
106122
if (loop) {
107-
setTimeout(() => {
123+
const timer = setTimeout(() => {
108124
this.measureText((state) => {
109125
this.resetMarquee.call(this, state);
110126
});
127+
clearTimeout(timer);
111128
}, trailing);
112129
}
113130
},
131+
/// #endif
114132
},
115133
{
116134
show: true,
@@ -133,7 +151,6 @@ Component(
133151
const { enableMarquee } = this.props;
134152
// 这里更新处理的原因是防止notice内容在动画过程中发生改变。
135153
if (enableMarquee) {
136-
console.log(enableMarquee);
137154
this.measureText((state) => {
138155
this.startMarquee.call(this, state);
139156
});

0 commit comments

Comments
 (0)