mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
8e65117205
commit
45f4c6c133
@ -50,7 +50,8 @@ VantComponent({
|
|||||||
this.inited = this.inited || active;
|
this.inited = this.inited || active;
|
||||||
this.setData({
|
this.setData({
|
||||||
active,
|
active,
|
||||||
shouldRender: this.inited || !parentData.lazyRender
|
shouldRender: this.inited || !parentData.lazyRender,
|
||||||
|
shouldShow: active || parentData.animated
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
wx:if="{{ shouldRender }}"
|
|
||||||
class="custom-class {{ utils.bem('tab__pane', { active, inactive: !active }) }}"
|
class="custom-class {{ utils.bem('tab__pane', { active, inactive: !active }) }}"
|
||||||
|
style="{{ shouldShow ? '' : 'display: none;' }}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot wx:if="{{ shouldRender }}" />
|
||||||
</view>
|
</view>
|
||||||
|
@ -73,11 +73,14 @@
|
|||||||
|
|
||||||
&__track {
|
&__track {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
&--animated {
|
||||||
|
display: flex;
|
||||||
transition-property: transform;
|
transition-property: transform;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__content {
|
&__content {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -37,7 +37,10 @@ VantComponent({
|
|||||||
sticky: Boolean,
|
sticky: Boolean,
|
||||||
animated: {
|
animated: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
observer: 'setTrack'
|
observer() {
|
||||||
|
this.setTrack();
|
||||||
|
this.children.forEach((child: TrivialInstance) => child.updateRender());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
swipeable: Boolean,
|
swipeable: Boolean,
|
||||||
lineWidth: {
|
lineWidth: {
|
||||||
@ -139,6 +142,10 @@ VantComponent({
|
|||||||
|
|
||||||
const child = this.children[currentIndex];
|
const child = this.children[currentIndex];
|
||||||
|
|
||||||
|
if (!isDef(child)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit(eventName, {
|
this.$emit(eventName, {
|
||||||
index: currentIndex,
|
index: currentIndex,
|
||||||
name: child.getComputedName(),
|
name: child.getComputedName(),
|
||||||
@ -181,9 +188,6 @@ VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldEmitChange = data.currentIndex !== null;
|
|
||||||
this.setData({ currentIndex });
|
|
||||||
|
|
||||||
children.forEach((item: TrivialInstance, index: number) => {
|
children.forEach((item: TrivialInstance, index: number) => {
|
||||||
const active = index === currentIndex;
|
const active = index === currentIndex;
|
||||||
if (active !== item.data.active || !item.inited) {
|
if (active !== item.data.active || !item.inited) {
|
||||||
@ -191,6 +195,13 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (currentIndex === data.currentIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldEmitChange = data.currentIndex !== null;
|
||||||
|
this.setData({ currentIndex });
|
||||||
|
|
||||||
wx.nextTick(() => {
|
wx.nextTick(() => {
|
||||||
this.setLine();
|
this.setLine();
|
||||||
this.setTrack();
|
this.setTrack();
|
||||||
@ -263,11 +274,15 @@ VantComponent({
|
|||||||
setTrack() {
|
setTrack() {
|
||||||
const { animated, duration, currentIndex } = this.data;
|
const { animated, duration, currentIndex } = this.data;
|
||||||
|
|
||||||
|
if (!animated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
trackStyle: `
|
trackStyle: `
|
||||||
transform: translate3d(${-100 * currentIndex}%, 0, 0);
|
transform: translate3d(${-100 * currentIndex}%, 0, 0);
|
||||||
-webkit-transition-duration: ${animated ? duration : 0}s;
|
-webkit-transition-duration: ${duration}s;
|
||||||
transition-duration: ${animated ? duration : 0}s;
|
transition-duration: ${duration}s;
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
bind:touchend="onTouchEnd"
|
bind:touchend="onTouchEnd"
|
||||||
bind:touchcancel="onTouchEnd"
|
bind:touchcancel="onTouchEnd"
|
||||||
>
|
>
|
||||||
<view class="van-tabs__track" style="{{ trackStyle }}">
|
<view class="{{ utils.bem('tabs__track', [{ animated }]) }} van-tabs__track" style="{{ trackStyle }}">
|
||||||
<slot />
|
<slot />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user