Skip to content

Comments

chore(swipe): 适配鸿蒙、小程序、H5#2326

Merged
xiaoyatong merged 19 commits intodev-harmonyfrom
feat/swipe-standard
Jun 19, 2024
Merged

chore(swipe): 适配鸿蒙、小程序、H5#2326
xiaoyatong merged 19 commits intodev-harmonyfrom
feat/swipe-standard

Conversation

@oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Jun 6, 2024

Conflicts:

packages/nutui-taro-demo-rn/scripts/taro/adapted.js<!--

非常感谢您的贡献 维护者审核通过后会合并。
请确保填写以下 pull request 的信息,谢谢!~
-->

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新特性

    • 添加了 Swipe 组件到导出模块列表中。
  • Bug 修复

    • 更新 useTouch 功能以更稳健地处理触摸事件。
  • 样式

    • CSS 类名和属性调整,提升样式一致性和功能性。
  • 文档

    • 添加了多个示例文件,展示了 Swipe 组件的不同用法,包括删除、收藏、移动和查看相似项功能。

Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、只提取了 taro 的 demo
2、web h5 表现:
image
3、rn 表现:
image

@coderabbitai
Copy link

coderabbitai bot commented Jun 18, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

这次更新引入了一个新的组件 Swipe,用于实现滑动操作,并展示了多个示例文件 demo1.tsxdemo9.tsx,展示如何在 React 项目中使用 Swipe 组件。文件还包括与滑动组件相关的样式调整和导出修改,增强了组件的功能和使用场景。

Changes

文件路径 变更摘要
...demo-rn/scripts/taro/adapted.js 添加了 'swipe' 组件到导出模块中
...demo-rn/src/app.config.ts 文件开头添加了一个空行
...swipe/demos/taro/demo*.tsx 引入了多个示例文件,展示了 Swipe 组件在不同场景下的应用
src/packages/swipe/swipe.harmony.css 重命名了 CSS 类并调整了它们的属性
src/packages/swipe/swipe.scss 调整了 .nut-swipe 类以及相关类的样式
src/packages/swipe/swipe.taro.tsx 调整了导入顺序、状态初始化、事件处理函数以及样式
src/utils/use-touch.ts 更新了 useTouch 函数以更强健地处理触摸事件并引入 getTouch 函数

Poem

在代码的树林里,我们漫步,
容纳滑动微风,凭空跃起。
组件在手,左右滑动,
React 派对,乐趣满满。
你的项目,如兔子般轻盈,
每次更新,皆如新春。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Outside diff range and nitpick comments (4)
src/packages/swipe/demos/taro/demo9.tsx (1)

7-39: 代码实现了平台特定的渲染逻辑,这是一个好的实践。不过,建议在harmonyAndRn函数中添加注释,说明它是如何判断不同平台的,以提高代码的可读性。

src/packages/swipe/demos/taro/demo8.tsx (1)

5-59: 这段代码中注释掉了 Dialog 组件的使用,可能是因为当前版本不需要这个功能,或者是在进行调试。如果这段代码不再需要,建议彻底移除以减少代码冗余。如果将来可能会使用,可以在代码旁边添加 TODO 注释,说明未来可能的用途。

src/packages/swipe/swipe.taro.tsx (2)

Line range hint 78-93: 使用 useStateuseReady 钩子来设置和获取根元素宽度。这里的异步使用方法可能会导致竞态条件,建议使用状态回调函数来确保状态的正确更新。

- setTimeout(() => getWidth())
+ setTimeout(() => getWidth(), 0) // 确保异步操作的正确序列

258-259: 在 useEffect 中,添加了环境检测以决定是否执行某些 DOM 操作。这种环境依赖的代码可能会导致组件的可移植性问题。建议将环境相关的逻辑封装到独立的模块或服务中。

