Skip to content

Commit

Permalink
支持ts fix #36 #42 #39 #40
Browse files Browse the repository at this point in the history
  • Loading branch information
cunjinli committed Sep 20, 2019
1 parent 0ecf43b commit e213d05
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ npm install --save miniprogram-recycle-view

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

​ 页面必须通过 Component 构造器定义,页面引入了`miniprogram-recycle-view`包之后,会在 wx 对象下面新增接口`createRecycleContext`函数创建`RecycleContext`对象来管理 recycle-view 定义的的数据,`createRecycleContext`接收类型为1个 Object 的参数,Object 参数的每一个 key 的介绍如下:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniprogram-recycle-view",
"version": "0.1.2",
"version": "0.1.3",
"description": "miniprogram custom component",
"main": "miniprogram_dist/index.js",
"scripts": {
Expand Down
18 changes: 9 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ declare namespace recycleContext {
}

interface RecycleContext<T> {
append(list: T[], callback?: () => void): void
appendList(list: T[], callback?: () => void): void
splice(begin: number, deleteCount: number, appendList: T[], callback?: () => void): void;
updateList(beginIndex: number, list: T[], callback?: () => void): void
update(beginIndex: number, list: T[], callback?: () => void): void
destroy(): void
forceUpdate(callback: () => void, reinitSlot: boolean): void
append(list: T[], callback?: () => void): RecycleContext<T>
appendList(list: T[], callback?: () => void): RecycleContext<T>
splice(begin: number, deleteCount: number, appendList: T[], callback?: () => void): RecycleContext<T>;
updateList(beginIndex: number, list: T[], callback?: () => void): RecycleContext<T>
update(beginIndex: number, list: T[], callback?: () => void): RecycleContext<T>
destroy(): RecycleContext<T>
forceUpdate(callback: () => void, reinitSlot: boolean): RecycleContext<T>
getBoundingClientRect(index: number | undefined): position | position[]
getScrollTop(): number;
transformRpx(rpx: number, addPxSuffix?: string): number;
getViewportItems(inViewportPx: number): T[]
getList(): T[]
}
}
declare function recycleContext<T>(op: recycleContext.options<T>): recycleContext.RecycleContext<T>
declare function createRecycleContext<T>(op: recycleContext.options<T>): recycleContext.RecycleContext<T>

export = recycleContext;
export = createRecycleContext;
5 changes: 4 additions & 1 deletion src/recycle-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ Component({
const scrollLeft = e.detail.scrollLeft
const scrollTop = e.detail.scrollTop
const scrollDistance = Math.abs(scrollTop - this._lastScrollTop)

if (!force && (Math.abs(scrollTop - pos.top) < pos.height * 1.5)) {
this._log('【not exceed height')
return
}
this._lastScrollTop = scrollTop
const SHOW_SCREENS = this.data.screen // 固定4屏幕
this._log('SHOW_SCREENS', SHOW_SCREENS, scrollTop)
Expand Down
2 changes: 1 addition & 1 deletion src/recycle-view.wxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--components/recycle-view/recycle-view.wxml-->
<view bindtouchstart='_beginToScroll' style="height:{{useInPage ? totalHeight : height}}px;width:{{width}}px;transform:translateZ(0);-webkit-transform:translateZ(0);" id="content" class="wrap">
<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}}">
<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}}">
<view style="position: absolute;z-index:1;width:100%;left: 0;top: 0;opacity: 0;visibility: hidden;">
<slot name="itemsize"></slot>
</view>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/recycle-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ RecycleContext.prototype.getTotalHeight = function () {
// 返回完整的列表数据
RecycleContext.prototype.getList = function () {
if (!recycleData[this.id]) {
return [];
return []
}
return recycleData[this.id].list
}
Expand Down

0 comments on commit e213d05

Please sign in to comment.