Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
9c37507a
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9c37507a
编写于
4月 30, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: scroll-view
上级
b9214406
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
327 addition
and
330 deletion
+327
-330
packages/uni-components/src/components/scroll-view/index.vue
packages/uni-components/src/components/scroll-view/index.vue
+231
-259
packages/uni-components/src/helpers/scroll.js
packages/uni-components/src/helpers/scroll.js
+25
-0
packages/uni-components/src/mixins/scroller/Friction.js
packages/uni-components/src/mixins/scroller/Friction.js
+11
-11
packages/uni-components/src/mixins/scroller/Scroll.js
packages/uni-components/src/mixins/scroller/Scroll.js
+9
-9
packages/uni-components/src/mixins/scroller/Scroller.js
packages/uni-components/src/mixins/scroller/Scroller.js
+14
-14
packages/uni-components/src/mixins/scroller/Spring.js
packages/uni-components/src/mixins/scroller/Spring.js
+25
-25
packages/uni-components/src/mixins/scroller/index.js
packages/uni-components/src/mixins/scroller/index.js
+12
-12
未找到文件。
packages/uni-components/src/components/scroll-view/index.vue
浏览文件 @
9c37507a
此差异已折叠。
点击以展开。
packages/uni-components/src/helpers/scroll.js
0 → 100644
浏览文件 @
9c37507a
import
{
plusReady
}
from
'
@dcloudio/uni-shared
'
let
webview
let
pullToRefreshStyle
export
function
initScrollBounce
()
{
plusReady
(()
=>
{
if
(
!
webview
)
{
webview
=
plus
.
webview
.
currentWebview
()
}
if
(
!
pullToRefreshStyle
)
{
pullToRefreshStyle
=
(
webview
.
getStyle
()
||
{}).
pullToRefresh
||
{}
}
})
}
export
function
disableScrollBounce
({
disable
})
{
if
(
pullToRefreshStyle
&&
pullToRefreshStyle
.
support
)
{
webview
.
setPullToRefresh
(
Object
.
assign
({},
pullToRefreshStyle
,
{
support
:
!
disable
,
})
)
}
}
packages/uni-components/src/mixins/scroller/Friction.js
浏览文件 @
9c37507a
...
...
@@ -6,15 +6,15 @@ export function Friction(e) {
this
.
_startTime
=
0
}
Friction
.
prototype
.
set
=
function
(
e
,
t
)
{
Friction
.
prototype
.
set
=
function
(
e
,
t
)
{
this
.
_x
=
e
this
.
_v
=
t
this
.
_startTime
=
new
Date
().
getTime
()
}
Friction
.
prototype
.
setVelocityByEnd
=
function
(
e
)
{
Friction
.
prototype
.
setVelocityByEnd
=
function
(
e
)
{
this
.
_v
=
((
e
-
this
.
_x
)
*
this
.
_dragLog
)
/
(
Math
.
pow
(
this
.
_drag
,
100
)
-
1
)
}
Friction
.
prototype
.
x
=
function
(
e
)
{
Friction
.
prototype
.
x
=
function
(
e
)
{
if
(
e
===
undefined
)
{
e
=
(
new
Date
().
getTime
()
-
this
.
_startTime
)
/
1
e3
}
...
...
@@ -26,7 +26,7 @@ Friction.prototype.x = function(e) {
this
.
_dt
=
e
return
this
.
_x
+
(
this
.
_v
*
t
)
/
this
.
_dragLog
-
this
.
_v
/
this
.
_dragLog
}
Friction
.
prototype
.
dx
=
function
(
e
)
{
Friction
.
prototype
.
dx
=
function
(
e
)
{
if
(
e
===
undefined
)
{
e
=
(
new
Date
().
getTime
()
-
this
.
_startTime
)
/
1
e3
}
...
...
@@ -38,30 +38,30 @@ Friction.prototype.dx = function(e) {
this
.
_dt
=
e
return
this
.
_v
*
t
}
Friction
.
prototype
.
done
=
function
()
{
Friction
.
prototype
.
done
=
function
()
{
return
Math
.
abs
(
this
.
dx
())
<
3
}
Friction
.
prototype
.
reconfigure
=
function
(
e
)
{
Friction
.
prototype
.
reconfigure
=
function
(
e
)
{
var
t
=
this
.
x
()
var
n
=
this
.
dx
()
this
.
_drag
=
e
this
.
_dragLog
=
Math
.
log
(
e
)
this
.
set
(
t
,
n
)
}
Friction
.
prototype
.
configuration
=
function
()
{
Friction
.
prototype
.
configuration
=
function
()
{
var
e
=
this
return
[
{
label
:
'
Friction
'
,
read
:
function
()
{
read
:
function
()
{
return
e
.
_drag
},
write
:
function
(
t
)
{
write
:
function
(
t
)
{
e
.
reconfigure
(
t
)
},
min
:
0.001
,
max
:
0.1
,
step
:
0.001
}
step
:
0.001
,
}
,
]
}
packages/uni-components/src/mixins/scroller/Scroll.js
浏览文件 @
9c37507a
...
...
@@ -10,13 +10,13 @@ export function Scroll(extent, friction, spring) {
this
.
_springOffset
=
0
}
Scroll
.
prototype
.
snap
=
function
(
e
,
t
)
{
Scroll
.
prototype
.
snap
=
function
(
e
,
t
)
{
this
.
_springOffset
=
0
this
.
_springing
=
true
this
.
_spring
.
snap
(
e
)
this
.
_spring
.
setEnd
(
t
)
}
Scroll
.
prototype
.
set
=
function
(
e
,
t
)
{
Scroll
.
prototype
.
set
=
function
(
e
,
t
)
{
this
.
_friction
.
set
(
e
,
t
)
if
(
e
>
0
&&
t
>=
0
)
{
this
.
_springOffset
=
0
...
...
@@ -35,7 +35,7 @@ Scroll.prototype.set = function(e, t) {
}
this
.
_startTime
=
new
Date
().
getTime
()
}
Scroll
.
prototype
.
x
=
function
(
e
)
{
Scroll
.
prototype
.
x
=
function
(
e
)
{
if
(
!
this
.
_startTime
)
{
return
0
}
...
...
@@ -59,25 +59,25 @@ Scroll.prototype.x = function(e) {
}
return
t
}
Scroll
.
prototype
.
dx
=
function
(
e
)
{
Scroll
.
prototype
.
dx
=
function
(
e
)
{
var
t
=
0
t
=
this
.
_lastTime
===
e
?
this
.
_lastDx
:
this
.
_springing
?
this
.
_spring
.
dx
(
e
)
:
this
.
_friction
.
dx
(
e
)
?
this
.
_spring
.
dx
(
e
)
:
this
.
_friction
.
dx
(
e
)
this
.
_lastTime
=
e
this
.
_lastDx
=
t
return
t
}
Scroll
.
prototype
.
done
=
function
()
{
Scroll
.
prototype
.
done
=
function
()
{
return
this
.
_springing
?
this
.
_spring
.
done
()
:
this
.
_friction
.
done
()
}
Scroll
.
prototype
.
setVelocityByEnd
=
function
(
e
)
{
Scroll
.
prototype
.
setVelocityByEnd
=
function
(
e
)
{
this
.
_friction
.
setVelocityByEnd
(
e
)
}
Scroll
.
prototype
.
configuration
=
function
()
{
Scroll
.
prototype
.
configuration
=
function
()
{
var
e
=
this
.
_friction
.
configuration
()
e
.
push
.
apply
(
e
,
this
.
_spring
.
configuration
())
return
e
...
...
packages/uni-components/src/mixins/scroller/Scroller.js
浏览文件 @
9c37507a
...
...
@@ -26,12 +26,12 @@ function i(scroll, t, n) {
}
var
o
=
{
id
:
0
,
cancelled
:
false
cancelled
:
false
,
}
i
(
o
,
scroll
,
t
,
n
)
return
{
cancel
:
r
.
bind
(
null
,
o
),
model
:
scroll
model
:
scroll
,
}
}
...
...
@@ -62,7 +62,7 @@ export function Scroller(element, options) {
this
.
updatePosition
()
}
Scroller
.
prototype
.
onTouchStart
=
function
()
{
Scroller
.
prototype
.
onTouchStart
=
function
()
{
this
.
_startPosition
=
this
.
_position
this
.
_lastChangePos
=
this
.
_startPosition
if
(
this
.
_startPosition
>
0
)
{
...
...
@@ -79,7 +79,7 @@ Scroller.prototype.onTouchStart = function() {
}
this
.
updatePosition
()
}
Scroller
.
prototype
.
onTouchMove
=
function
(
x
,
y
)
{
Scroller
.
prototype
.
onTouchMove
=
function
(
x
,
y
)
{
var
startPosition
=
this
.
_startPosition
if
(
this
.
_enableX
)
{
startPosition
+=
x
...
...
@@ -96,7 +96,7 @@ Scroller.prototype.onTouchMove = function(x, y) {
this
.
updatePosition
()
this
.
dispatchScroll
()
}
Scroller
.
prototype
.
onTouchEnd
=
function
(
e
,
r
,
o
)
{
Scroller
.
prototype
.
onTouchEnd
=
function
(
e
,
r
,
o
)
{
if
(
this
.
_enableSnap
&&
this
.
_position
>
-
this
.
_extent
&&
...
...
@@ -178,7 +178,7 @@ Scroller.prototype.onTouchEnd = function(e, r, o) {
}
)
}
Scroller
.
prototype
.
onTransitionEnd
=
function
()
{
Scroller
.
prototype
.
onTransitionEnd
=
function
()
{
this
.
_element
.
style
.
transition
=
''
this
.
_element
.
style
.
webkitTransition
=
''
this
.
_element
.
removeEventListener
(
'
transitionend
'
,
this
.
_onTransitionEnd
)
...
...
@@ -191,7 +191,7 @@ Scroller.prototype.onTransitionEnd = function() {
}
this
.
dispatchScroll
()
}
Scroller
.
prototype
.
snap
=
function
()
{
Scroller
.
prototype
.
snap
=
function
()
{
var
e
=
this
.
_itemSize
var
t
=
this
.
_position
%
e
var
i
=
...
...
@@ -208,7 +208,7 @@ Scroller.prototype.snap = function() {
}
}
}
Scroller
.
prototype
.
scrollTo
=
function
(
e
,
t
)
{
Scroller
.
prototype
.
scrollTo
=
function
(
e
,
t
)
{
if
(
this
.
_animation
)
{
this
.
_animation
.
cancel
()
this
.
_scrolling
=
false
...
...
@@ -230,7 +230,7 @@ Scroller.prototype.scrollTo = function(e, t) {
this
.
_element
.
addEventListener
(
'
transitionend
'
,
this
.
_onTransitionEnd
)
this
.
_element
.
addEventListener
(
'
webkitTransitionEnd
'
,
this
.
_onTransitionEnd
)
}
Scroller
.
prototype
.
dispatchScroll
=
function
()
{
Scroller
.
prototype
.
dispatchScroll
=
function
()
{
if
(
typeof
this
.
_options
.
onScroll
===
'
function
'
&&
Math
.
round
(
this
.
_lastPos
)
!==
Math
.
round
(
this
.
_position
)
...
...
@@ -243,13 +243,13 @@ Scroller.prototype.dispatchScroll = function() {
scrollHeight
:
this
.
_scrollHeight
||
this
.
_element
.
offsetHeight
,
scrollWidth
:
this
.
_scrollWidth
||
this
.
_element
.
offsetWidth
,
offsetHeight
:
this
.
_element
.
parentElement
.
offsetHeight
,
offsetWidth
:
this
.
_element
.
parentElement
.
offsetWidth
}
offsetWidth
:
this
.
_element
.
parentElement
.
offsetWidth
,
}
,
}
this
.
_options
.
onScroll
(
e
)
}
}
Scroller
.
prototype
.
update
=
function
(
e
,
t
,
n
)
{
Scroller
.
prototype
.
update
=
function
(
e
,
t
,
n
)
{
var
i
=
0
var
r
=
this
.
_position
if
(
this
.
_enableX
)
{
...
...
@@ -288,7 +288,7 @@ Scroller.prototype.update = function(e, t, n) {
this
.
_extent
=
i
this
.
_scroll
.
_extent
=
i
}
Scroller
.
prototype
.
updatePosition
=
function
()
{
Scroller
.
prototype
.
updatePosition
=
function
()
{
var
transform
=
''
if
(
this
.
_enableX
)
{
transform
=
'
translateX(
'
+
this
.
_position
+
'
px) translateZ(0)
'
...
...
@@ -300,6 +300,6 @@ Scroller.prototype.updatePosition = function() {
this
.
_element
.
style
.
webkitTransform
=
transform
this
.
_element
.
style
.
transform
=
transform
}
Scroller
.
prototype
.
isScrolling
=
function
()
{
Scroller
.
prototype
.
isScrolling
=
function
()
{
return
this
.
_scrolling
||
this
.
_snapping
}
packages/uni-components/src/mixins/scroller/Spring.js
浏览文件 @
9c37507a
...
...
@@ -15,7 +15,7 @@ export function Spring(e, t, n) {
this
.
_startTime
=
0
}
Spring
.
prototype
.
_solve
=
function
(
e
,
t
)
{
Spring
.
prototype
.
_solve
=
function
(
e
,
t
)
{
var
n
=
this
.
_c
var
i
=
this
.
_m
var
r
=
this
.
_k
...
...
@@ -25,13 +25,13 @@ Spring.prototype._solve = function(e, t) {
const
s
=
e
const
l
=
t
/
(
a
*
e
)
return
{
x
:
function
(
e
)
{
x
:
function
(
e
)
{
return
(
s
+
l
*
e
)
*
Math
.
pow
(
Math
.
E
,
a
*
e
)
},
dx
:
function
(
e
)
{
dx
:
function
(
e
)
{
var
t
=
Math
.
pow
(
Math
.
E
,
a
*
e
)
return
a
*
(
s
+
l
*
e
)
*
t
+
l
*
t
}
}
,
}
}
if
(
o
>
0
)
{
...
...
@@ -40,7 +40,7 @@ Spring.prototype._solve = function(e, t) {
const
l
=
(
t
-
c
*
e
)
/
(
u
-
c
)
const
s
=
e
-
l
return
{
x
:
function
(
e
)
{
x
:
function
(
e
)
{
let
t
let
n
if
(
e
===
this
.
_t
)
{
...
...
@@ -56,7 +56,7 @@ Spring.prototype._solve = function(e, t) {
}
return
s
*
t
+
l
*
n
},
dx
:
function
(
e
)
{
dx
:
function
(
e
)
{
let
t
let
n
if
(
e
===
this
.
_t
)
{
...
...
@@ -71,7 +71,7 @@ Spring.prototype._solve = function(e, t) {
n
=
this
.
_powER2T
=
Math
.
pow
(
Math
.
E
,
u
*
e
)
}
return
s
*
c
*
t
+
l
*
u
*
n
}
}
,
}
}
var
d
=
Math
.
sqrt
(
4
*
i
*
r
-
n
*
n
)
/
(
2
*
i
)
...
...
@@ -82,34 +82,34 @@ Spring.prototype._solve = function(e, t) {
var
l
=
(
t
-
a
*
e
)
/
d
return
{
x
:
function
(
e
)
{
x
:
function
(
e
)
{
return
(
Math
.
pow
(
Math
.
E
,
a
*
e
)
*
(
s
*
Math
.
cos
(
d
*
e
)
+
l
*
Math
.
sin
(
d
*
e
))
)
},
dx
:
function
(
e
)
{
dx
:
function
(
e
)
{
var
t
=
Math
.
pow
(
Math
.
E
,
a
*
e
)
var
n
=
Math
.
cos
(
d
*
e
)
var
i
=
Math
.
sin
(
d
*
e
)
return
t
*
(
l
*
d
*
n
-
s
*
d
*
i
)
+
a
*
t
*
(
l
*
i
+
s
*
n
)
}
}
,
}
}
Spring
.
prototype
.
x
=
function
(
e
)
{
Spring
.
prototype
.
x
=
function
(
e
)
{
if
(
e
===
undefined
)
{
e
=
(
new
Date
().
getTime
()
-
this
.
_startTime
)
/
1
e3
}
return
this
.
_solution
?
this
.
_endPosition
+
this
.
_solution
.
x
(
e
)
:
0
}
Spring
.
prototype
.
dx
=
function
(
e
)
{
Spring
.
prototype
.
dx
=
function
(
e
)
{
if
(
e
===
undefined
)
{
e
=
(
new
Date
().
getTime
()
-
this
.
_startTime
)
/
1
e3
}
return
this
.
_solution
?
this
.
_solution
.
dx
(
e
)
:
0
}
Spring
.
prototype
.
setEnd
=
function
(
e
,
t
,
n
)
{
Spring
.
prototype
.
setEnd
=
function
(
e
,
t
,
n
)
{
if
(
!
n
)
{
n
=
new
Date
().
getTime
()
}
...
...
@@ -136,25 +136,25 @@ Spring.prototype.setEnd = function(e, t, n) {
}
}
}
Spring
.
prototype
.
snap
=
function
(
e
)
{
Spring
.
prototype
.
snap
=
function
(
e
)
{
this
.
_startTime
=
new
Date
().
getTime
()
this
.
_endPosition
=
e
this
.
_solution
=
{
x
:
function
()
{
x
:
function
()
{
return
0
},
dx
:
function
()
{
dx
:
function
()
{
return
0
}
}
,
}
}
Spring
.
prototype
.
done
=
function
(
e
)
{
Spring
.
prototype
.
done
=
function
(
e
)
{
if
(
!
e
)
{
e
=
new
Date
().
getTime
()
}
return
o
(
this
.
x
(),
this
.
_endPosition
,
0.4
)
&&
a
(
this
.
dx
(),
0.4
)
}
Spring
.
prototype
.
reconfigure
=
function
(
e
,
t
,
n
)
{
Spring
.
prototype
.
reconfigure
=
function
(
e
,
t
,
n
)
{
this
.
_m
=
e
this
.
_k
=
t
this
.
_c
=
n
...
...
@@ -163,13 +163,13 @@ Spring.prototype.reconfigure = function(e, t, n) {
this
.
_startTime
=
new
Date
().
getTime
()
}
}
Spring
.
prototype
.
springConstant
=
function
()
{
Spring
.
prototype
.
springConstant
=
function
()
{
return
this
.
_k
}
Spring
.
prototype
.
damping
=
function
()
{
Spring
.
prototype
.
damping
=
function
()
{
return
this
.
_c
}
Spring
.
prototype
.
configuration
=
function
()
{
Spring
.
prototype
.
configuration
=
function
()
{
function
e
(
e
,
t
)
{
e
.
reconfigure
(
1
,
t
,
e
.
damping
())
}
...
...
@@ -183,14 +183,14 @@ Spring.prototype.configuration = function() {
read
:
this
.
springConstant
.
bind
(
this
),
write
:
e
.
bind
(
this
,
this
),
min
:
100
,
max
:
1
e3
max
:
1
e3
,
},
{
label
:
'
Damping
'
,
read
:
this
.
damping
.
bind
(
this
),
write
:
t
.
bind
(
this
,
this
),
min
:
1
,
max
:
500
}
max
:
500
,
}
,
]
}
packages/uni-components/src/mixins/scroller/index.js
浏览文件 @
9c37507a
...
...
@@ -2,11 +2,11 @@ import { Scroller } from './Scroller'
export
default
{
methods
:
{
initScroller
:
function
(
element
,
options
)
{
initScroller
:
function
(
element
,
options
)
{
this
.
_touchInfo
=
{
trackingID
:
-
1
,
maxDy
:
0
,
maxDx
:
0
maxDx
:
0
,
}
this
.
_scroller
=
new
Scroller
(
element
,
options
)
this
.
__handleTouchStart
=
this
.
_handleTouchStart
.
bind
(
this
)
...
...
@@ -14,19 +14,19 @@ export default {
this
.
__handleTouchEnd
=
this
.
_handleTouchEnd
.
bind
(
this
)
this
.
_initedScroller
=
true
},
_findDelta
:
function
(
event
)
{
_findDelta
:
function
(
event
)
{
var
touchInfo
=
this
.
_touchInfo
return
event
.
detail
.
state
===
'
move
'
||
event
.
detail
.
state
===
'
end
'
?
{
x
:
event
.
detail
.
dx
,
y
:
event
.
detail
.
dy
y
:
event
.
detail
.
dy
,
}
:
{
x
:
event
.
screenX
-
touchInfo
.
x
,
y
:
event
.
screenY
-
touchInfo
.
y
y
:
event
.
screenY
-
touchInfo
.
y
,
}
},
_handleTouchStart
:
function
(
e
)
{
_handleTouchStart
:
function
(
e
)
{
var
t
=
this
.
_touchInfo
var
n
=
this
.
_scroller
if
(
n
)
{
...
...
@@ -48,10 +48,10 @@ export default {
if
(
n
.
onTouchStart
)
{
n
.
onTouchStart
()
}
e
vent
.
preventDefault
()
e
.
preventDefault
()
}
},
_handleTouchMove
:
function
(
event
)
{
_handleTouchMove
:
function
(
event
)
{
var
touchInfo
=
this
.
_touchInfo
if
(
touchInfo
.
trackingID
!==
-
1
)
{
event
.
preventDefault
()
...
...
@@ -80,7 +80,7 @@ export default {
}
}
},
_handleTouchEnd
:
function
(
event
)
{
_handleTouchEnd
:
function
(
event
)
{
var
touchInfo
=
this
.
_touchInfo
if
(
touchInfo
.
trackingID
!==
-
1
)
{
event
.
preventDefault
()
...
...
@@ -92,7 +92,7 @@ export default {
var
r
=
touchInfo
.
historyTime
.
length
var
o
=
{
x
:
0
,
y
:
0
y
:
0
,
}
if
(
r
>
2
)
{
for
(
...
...
@@ -121,6 +121,6 @@ export default {
}
}
}
}
}
}
,
}
,
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录