Skip to content

Commit 554bdb0

Browse files
committed
update: in the user profile page, pin tabbar to the top when appropriate
1 parent b273141 commit 554bdb0

File tree

4 files changed

+66
-21
lines changed

4 files changed

+66
-21
lines changed

src/pages/user/components/topic-list/topic-list.wxss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.topic-item {
44
padding: 30rpx;
5-
margin-bottom: 10rpx;
5+
margin-bottom: 12rpx;
66
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
77
border-radius: 8rpx;
88
}

src/pages/user/user.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Page({
22
data: {
33
bIsReady: false, // 页面是否准备就绪
44
bIsFetchingUserCollectTopicList: false, // 是否正在获取用户收藏话题列表
5+
bAllowScrollY: false, // 是否允许scroll-view滚动
56
nActiveTabIndex: 0,
7+
nTabBarOffsetTop: 0, // tabBar距离顶部的距离
68
aTabBar: [
79
{
810
active: true,
@@ -24,13 +26,45 @@ Page({
2426
this.fnGetUserCollectTopicList(options.name);
2527
}
2628
},
29+
onReady() {
30+
// 更新tabBar距离顶部的距离
31+
this.fnUpdateTabBarOffsetTop();
32+
},
33+
// 监听页面滚动
34+
onPageScroll(e) {
35+
// 判断页面是否滚动带tabBar顶部
36+
if (e.scrollTop >= this.data.nTabBarOffsetTop) {
37+
// 将scroll-view设为可滚动(实现tabBar吸顶效果)
38+
this.setData({
39+
bAllowScrollY: true
40+
});
41+
} else {
42+
// 否则scroll-view设为不可滚动(释放tabBar吸顶效果)
43+
this.data.bAllowScrollY &&
44+
this.setData({
45+
bAllowScrollY: false
46+
});
47+
}
48+
},
2749
// 点击切换tab
2850
fnClickSwitchTab(e) {
2951
let oDataSet = e.currentTarget.dataset;
3052
this.setData({
3153
nActiveTabIndex: oDataSet.index
3254
});
3355
},
56+
// 更新tabBar距离顶部的距离
57+
fnUpdateTabBarOffsetTop() {
58+
let oQuery = wx.createSelectorQuery();
59+
oQuery
60+
.select('.tabbar-wrap')
61+
.boundingClientRect(res => {
62+
this.setData({
63+
nTabBarOffsetTop: res.top
64+
});
65+
})
66+
.exec();
67+
},
3468
// 获取用户收藏话题
3569
fnGetUserCollectTopicList(sUserName) {
3670
// 显示标题栏加载效果

src/pages/user/user.wxml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<view class="user-activity-wrap">
1414
<!-- tabbar -->
1515
<view class="tabbar-wrap ta-c">
16-
<view
16+
<view
1717
class="tab {{index === nActiveTabIndex ? 'tab-active color-white' : 'color-grey'}}"
1818
wx:for="{{aTabBar}}"
1919
wx:key="{{index}}"
@@ -23,22 +23,24 @@
2323
<view>{{item.text}}</view>
2424
</view>
2525
</view>
26-
<view class="topic-list-wrap">
27-
<!-- 最近回复列表 -->
28-
<block wx:if="{{nActiveTabIndex === 0}}">
29-
<topic-list list="{{oUserProfile.recent_replies}}" name="{{oUserProfile.loginname}}"></topic-list>
30-
</block>
31-
<!-- 最新发布话题列表 -->
32-
<block wx:elif="{{nActiveTabIndex === 1}}">
33-
<topic-list list="{{oUserProfile.recent_topics}}" name="{{oUserProfile.loginname}}"></topic-list>
34-
</block>
35-
<!-- 话题收藏列表 -->
36-
<block wx:elif="{{nActiveTabIndex === 2}}">
37-
<topic-list wx:if="{{!bIsFetchingUserCollectTopicList}}" list="{{aUserCollectTopicList}}" name="{{oUserProfile.loginname}}"></topic-list>
38-
<view wx:else class="topic-collection-list ta-c">
39-
<view>正在加载...</view>
40-
</view>
41-
</block>
42-
</view>
26+
<scroll-view class="topic-list-scroll-wrap" scroll-y="{{bAllowScrollY}}">
27+
<view class="topic-list-wrap">
28+
<!-- 最近回复列表 -->
29+
<block wx:if="{{nActiveTabIndex === 0}}">
30+
<topic-list list="{{oUserProfile.recent_replies}}" name="{{oUserProfile.loginname}}"></topic-list>
31+
</block>
32+
<!-- 最新发布话题列表 -->
33+
<block wx:elif="{{nActiveTabIndex === 1}}">
34+
<topic-list list="{{oUserProfile.recent_topics}}" name="{{oUserProfile.loginname}}"></topic-list>
35+
</block>
36+
<!-- 话题收藏列表 -->
37+
<block wx:elif="{{nActiveTabIndex === 2}}">
38+
<topic-list wx:if="{{!bIsFetchingUserCollectTopicList}}" list="{{aUserCollectTopicList}}" name="{{oUserProfile.loginname}}"></topic-list>
39+
<view wx:else class="topic-collection-list ta-c">
40+
<view>正在加载...</view>
41+
</view>
42+
</block>
43+
</view>
44+
</scroll-view>
4345
</view>
4446
</view>

src/pages/user/user.wxss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.user-profile-wrap {
2+
height: 460rpx;
23
padding: 40rpx 30rpx 20rpx 30rpx;
34
background: #333;
5+
box-sizing: border-box;
46
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
57
}
68
.user-avatrl {
@@ -9,31 +11,38 @@
911
height: 200rpx;
1012
}
1113
.user-name {
14+
height: 52rpx;
15+
line-height: 52rpx;
1216
margin-top: 10rpx;
1317
margin-bottom: 10rpx;
1418
}
1519
.user-github-link {
16-
margin-bottom: 60rpx;
20+
margin-bottom: 54rpx;
1721
font-size: 28rpx;
1822
color: #A2A099;
1923
text-decoration: underline;
2024
}
2125
/* 用户动态 */
2226
.tabbar-wrap {
2327
display: flex;
24-
background: #2e3331;
28+
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
2529
}
2630
.tabbar-wrap .tab {
2731
flex: 1;
2832
height: 100rpx;
2933
line-height: 100rpx;
3034
font-size: 28rpx;
35+
font-weight: 500;
3136
border-bottom: 6rpx solid #2e3331;
3237
box-sizing: border-box;
38+
background: #2e3331;
3339
}
3440
.tabbar-wrap .tab.tab-active {
3541
border-color: #80bd01;
3642
}
43+
.topic-list-scroll-wrap {
44+
height: calc(100vh - 100rpx)
45+
}
3746
.topic-list-wrap {
3847
padding: 30rpx 20rpx;
3948
}

0 commit comments

Comments
 (0)