Comment on lines +4 to +58
const App = () => {
const [showDialog, setShowDialog] = useState(false)
const refDom = useRef<SwipeInstance>(null)
const pRef = useRef('left')
const beforeClose = (postion: string) => {
pRef.current = postion
setShowDialog(true)
}

return (
<>
<Swipe
ref={refDom}
beforeClose={beforeClose}
leftAction={
<Button
shape="square"
type="success"
style={{ alignSelf: 'stretch', height: 46 }}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
</>
}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
<Dialog
visible={showDialog}
title="提示"
onConfirm={() => {
refDom.current && refDom.current.close()
setShowDialog(false)
}}
>
{pRef.current === 'left' ? '确定选择吗?' : '确定删除吗?'}
</Dialog>
</>
)
}
export default App
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此代码段中,Swipe 组件被用于实现滑动操作,并通过 Dialog 组件来确认操作。代码逻辑清晰,但在行 49-50 使用了非空断言操作符(!),这可能在 refDom.currentnull 时引发运行时错误。

- refDom.current && refDom.current.close()
+ refDom.current?.close()

此修改使用了可选链(Optional Chaining),能够更安全地处理可能为 null 的情况。

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const App = () => {
const [showDialog, setShowDialog] = useState(false)
const refDom = useRef<SwipeInstance>(null)
const pRef = useRef('left')
const beforeClose = (postion: string) => {
pRef.current = postion
setShowDialog(true)
}
return (
<>
<Swipe
ref={refDom}
beforeClose={beforeClose}
leftAction={
<Button
shape="square"
type="success"
style={{ alignSelf: 'stretch', height: 46 }}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
</>
}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
<Dialog
visible={showDialog}
title="提示"
onConfirm={() => {
refDom.current && refDom.current.close()
setShowDialog(false)
}}
>
{pRef.current === 'left' ? '确定选择吗?' : '确定删除吗?'}
</Dialog>
</>
)
}
export default App
const App = () => {
const [showDialog, setShowDialog] = useState(false)
const refDom = useRef<SwipeInstance>(null)
const pRef = useRef('left')
const beforeClose = (postion: string) => {
pRef.current = postion
setShowDialog(true)
}
return (
<>
<Swipe
ref={refDom}
beforeClose={beforeClose}
leftAction={
<Button
shape="square"
type="success"
style={{ alignSelf: 'stretch', height: 46 }}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
</>
}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
<Dialog
visible={showDialog}
title="提示"
onConfirm={() => {
refDom.current?.close()
setShowDialog(false)
}}
>
{pRef.current === 'left' ? '确定选择吗?' : '确定删除吗?'}
</Dialog>
</>
)
}
export default App
Tools
Biome

[error] 49-50: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

rightRect.width,
JSON.stringify(rightRect)
)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onTouchStart 事件处理函数中,对左右滑块进行尺寸获取和设置。这部分代码与 getWidth 函数中的代码重复,建议封装成独立的函数以避免代码重复。

