Skip to content

Commit

Permalink
fix: swipe-aciton、accordion 兼容支付宝
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyongming committed Sep 14, 2024
1 parent b6c97d8 commit 15a096b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/taro-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro-ui3",
"version": "3.3.1-beta.0",
"version": "3.3.1-beta.1",
"description": "UI KIT for Taro",
"module": "dist/index.esm.js",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-ui/src/components/accordion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class AtAccordion extends React.Component<
private getSelectorStr(type: string): string {
const { componentId } = this.state
const { parentSelector } = this.props
return (parentSelector ? `${parentSelector} >>> ` : '') + `#${type}-${componentId}`
return (parentSelector && process.env.TARO_ENV === 'weapp' ? `${parentSelector} >>> ` : '') + `#${type}-${componentId}`
}

private toggleWithAnimation(): void {
Expand Down
68 changes: 39 additions & 29 deletions packages/taro-ui/src/components/swipe-action/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class AtSwipeAction extends React.Component<
public static propTypes: InferProps<AtSwipeActionProps>

private moveX: number
private delayTime: NodeJS.Timeout

public constructor(props: AtSwipeActionProps) {
super(props)
Expand Down Expand Up @@ -53,6 +54,7 @@ export default class AtSwipeAction extends React.Component<
const { _isOpened, maxOffsetSize } = this.state

if (isOpened !== _isOpened) {
clearTimeout(this.delayTime);
this.moveX = isOpened ? 0 : maxOffsetSize
this._reset(!!isOpened) // TODO: Check behavior
}
Expand All @@ -64,7 +66,7 @@ export default class AtSwipeAction extends React.Component<
private getSelectorStr(type: string): string {
const { componentId } = this.state
const { parentSelector } = this.props
return (parentSelector ? `${parentSelector} >>> ` : '') + `#${type}-${componentId}`
return (parentSelector && process.env.TARO_ENV === 'weapp' ? `${parentSelector} >>> ` : '') + `#${type}-${componentId}`
}

/**
Expand Down Expand Up @@ -102,29 +104,32 @@ export default class AtSwipeAction extends React.Component<
})
}

private _reset(isOpened: boolean): void {
private _reset(isOpened: boolean, then: () => void = () => { }): void {
this.setState({
offsetSize: this.moveX
}, () => {
if (isOpened) {
const { maxOffsetSize } = this.state
if (process.env.TARO_ENV === 'jd') {
this.setState({
_isOpened: true,
offsetSize: -maxOffsetSize + 0.01
})
this.moveX = 0;
Taro.nextTick(() => {
if (isOpened) {
const { maxOffsetSize } = this.state
if (process.env.TARO_ENV === 'jd') {
this.setState({
_isOpened: true,
offsetSize: -maxOffsetSize + 0.01
}, then)
} else {
this.setState({
_isOpened: true,
offsetSize: -maxOffsetSize
}, then)
}
} else {
this.setState({
_isOpened: true,
offsetSize: -maxOffsetSize
})
offsetSize: 0,
_isOpened: false
}, then)
}
} else {
this.setState({
offsetSize: 0,
_isOpened: false
})
}
})
})
}

Expand Down Expand Up @@ -153,20 +158,26 @@ export default class AtSwipeAction extends React.Component<
onClick(item, index, event)
}
if (autoClose) {
this._reset(false) // TODO: Check behavior
this.handleClosed(event)
this._reset(false, () => {
this.handleClosed(event)
}) // TODO: Check behavior
}
}

onTouchEnd = e => {
const { maxOffsetSize } = this.state
if (Math.abs(this.moveX) < maxOffsetSize / 2) {
this._reset(false)
this.handleClosed(e)
} else {
this._reset(true)
this.handleOpened(e)
}
clearTimeout(this.delayTime);
this.delayTime = setTimeout(() => {
const { maxOffsetSize } = this.state
if (Math.abs(this.moveX) < maxOffsetSize / 2) {
this._reset(false, () => {
this.handleClosed(e)
})
} else {
this._reset(true, () => {
this.handleOpened(e)
})
}
}, 10);
}

onChange = e => {
Expand All @@ -175,7 +186,6 @@ export default class AtSwipeAction extends React.Component<

public render(): JSX.Element {
const { componentId, maxOffsetSize, eleWidth, offsetSize } = this.state

const { options, disabled } = this.props
const rootClass = classNames('at-swipe-action', this.props.className)

Expand Down

0 comments on commit 15a096b

Please sign in to comment.