Skip to content

Commit f86ec03

Browse files
author
binniexu
committed
update: app-bar
1 parent 9725552 commit f86ec03

File tree

16 files changed

+9
-164
lines changed

16 files changed

+9
-164
lines changed

miniprogram/app-bar/index.js

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,10 @@
11
// components/app-bar/index.js
2-
3-
const { shared, timing, Easing } = wx.worklet
4-
5-
export const GestureState = {
6-
POSSIBLE: 0,
7-
BEGIN: 1,
8-
ACTIVE: 2,
9-
END: 3,
10-
CANCELLED: 4,
11-
}
12-
13-
export const lerp = function (begin, end, t) {
14-
'worklet'
15-
return begin + (end - begin) * t
16-
}
17-
18-
export const clamp = function (cur, lowerBound, upperBound) {
19-
'worklet'
20-
if (cur > upperBound) return upperBound
21-
if (cur < lowerBound) return lowerBound
22-
return cur
23-
}
24-
25-
const systemInfo = wx.getSystemInfoSync()
26-
const { statusBarHeight, screenHeight, screenWidth, safeArea } = systemInfo
27-
console.info('@@@ systemInfo', systemInfo)
282
Component({
293
properties: {
304

315
},
326

337
data: {
34-
showAppbar: false,
35-
maxCoverSize: 0,
36-
statusBarHeight: 0,
37-
musicCover: 'https://res.wx.qq.com/op_res/Nu9XXzXcXnD1j5EgWQ2ElxNcl1yMvnKypRo4MTbjOv7FC3saigGoOBTZibyESC7EXaClnPYhB6pvfb-IRmso6g'
38-
},
39-
40-
lifetimes: {
41-
attached() {
42-
const progress = shared(0)
43-
const initCoverSize = 60 // 初始图片大小
44-
const pagePadding = 24
45-
const maxCoverSize = screenWidth - 2 * pagePadding
46-
const safeAreaInsetBottom = screenHeight - safeArea.bottom
47-
const isIOS = systemInfo.system.indexOf('iOS') >= 0
48-
this.setData({ statusBarHeight, maxCoverSize })
49-
console.log('attached: ', statusBarHeight, maxCoverSize)
50-
51-
this.applyAnimatedStyle('.cover', () => {
52-
'worklet'
53-
const height = initCoverSize + (maxCoverSize - initCoverSize) * progress.value
54-
console.log('height: ', maxCoverSize, initCoverSize, progress.value)
55-
return {
56-
width: `${height}px`,
57-
height:`${height}px`,
58-
}
59-
})
60-
61-
this.applyAnimatedStyle('.expand-container', () => {
62-
'worklet'
63-
console.log('expand-container: ', maxCoverSize, initCoverSize, progress.value)
64-
const t = progress.value
65-
const maxRadius = 30
66-
const radius = isIOS ? maxRadius * t : 0
67-
const initBarHeight = initCoverSize + 8 * 2 + safeAreaInsetBottom
68-
return {
69-
top: `${(screenHeight - initBarHeight) * (1 - t)}px`,
70-
borderRadius: `${radius}px ${radius}px 0px 0px`
71-
}
72-
})
73-
74-
this.applyAnimatedStyle('.title-wrap', () => {
75-
'worklet'
76-
console.log('title-wrap: ', maxCoverSize, initCoverSize, progress.value)
77-
return {
78-
opacity: 1 - progress.value
79-
}
80-
})
81-
82-
const navBarHeight = statusBarHeight + (isIOS ? 40 : 44)
83-
this.applyAnimatedStyle('.nav-bar', () => {
84-
'worklet'
85-
console.log('nav-bar: ', maxCoverSize, initCoverSize, progress.value)
86-
const t = progress.value
87-
const threshold = 0.8
88-
const opacity = t < threshold ? 0 : (t - threshold) / (1 - threshold)
89-
90-
return {
91-
opacity,
92-
height: `${navBarHeight * progress.value}px`
93-
}
94-
})
95-
96-
this.progress = progress
97-
}
98-
},
99-
100-
methods: {
101-
close() {
102-
this.progress.value = timing(0, {
103-
duration: 250,
104-
easing: Easing.ease
105-
})
106-
},
107-
108-
expand() {
109-
this.progress.value = timing(1, {
110-
duration: 250,
111-
easing: Easing.ease
112-
})
113-
},
114-
115-
handleDragUpdate(delta) {
116-
'worklet'
117-
const curValue = this.progress.value
118-
const newVal = curValue - delta
119-
this.progress.value = clamp(newVal, 0.0, 1.0)
120-
},
121-
122-
handleDragEnd(velocity) {
123-
'worklet'
124-
const t = this.progress.value
125-
let animateForward = false
126-
if (Math.abs(velocity) >= 1) {
127-
animateForward = velocity <= 0
128-
} else {
129-
animateForward = t > 0.7
130-
}
131-
const animationCurve = Easing.out(Easing.ease)
132-
if (animateForward) {
133-
this.progress.value = timing(
134-
1.0, {
135-
duration: 200,
136-
easing: animationCurve,
137-
})
138-
} else {
139-
this.progress.value = timing(
140-
0.0, {
141-
duration: 250,
142-
easing: animationCurve,
143-
})
144-
}
145-
},
146-
147-
handleVerticalDrag(evt) {
148-
'worklet'
149-
if (evt.state === GestureState.ACTIVE) {
150-
const delta = evt.deltaY / screenHeight
151-
this.handleDragUpdate(delta)
152-
} else if (evt.state === GestureState.END) {
153-
const velocity = evt.velocityY / screenHeight
154-
this.handleDragEnd(velocity)
155-
} else if (evt.state === GestureState.CANCELLED) {
156-
this.handleDragEnd(0.0)
157-
}
158-
},
159-
},
160-
8+
showAppbar: false
9+
}
16110
})