- const leftRect = await getRectByTaro(leftWrapper.current)
- leftRect && setActionWidth((v: any) => ({ ...v, left: leftRect.width }))
- if (rightWrapper.current) {
-   const rightRect = await getRectByTaro(rightWrapper.current)
-   rightRect && setActionWidth((v: any) => ({ ...v, right: rightRect.width }))
+ updateActionWidth(leftWrapper, rightWrapper)

Committable suggestion was skipped due to low confidence.

Comment on lines +5 to +69
const ViewNode = (text: string, style: any) => {
return (
<div
style={{
display: 'flex',
width: 60,
height: 104,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
...style,
}}
>
<Del style={{ marginBottom: 8 }} />
<>{text}</>
</div>
)
}

const App = () => {
return (
<>
<Swipe
style={{ height: 104 }}
rightAction={
<div
style={{
display: 'flex',
flexDirection: 'row',
width: 240,
height: 104,
fontSize: 12,
}}
>
<>
{ViewNode('设置常买', {
background: '#F8F8F8',
color: '#1A1A1A',
})}
{ViewNode('移入收藏', {
background: '#ffcc00',
color: '#FFF',
})}
{ViewNode('看相似', {
background: '#FF860D',
color: '#FFF',
})}
{ViewNode('删除', {
background: '#FA2C19',
color: '#FFF',
})}
</>
</div>
}
>
<Cell
title="左滑"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码展示了如何使用 Swipe 组件实现多个滑动操作按钮。ViewNode 函数用于生成具有特定样式和文本的节点。代码整体上实现了预期功能,但在行 19 使用了不必要的 Fragment。可以简化如下:

- <>{text}</>
+ text

这样的修改可以去除不必要的 React Fragment,简化 DOM 结构。

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const ViewNode = (text: string, style: any) => {
return (
<div
style={{
display: 'flex',
width: 60,
height: 104,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
...style,
}}
>
<Del style={{ marginBottom: 8 }} />
<>{text}</>
</div>
)
}
const App = () => {
return (
<>
<Swipe
style={{ height: 104 }}
rightAction={
<div
style={{
display: 'flex',
flexDirection: 'row',
width: 240,
height: 104,
fontSize: 12,
}}
>
<>
{ViewNode('设置常买', {
background: '#F8F8F8',
color: '#1A1A1A',
})}
{ViewNode('移入收藏', {
background: '#ffcc00',
color: '#FFF',
})}
{ViewNode('看相似', {
background: '#FF860D',
color: '#FFF',
})}
{ViewNode('删除', {
background: '#FA2C19',
color: '#FFF',
})}
</>
</div>
}
>
<Cell
title="左滑"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App
const ViewNode = (text: string, style: any) => {
return (
<div
style={{
display: 'flex',
width: 60,
height: 104,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
...style,
}}
>
<Del style={{ marginBottom: 8 }} />
{text}
</div>
)
}
const App = () => {
return (
<>
<Swipe
style={{ height: 104 }}
rightAction={
<div
style={{
display: 'flex',
flexDirection: 'row',
width: 240,
height: 104,
fontSize: 12,
}}
>
<>
{ViewNode('设置常买', {
background: '#F8F8F8',
color: '#1A1A1A',
})}
{ViewNode('移入收藏', {
background: '#ffcc00',
color: '#FFF',
})}
{ViewNode('看相似', {
background: '#FF860D',
color: '#FFF',
})}
{ViewNode('删除', {
background: '#FA2C19',
color: '#FFF',
})}
</>
</div>
}
>
<Cell
title="左滑"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App
Tools
Biome

[error] 19-19: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

Comment on lines 5 to 7
if (harmony()) return transform(value)
if (rn()) return value
return `${value}px`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此逻辑调整确保了在不同平台下,像素转换能够正确处理。建议添加单元测试以验证这些条件分支。

是否需要帮助编写这部分的单元测试?

Comment on lines +227 to +231
style={{
...(side === 'left'
? { left: Number(`${-actionWidth.current.left}`) }
: {}),
}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置动态样式时,使用了展开操作符和条件表达式。这种方法虽然灵活,但可能会对性能产生影响,特别是在频繁更新样式的场景下。建议预先计算样式或使用 useMemo 钩子来优化性能。

- style={{
-   ...(side === 'left' ? { left: Number(`${-actionWidth.current.left}`) } : {}),
- }}
+ style={getSwipeStyle(side, actionWidth)}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
style={{
...(side === 'left'
? { left: Number(`${-actionWidth.current.left}`) }
: {}),
}}
style={getSwipeStyle(side, actionWidth)}

Comment on lines 6 to 38
const App = () => {
const [shouldCatchMove, setShouldCatchMove] = useState(false)

return (
<>
<View catchMove={shouldCatchMove}>
<Swipe
rightAction={
<Button
type="primary"
shape="square"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
onTouchEnd={(e) => {
setShouldCatchMove(false)
}}
onTouchMove={(e) => {
setShouldCatchMove(true)
}}
>
<Cell
title="左滑删除"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</View>
</>
)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体代码逻辑清晰,组件结构合理。但建议将触摸事件处理逻辑封装为一个独立的函数,以增强代码的可读性和可维护性。

- onTouchEnd={(e) => {
-   setShouldCatchMove(false)
- }}
- onTouchMove={(e) => {
-   setShouldCatchMove(true)
- }}
+ const handleTouchMove = (e) => {
+   setShouldCatchMove(e.type === 'touchmove')
+ }
+ onTouchEnd={handleTouchMove}
+ onTouchMove={handleTouchMove}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const App = () => {
const [shouldCatchMove, setShouldCatchMove] = useState(false)
return (
<>
<View catchMove={shouldCatchMove}>
<Swipe
rightAction={
<Button
type="primary"
shape="square"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
onTouchEnd={(e) => {
setShouldCatchMove(false)
}}
onTouchMove={(e) => {
setShouldCatchMove(true)
}}
>
<Cell
title="左滑删除"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</View>
</>
)
}
const App = () => {
const [shouldCatchMove, setShouldCatchMove] = useState(false)
const handleTouchMove = (e) => {
setShouldCatchMove(e.type === 'touchmove')
}
return (
<>
<View catchMove={shouldCatchMove}>
<Swipe
rightAction={
<Button
type="primary"
shape="square"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
onTouchEnd={handleTouchMove}
onTouchMove={handleTouchMove}
>
<Cell
title="左滑删除"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</View>
</>
)
}

Comment on lines 6 to 43
const App = () => {
const openRef = useRef<SwipeInstance>(null)
return (
<>
<Swipe
ref={openRef}
rightAction={
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
>
<Cell
title="点击下方按钮打开或关闭"
radius={0}
style={{ margin: 0, alignSelf: 'stretch', boxShadow: 'none' }}
/>
</Swipe>
<View style={{ display: 'flex', flexDirection: 'row' }}>
<Button
onClick={() => openRef.current?.open('right')}
type="primary"
size="small"
>
<Text style={{ color: '#ffffff' }}>打开</Text>
</Button>
<Button size="small" onClick={() => openRef.current?.close()}>
关闭
</Button>
</View>
</>
)
}
export default App
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

组件使用了SwipeInstance来控制滑动组件的状态,这是一种有效的方法。但是,建议将按钮点击事件处理逻辑封装成函数,而不是直接在JSX中实现,以提高代码的可维护性。

- onClick={() => openRef.current?.open('right')}
- onClick={() => openRef.current?.close()}
+ const handleOpen = () => openRef.current?.open('right')
+ const handleClose = () => openRef.current?.close()
+ onClick={handleOpen}
+ onClick={handleClose}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const App = () => {
const openRef = useRef<SwipeInstance>(null)
return (
<>
<Swipe
ref={openRef}
rightAction={
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
>
<Cell
title="点击下方按钮打开或关闭"
radius={0}
style={{ margin: 0, alignSelf: 'stretch', boxShadow: 'none' }}
/>
</Swipe>
<View style={{ display: 'flex', flexDirection: 'row' }}>
<Button
onClick={() => openRef.current?.open('right')}
type="primary"
size="small"
>
<Text style={{ color: '#ffffff' }}>打开</Text>
</Button>
<Button size="small" onClick={() => openRef.current?.close()}>
关闭
</Button>
</View>
</>
)
}
export default App
const App = () => {
const openRef = useRef<SwipeInstance>(null)
const handleOpen = () => openRef.current?.open('right')
const handleClose = () => openRef.current?.close()
return (
<>
<Swipe
ref={openRef}
rightAction={
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: pxTransform(46) }}
>
删除
</Button>
}
>
<Cell
title="点击下方按钮打开或关闭"
radius={0}
style={{ margin: 0, alignSelf: 'stretch', boxShadow: 'none' }}
/>
</Swipe>
<View style={{ display: 'flex', flexDirection: 'row' }}>
<Button
onClick={handleOpen}
type="primary"
size="small"
>
<Text style={{ color: '#ffffff' }}>打开</Text>
</Button>
<Button size="small" onClick={handleClose}>
关闭
</Button>
</View>
</>
)
}
export default App

Comment on lines +4 to +54
const App = () => {
const handleChange = () => {
Toast.show({ title: 'title' })
}
return (
<>
<Swipe
leftAction={
<Button
shape="square"
type="success"
style={{
alignSelf: 'stretch',
height: 46,
}}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
<Button
shape="square"
type="info"
style={{ alignSelf: 'stretch', height: 46 }}
>
收藏
</Button>
</>
}
onActionClick={handleChange}
onOpen={() => Toast.show({ title: '打开' })}
onClose={() => Toast.show({ title: '关闭' })}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

组件结构清晰,使用了多个滑动操作和Toast通知。建议将onActionClick, onOpen, 和 onClose的逻辑封装成独立的函数,以提高代码的可维护性和可读性。

- onActionClick={handleChange}
- onOpen={() => Toast.show({ title: '打开' })}
- onClose={() => Toast.show({ title: '关闭' })}
+ const handleActionClick = () => {
+   handleChange();
+   Toast.show({ title: '操作' });
+ }
+ const handleOpen = () => Toast.show({ title: '打开' });
+ const handleClose = () => Toast.show({ title: '关闭' });
+ onActionClick={handleActionClick}
+ onOpen={handleOpen}
+ onClose={handleClose}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const App = () => {
const handleChange = () => {
Toast.show({ title: 'title' })
}
return (
<>
<Swipe
leftAction={
<Button
shape="square"
type="success"
style={{
alignSelf: 'stretch',
height: 46,
}}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
<Button
shape="square"
type="info"
style={{ alignSelf: 'stretch', height: 46 }}
>
收藏
</Button>
</>
}
onActionClick={handleChange}
onOpen={() => Toast.show({ title: '打开' })}
onClose={() => Toast.show({ title: '关闭' })}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App
const App = () => {
const handleChange = () => {
Toast.show({ title: 'title' })
}
const handleActionClick = () => {
handleChange();
Toast.show({ title: '操作' });
}
const handleOpen = () => Toast.show({ title: '打开' });
const handleClose = () => Toast.show({ title: '关闭' });
return (
<>
<Swipe
leftAction={
<Button
shape="square"
type="success"
style={{
alignSelf: 'stretch',
height: 46,
}}
>
选择
</Button>
}
rightAction={
<>
<Button
shape="square"
type="danger"
style={{ alignSelf: 'stretch', height: 46 }}
>
删除
</Button>
<Button
shape="square"
type="info"
style={{ alignSelf: 'stretch', height: 46 }}
>
收藏
</Button>
</>
}
onActionClick={handleActionClick}
onOpen={handleOpen}
onClose={handleClose}
>
<Cell
title="事件"
radius={0}
style={{ margin: 0, alignSelf: 'stretch' }}
/>
</Swipe>
</>
)
}
export default App

@@ -1,12 +1,8 @@
import Taro, { pxTransform as transform } from '@tarojs/taro'
import { pxTransform as transform } from '@tarojs/taro'
import { harmony, rn } from './platform-taro'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种可以单独提~~ 要不总要等待其他功能才能被合并~~

# Conflicts:
#	packages/nutui-taro-demo-rn/scripts/taro/adapted.js
…wipe-standard

# Conflicts:
#	packages/nutui-taro-demo-rn/scripts/taro/adapted.js
Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

鸿蒙下滑动会很费劲,并且不是很好的展示,可查看卡片场景。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

'configprovider',
'input',
]
exports = module.exports = ["cell","cellgroup","overlay","button","switch","countdown","empty","price","tag","layout","row","col","space","grid","griditem","divider","image","resultpage","skeleton","notify","pagination","swiper","textarea","indicator","hoverbutton","safearea","hoverbuttonitem","configprovider","input","swipe"]; No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免重新分配全局变量可能导致的问题。

- exports = module.exports = ["cell","cellgroup","overlay","button","switch","countdown","empty","price","tag","layout","row","col","space","grid","griditem","divider","image","resultpage","skeleton","notify","pagination","swiper","textarea","indicator","hoverbutton","safearea","hoverbuttonitem","configprovider","input","swipe"];
+ const exportsList = ["cell","cellgroup","overlay","button","switch","countdown","empty","price","tag","layout","row","col","space","grid","griditem","divider","image","resultpage","skeleton","notify","pagination","swiper","textarea","indicator","hoverbutton","safearea","hoverbuttonitem","configprovider","input","swipe"];
+ module.exports = exportsList;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
exports = module.exports = ["cell","cellgroup","overlay","button","switch","countdown","empty","price","tag","layout","row","col","space","grid","griditem","divider","image","resultpage","skeleton","notify","pagination","swiper","textarea","indicator","hoverbutton","safearea","hoverbuttonitem","configprovider","input","swipe"];
const exportsList = ["cell","cellgroup","overlay","button","switch","countdown","empty","price","tag","layout","row","col","space","grid","griditem","divider","image","resultpage","skeleton","notify","pagination","swiper","textarea","indicator","hoverbutton","safearea","hoverbuttonitem","configprovider","input","swipe"];
module.exports = exportsList;
Tools
Biome

[error] 1-1: A global variable should not be reassigned. (lint/suspicious/noGlobalAssign)

Assigning to a global variable can override essential functionality.

@xiaoyatong xiaoyatong merged commit cfd6804 into dev-harmony Jun 19, 2024
@oasis-cloud oasis-cloud deleted the feat/swipe-standard branch July 2, 2024 09:33
@coderabbitai coderabbitai bot mentioned this pull request Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants