Skip to content

Commit e213d05

Browse files
author
cunjinli
committed
支持ts fix #36 #42 #39 #40
1 parent 0ecf43b commit e213d05

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ npm install --save miniprogram-recycle-view
141141

142142
`typescript`支持,使用如下方式引入
143143
```typescript
144-
import * as recycleContext from 'miniprogram-recycle-view';
144+
import * as createRecycleContext from 'miniprogram-recycle-view';
145145
```
146146

147147
​ 页面必须通过 Component 构造器定义,页面引入了`miniprogram-recycle-view`包之后,会在 wx 对象下面新增接口`createRecycleContext`函数创建`RecycleContext`对象来管理 recycle-view 定义的的数据,`createRecycleContext`接收类型为1个 Object 的参数,Object 参数的每一个 key 的介绍如下:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-recycle-view",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "miniprogram custom component",
55
"main": "miniprogram_dist/index.js",
66
"scripts": {

src/index.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ declare namespace recycleContext {
2626
}
2727

2828
interface RecycleContext<T> {
29-
append(list: T[], callback?: () => void): void
30-
appendList(list: T[], callback?: () => void): void
31-
splice(begin: number, deleteCount: number, appendList: T[], callback?: () => void): void;
32-
updateList(beginIndex: number, list: T[], callback?: () => void): void
33-
update(beginIndex: number, list: T[], callback?: () => void): void
34-
destroy(): void
35-
forceUpdate(callback: () => void, reinitSlot: boolean): void
29+
append(list: T[], callback?: () => void): RecycleContext<T>
30+
appendList(list: T[], callback?: () => void): RecycleContext<T>
31+
splice(begin: number, deleteCount: number, appendList: T[], callback?: () => void): RecycleContext<T>;
32+
updateList(beginIndex: number, list: T[], callback?: () => void): RecycleContext<T>
33+
update(beginIndex: number, list: T[], callback?: () => void): RecycleContext<T>
34+
destroy(): RecycleContext<T>
35+
forceUpdate(callback: () => void, reinitSlot: boolean): RecycleContext<T>
3636
getBoundingClientRect(index: number | undefined): position | position[]
3737
getScrollTop(): number;
3838
transformRpx(rpx: number, addPxSuffix?: string): number;
3939
getViewportItems(inViewportPx: number): T[]
4040
getList(): T[]
4141
}
4242
}
43-
declare function recycleContext<T>(op: recycleContext.options<T>): recycleContext.RecycleContext<T>
43+
declare function createRecycleContext<T>(op: recycleContext.options<T>): recycleContext.RecycleContext<T>
4444

45-
export = recycleContext;
45+
export = createRecycleContext;

src/recycle-view.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ Component({
243243
const scrollLeft = e.detail.scrollLeft
244244
const scrollTop = e.detail.scrollTop
245245
const scrollDistance = Math.abs(scrollTop - this._lastScrollTop)
246-
246+
if (!force && (Math.abs(scrollTop - pos.top) < pos.height * 1.5)) {
247+
this._log('【not exceed height')
248+
return
249+
}
247250
this._lastScrollTop = scrollTop
248251
const SHOW_SCREENS = this.data.screen // 固定4屏幕
249252
this._log('SHOW_SCREENS', SHOW_SCREENS, scrollTop)

src/recycle-view.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--components/recycle-view/recycle-view.wxml-->
22
<view bindtouchstart='_beginToScroll' style="height:{{useInPage ? totalHeight : height}}px;width:{{width}}px;transform:translateZ(0);-webkit-transform:translateZ(0);" id="content" class="wrap">
3-
<scroll-view bindscroll="_scrollViewDidScroll" class="content" style='height:100%;position: relative;' scroll-y="{{useInPage ? false : true}}" scroll-x="{{scrollY}}" upper-threshold="{{upperThreshold}}" lower-threshold="{{lowerThreshold}}" scroll-top="{{innerScrollTop}}" scroll-into-view="{{innerScrollIntoView}}" scroll-with-animation="{{scrollWithAnimation}}" bindscrolltoupper="_scrollToUpper" bindscrolltolower="_scrollToLower" enable-back-to-top="{{enableBackToTop}}" throttle="{{throttle}}">
3+
<scroll-view bindscroll="_scrollViewDidScroll" class="content" style='height:100%;position: relative;' scroll-y="{{useInPage ? false : scrollY}}" scroll-x="{{false}}" upper-threshold="{{upperThreshold}}" lower-threshold="{{lowerThreshold}}" scroll-top="{{innerScrollTop}}" scroll-into-view="{{innerScrollIntoView}}" scroll-with-animation="{{scrollWithAnimation}}" bindscrolltoupper="_scrollToUpper" bindscrolltolower="_scrollToLower" enable-back-to-top="{{enableBackToTop}}" throttle="{{throttle}}">
44
<view style="position: absolute;z-index:1;width:100%;left: 0;top: 0;opacity: 0;visibility: hidden;">
55
<slot name="itemsize"></slot>
66
</view>

src/utils/recycle-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ RecycleContext.prototype.getTotalHeight = function () {
575575
// 返回完整的列表数据
576576
RecycleContext.prototype.getList = function () {
577577
if (!recycleData[this.id]) {
578-
return [];
578+
return []
579579
}
580580
return recycleData[this.id].list
581581
}

0 commit comments

Comments
 (0)