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(tabs): 修复Tabs在ios低版本不渲染(#247) #514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kalu5
Copy link

@kalu5 kalu5 commented Aug 13, 2024

🤔 这个 PR 的性质是?(至少选择一个)

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

🔗 相关 Issue

#247

💡 需求背景和解决方案

解决tabs在ios低版本不渲染
修改代码如下

// tabs数据
const items = ref<TTabProps[]>([])
// 解决ios低版本tabs不渲染
watch(children, newChildren => {
  items.value = newChildren.map((child, index) => {
    return { disabled: child.disabled, title: child.title, name: isDef(child.name)? child.name : index }
  })
}, {
  deep: true,
  flush: 'post'
})

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新特性

    • 增强了 wd-tabs 组件的标签项管理,支持更结构化的标签属性。
    • 改进了标签项的响应性,确保其与底层数据的同步更新。
  • 文档

    • 更新了类型定义,提升了代码的类型安全性和清晰度。

Copy link

netlify bot commented Aug 13, 2024

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 5e1f56f
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/66bb0c4b4449990008482c5a
😎 Deploy Preview https://deploy-preview-514--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

vercel bot commented Aug 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 7:34am

Copy link

coderabbitai bot commented Aug 13, 2024

Walkthrough

这次更改为 wd-tabs 组件引入了更结构化的类型定义,特别是在处理选项卡属性方面。通过将 TabProps 的部分属性提取到 TTabProps 类型中,增强了类型安全性。组件内部状态的管理也得到了改进,采用反应式引用和观察者模式,使得选项卡项目在外部数据变化时更加灵活和高效。

Changes

文件 更改摘要
src/.../wd-tabs/types.ts 引入 TabProps,定义 TTabProps 类型,提取 nametitledisabled 属性以增强类型管理。
src/.../wd-tabs/wd-tabs.vue items 从计算属性改为反应式引用,使用 watch 函数监控 children 数组的变化,以改善选项卡的动态更新处理。

Poem

在花丛中跳跃的小兔子,
新的选项卡如花儿一样盛开。
类型安全,功能更强大,
哦,组件焕发光彩,
每次点击都如春风拂面,
欢快的节奏伴我前行。 🐇✨


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 Configuration 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3cd0905 and 5e1f56f.

Files selected for processing (2)
  • src/uni_modules/wot-design-uni/components/wd-tabs/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue (2 hunks)
Additional comments not posted (3)
src/uni_modules/wot-design-uni/components/wd-tabs/types.ts (1)

3-3: 改进类型安全性和清晰度

通过引入 TabProps 并使用 Pick 工具类型定义 TTabProps,增强了类型安全性和代码的清晰度。这种方式确保了在处理选项卡属性时,只有需要的属性被使用。

src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue (2)

146-146: 增强组件的响应性

通过引入 TTabProps 并在 watch 函数中使用它来处理选项卡项,增强了组件的响应性和数据同步能力。这种改进确保了选项卡项与其底层数据始终保持同步。


177-185: 验证对 children 的观察

watch 函数用于观察 children 的变化并更新 items。请确保 children 的变化会触发正确的更新逻辑,并且所有相关的子组件属性都被正确处理。

Verification successful

验证通过:children 的观察逻辑

watch 函数正确地设置为观察 children 的变化,并在变化时更新 itemschildren 是通过 useChildren 组合式函数提供的,并在多个组件中使用,表明其作为共享状态被管理。此设置应能确保 children 的任何变化都会触发 items 的更新逻辑。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that changes to `children` trigger updates to `items`.

# Test: Search for `children` usage and ensure it aligns with the `watch` function logic.
rg --type vue --type ts --type js 'children' -A 5

Length of output: 77


Script:

#!/bin/bash
# Description: Verify that changes to `children` trigger updates to `items`.

# Test: Search for `children` usage and ensure it aligns with the `watch` function logic.
rg 'children' -A 5

Length of output: 30354

Copy link
Owner

@Moonofweisheng Moonofweisheng left a comment

Choose a reason for hiding this comment

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

感谢你的PR!
我看PR中的改动是将计算属性内的逻辑调整到了watch里面,是这个计算属性的写法在低版本iOS中,存在问题吗?

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

这个计算属性的写法在低版本iOS中,存在问题吗

ios13.3.1, tab挂载后,tabs的数组未更新,使用watch加flush: 'post'后,渲染正常

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

https://cn.vuejs.org/guide/essentials/computed.html

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

@Moonofweisheng
Copy link
Owner

https://cn.vuejs.org/guide/essentials/computed.html

我想tabs中items计算属性是没有任何副作用的,仅是依赖原值派生出的新值,不过换成watch可以解决这个问题的话,一些类似组件应该也要做出相应的调整,我这两天找一台可以复现的手机测试一下,再次感谢你的PR。

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

使用computed时,items为空数组
Image_20240814140832
Image_20240814140806
image

使用watch后
Image_20240814141245
image

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

使用inject注入后,children改变了,但是computed监听不到他变了,返回的items还是空

@Moonofweisheng
Copy link
Owner

使用inject注入后,children改变了,但是computed监听不到他变了,返回的items还是空

嗯,是的,这个就是问题所在。我想也可以看看是否需要提个issue给到uni-app来解决这个问题,目前看来只会在14之前的iOS上复现此问题。

@kalu5
Copy link
Author

kalu5 commented Aug 14, 2024

使用inject注入后,children改变了,但是computed监听不到他变了,返回的items还是空

嗯,是的,这个就是问题所在。我想也可以看看是否需要提个issue给到uni-app来解决这个问题,目前看来只会在14之前的iOS上复现此问题。

嗯,ios16之前的应该都有这个问题,issue中14版本也有这个问题,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants