Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swipe-cell): enable hidden on the beginning #2283

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/wechat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const getObserver = (context, selector: string) => {
return new Promise((resolve, reject) => {
wx.createIntersectionObserver(context)
.relativeToViewport()
.observe(selector, (res) => {
resolve(res);
});
});
};
32 changes: 1 addition & 31 deletions src/swipe-cell/_example/swipe-cell.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@
Page({
data: {
right: [
{
text: '编辑',
className: 't-swipe-cell-demo-btn edit-btn',
},
{
text: '删除',
className: 't-swipe-cell-demo-btn delete-btn',
},
],
},

onActionClick({ detail }) {
wx.showToast({ title: `你点击了${detail.text}`, icon: 'none' });
},

onDelete() {
wx.showToast({ title: '你点击了删除', icon: 'none' });
},
onEdit() {
wx.showToast({ title: '你点击了编辑', icon: 'none' });
},
onFavor() {
wx.showToast({ title: '你点击了收藏', icon: 'none' });
},
onChoice() {
wx.showToast({ title: '你点击了选择', icon: 'none' });
},
});
Page({});
7 changes: 7 additions & 0 deletions src/swipe-cell/swipe-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
import { getRect } from '../common/utils';
import { getObserver } from '../common/wechat';

let ARRAY: WechatMiniprogram.Component.TrivialInstance[] = [];

Expand Down Expand Up @@ -49,6 +50,12 @@ export default class SwiperCell extends SuperComponent {
setSwipeWidth() {
Promise.all([getRect(this, `${ContainerClass}__left`), getRect(this, `${ContainerClass}__right`)]).then(
([leftRect, rightRect]) => {
if (leftRect.width === 0 && rightRect.width === 0 && !this._hasObserved) {
this._hasObserved = true;
getObserver(this, `.${name}`).then(() => {
this.setSwipeWidth();
});
}
this.setData({
leftWidth: leftRect.width,
rightWidth: rightRect.width,
Expand Down
Loading