miniprogram/assets/arrow-down.png

475 Bytes
Loading

miniprogram/assets/next.png

2.68 KB
Loading

miniprogram/assets/play.png

3.07 KB
Loading

miniprogram/components/app-bar-course/index.wxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- components/app-bar/index.wxml -->
2+
<root-portal style="width: 100vw;height: 100vh;">
23
<vertical-drag-gesture-handler worklet:ongesture="handleVerticalDrag">
34
<view class="expand-container">
45
<!-- 放大模式:nav-bar -->
@@ -51,3 +52,4 @@
5152
</view>
5253
</view>
5354
</vertical-drag-gesture-handler>
55+
</root-portal>

miniprogram/packageComponent/pages/view/root-portal/root-portal.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"usingComponents": {
3-
"navigation-bar": "../../../../components/navigation-bar/index",
43
"popup": "../../../../components/popup/index"
54
},
65
"navigationBarTitleText": "root-portal",

miniprogram/packageSkyline/pages/half-page/half-page/index.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"usingComponents": {
3-
"navigation-bar": "/components/navigation-bar/index",
43
"page-scroll": "/components/page-scroll/index"
54
},
65
"disableScroll": true,

miniprogram/packageSkyline/pages/half-page/scale-page/index.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"usingComponents": {
3-
"navigation-bar": "/components/navigation-bar/index",
43
"page-scroll": "/components/page-scroll/index"
54
},
65
"disableScroll": true,

miniprogram/packageSkyline/pages/share-element/card/index.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"usingComponents": {
3-
"navigation-bar": "/components/navigation-bar/index",
43
"page-scroll": "/components/page-scroll/index"
54
},
65
"disableScroll": true,

miniprogram/packageSkyline/pages/share-element/list/index.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"usingComponents": {
3-
"navigation-bar": "/components/navigation-bar/index",
43
"page-scroll": "/components/page-scroll/index"
54
},
65
"disableScroll": true,

0 commit comments

Comments
 (0)