-
Notifications
You must be signed in to change notification settings - Fork 271
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
refactor: use compatible systemInfo util API #2995
Conversation
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (2)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the Walkthrough此次拉取请求对多个组件中获取系统信息的方式进行了调整。原先直接调用 Changes
Sequence Diagram(s)sequenceDiagram
participant Comp as 组件
participant Util as getWindowInfo()
participant Taro as Taro API
Comp->>Util: 请求窗口/系统信息
Util->>Taro: 检查 API 支持 (Taro.canIUse)
alt API 可用
Util->>Taro: 调用 Taro.getWindowInfo()
else 无支持
Util->>Taro: 调用 Taro.getSystemInfoSync()
end
Taro-->>Util: 返回系统信息
Util-->>Comp: 传回信息
sequenceDiagram
participant Comp as 组件
participant Util as getDeviceInfo()
participant Taro as Taro API
Comp->>Util: 请求设备信息
Util->>Taro: 检查设备 API 支持 (Taro.canIUse)
alt API 可用
Util->>Taro: 调用 Taro.getDeviceInfo()
else 无支持
Util->>Taro: 调用 Taro.getSystemInfoSync()
end
Taro-->>Util: 返回设备信息
Util-->>Comp: 传回设备信息
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
src/packages/drag/drag.taro.tsx (1)
63-86
: 🛠️ Refactor suggestion建议完善异步函数的错误处理
当前异步函数缺少错误处理机制,且与定时器的交互可能存在问题。
const getInfo = async () => { + try { const el = myDrag.current if (el) { const { top, left, bottom, right } = boundary const { screenWidth, windowHeight } = getWindowInfo() const { width, height, top: dragTop, left: dragLeft, } = await getRectByTaro(dragRef.current) setBoundaryState({ top: -dragTop + top, left: -dragLeft + left, bottom: windowHeight - dragTop - bottom - Math.ceil(height), right: screenWidth - dragLeft - right - Math.ceil(width), }) middleLine.current = screenWidth - width - dragLeft - (screenWidth - width) / 2 } + } catch (error) { + console.error('获取拖拽元素信息失败:', error) + // 提供合理的降级处理 + } }
🧹 Nitpick comments (4)
src/utils/get-system-info.ts (1)
3-4
: 类型定义建议补充说明建议为
IDeviceInfo
接口添加更详细的类型说明文档,解释为什么要排除deviceAbi
和CPUType
属性。+/** + * 设备信息接口,排除了在某些平台上不支持的属性 + * @excludes deviceAbi - 设备指令集,仅在特定平台支持 + * @excludes CPUType - CPU 类型,仅在特定平台支持 + */ interface IDeviceInfo extends Omit<Taro.getDeviceInfo.Result, 'deviceAbi' | 'CPUType'> {}src/packages/sticky/sticky.taro.tsx (1)
127-128
: 建议优化窗口高度获取方式当前在渲染路径中直接调用
getWindowInfo()
,可能导致不必要的重复计算。建议使用useMemo
或将窗口高度保存在状态中。+ const windowHeight = useMemo(() => getWindowInfo().windowHeight, []) - const windowHeight = getWindowInfo().windowHeight setFixed(windowHeight - threshold < curRootRect.bottom)src/packages/drag/drag.taro.tsx (1)
142-150
: 建议优化定时器与异步函数的交互当前使用定时器延迟调用异步函数,建议改用
useEffect
的清理函数来处理异步操作的取消。useEffect(() => { + let mounted = true timer.current = window.setTimeout(() => { - getInfo() + if (mounted) { + getInfo().catch(error => { + console.error('初始化拖拽元素失败:', error) + }) + } }, 300) return () => { + mounted = false clearTimeout(timer.current) } }, [])src/packages/avatarcropper/avatarcropper.taro.tsx (1)
11-11
: 优化系统信息获取方式使用
getWindowInfo
工具函数获取系统信息,使代码更加规范和统一。建议在注释中说明
systemInfo
包含的具体信息,以提高代码可读性。- const systemInfo = getWindowInfo() + // 获取窗口信息,包含 pixelRatio 和窗口尺寸 + const systemInfo = getWindowInfo()Also applies to: 122-122
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/packages/avatarcropper/avatarcropper.taro.tsx
(2 hunks)src/packages/drag/demos/taro/demo4.tsx
(1 hunks)src/packages/drag/drag.taro.tsx
(2 hunks)src/packages/menuitem/menuitem.taro.tsx
(4 hunks)src/packages/pulltorefresh/pulltorefresh.taro.tsx
(2 hunks)src/packages/sticky/sticky.taro.tsx
(2 hunks)src/packages/virtuallist/virtuallist.taro.tsx
(2 hunks)src/utils/get-system-info.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (4)
src/utils/get-system-info.ts (1)
18-22
:❓ Verification inconclusive
建议统一返回类型处理
getSystemInfoSync
返回的数据结构可能与新 API 不完全匹配,建议添加类型转换确保返回数据的一致性。Also applies to: 27-31
🏁 Script executed:
#!/bin/bash # 检查 Taro API 返回类型的差异 ast-grep --pattern 'interface $Type extends Taro.$_.Result'Length of output: 61
请开发者重点确认 Taro API 返回值类型一致性
经过尝试使用自动脚本搜索代码库,没有获得明确的类型接口信息来直接验证
Taro.getWindowInfo()
与Taro.getSystemInfoSync()
的返回数据结构是否一致。因此请手动确认这两个 API 的返回值结构是否存在差异。
- 如果存在结构不一致,请添加必要的类型转换或数据适配代码,确保统一返回类型。
- 该问题同样适用于文件中 27-31 行代码。
src/packages/virtuallist/virtuallist.taro.tsx (1)
14-14
: 系统信息获取方式的改进使用
getWindowInfo
工具函数替代直接调用Taro.getSystemInfoSync()
是一个很好的改进,它提供了更好的抽象和一致性。Also applies to: 58-60
src/packages/pulltorefresh/pulltorefresh.taro.tsx (1)
12-12
: 平台检测逻辑优化使用
getDeviceInfo
工具函数替代直接调用系统 API 进行平台检测,提高了代码的可维护性。Also applies to: 156-157
src/packages/menuitem/menuitem.taro.tsx (1)
16-16
: 统一使用 getWindowInfo 获取窗口信息将所有获取窗口高度的地方统一使用
getWindowInfo
工具函数,提高了代码的一致性和可维护性。Also applies to: 110-110, 167-167, 181-181
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2995 +/- ##
=========================================
+ Coverage 0 85.56% +85.56%
=========================================
Files 0 267 +267
Lines 0 18000 +18000
Branches 0 2726 +2726
=========================================
+ Hits 0 15401 +15401
- Misses 0 2596 +2596
- Partials 0 3 +3 ☔ View full report in Codecov by Sentry. |
🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
☑️ 请求合并前的自查清单
Summary by CodeRabbit