Skip to content

refactor: 将 Button 和 Switch 从 AntD 迁移到 ReactNativeElementUI - #292

Open
lqx-nancy wants to merge 4 commits into
mainfrom
migrate/button-to-rneui
Open

refactor: 将 Button 和 Switch 从 AntD 迁移到 ReactNativeElementUI#292
lqx-nancy wants to merge 4 commits into
mainfrom
migrate/button-to-rneui

Conversation

@lqx-nancy

@lqx-nancy lqx-nancy commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

-Button 封装层从RectButton改为@rneui/themed Button
-ModalContent.tsx中AntD ghost 替换为 TouchableOpacity
-CourseDataForm.tsx改用新button
-新增switch封装层
-pushSubscriptionItem.tsx、NotiPicker.tsx、selectStyle.tsx 改为使用新 Switch

Summary by CodeRabbit

  • 新功能
    • 新增统一开关组件封装,支持选中/禁用、轨道/滑块颜色及状态切换回调。
  • 改进
    • 更新按钮组件:加载与禁用状态逻辑更一致,样式合并主题并统一圆角;标题/子内容渲染方式已调整以适配新按钮实现。
    • 课程表提交按钮改为使用新的加载状态配置。
    • 课程操作按钮由原按钮组件替换为触控交互控件,外观与点击行为保持一致。
  • 其他
    • 通知、推送订阅与样式设置页面统一切换为新开关组件。

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 132ec039-8110-45ab-b75e-9ad0baa905bc

📥 Commits

Reviewing files that changed from the base of the PR and between 2232b35 and f04d09b.

📒 Files selected for processing (5)
  • src/components/button/index.tsx
  • src/components/button/type.ts
  • src/components/switch/index.tsx
  • src/components/switch/type.ts
  • src/modules/courseTable/components/courseTable/ModalContent.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/switch/index.tsx
  • src/components/switch/type.ts
  • src/components/button/index.tsx
  • src/modules/courseTable/components/courseTable/ModalContent.tsx

Walkthrough

本次更新将本地 Button 和 Switch 组件切换为 RNEUI 实现,显式定义按钮与开关属性类型,并更新课程表、通知及设置模块的组件引用和加载、操作逻辑。

Changes

UI 控件迁移

Layer / File(s) Summary
按钮组件迁移
src/components/button/index.tsx, src/components/button/type.ts
ButtonProps 改为组合 RNEUI Button 类型;按钮使用 RNEUI Button 渲染,并统一传递加载、禁用及样式属性。
开关包装组件
src/components/switch/type.ts, src/components/switch/index.tsx
新增 SwitchProps 和本地 Switch 包装组件,映射选中状态、回调、样式及颜色属性。
开关组件接入
src/modules/notification/component/NotiPicker.tsx, src/modules/setting/components/pushSubscriptionItem.tsx, src/modules/setting/components/selectStyle.tsx
通知和设置模块改用本地 Switch,现有属性和交互逻辑保持传递。
课程表操作控件
src/modules/courseTable/components/CourseDataForm.tsx, src/modules/courseTable/components/courseTable/ModalContent.tsx
提交按钮改用 isLoading;删除和编辑操作改用 TouchableOpacity,对应确认及跳转逻辑保留。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Muxi-X/ccnubox_rn#293:同样迁移 src/components/button/index.tsx@rneui Button,涉及加载、属性及样式处理。

Suggested labels: enhancement

Suggested reviewers: bingling-sama

Poem

一只兔子跳过按钮旁,
新的开关闪着光。
加载时安静不乱跑,
删除编辑各自忙。
代码换装齐欢唱,
胡萝卜也来庆功啦!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次将 Button 和 Switch 从 AntD 迁移到 ReactNativeElementUI 的主要改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate/button-to-rneui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/button/index.tsx (1)

25-26: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

加载指示器颜色硬编码为白色,未随主题适配。

loadingProps={{ color: '#fff' }} 固定为白色,如果 currentStyle?.button_style 在某些主题下设置了浅色/白色背景,加载指示器可能与背景对比度不足而难以辨认。建议让加载指示器颜色跟随 currentStyle(例如从主题中派生,或允许通过 prop 覆盖),而不是固定写死。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/button/index.tsx` around lines 25 - 26, Update the
loadingProps color in the button component to derive from currentStyle or the
active theme instead of hard-coding '`#fff`', while preserving support for an
explicit prop override if the component already exposes one. Ensure the loading
indicator remains sufficiently contrasted across button themes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/button/index.tsx`:
- Around line 19-24: Update the RNEButton props in the component to merge style
into buttonStyle, preserving the existing currentStyle?.button_style and
borderRadius defaults while allowing caller-provided visual properties such as
borderRadius to take effect; keep style in containerStyle only if container
styling is still required.

---

Nitpick comments:
In `@src/components/button/index.tsx`:
- Around line 25-26: Update the loadingProps color in the button component to
derive from currentStyle or the active theme instead of hard-coding '`#fff`',
while preserving support for an explicit prop override if the component already
exposes one. Ensure the loading indicator remains sufficiently contrasted across
button themes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e5ac576b-055b-44c3-b5d0-3886af4153b3

📥 Commits

Reviewing files that changed from the base of the PR and between d8064fa and 2232b35.

📒 Files selected for processing (9)
  • src/components/button/index.tsx
  • src/components/button/type.ts
  • src/components/switch/index.tsx
  • src/components/switch/type.ts
  • src/modules/courseTable/components/CourseDataForm.tsx
  • src/modules/courseTable/components/courseTable/ModalContent.tsx
  • src/modules/notification/component/NotiPicker.tsx
  • src/modules/setting/components/pushSubscriptionItem.tsx
  • src/modules/setting/components/selectStyle.tsx

Comment on lines +19 to +24
<RNEButton
title={children}
onPress={onPress}
disabled={disabled || isLoading}
buttonStyle={[currentStyle?.button_style, { borderRadius: 6 }]}
containerStyle={[{ width: 200, height: 40 }, style]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

@rneui/themed Button buttonStyle vs containerStyle which controls visible background and borderRadius

💡 Result:

In the @rneui/themed Button component, the buttonStyle prop is the correct choice for controlling the visible background color and borderRadius of the button itself [1][2]. The two props serve distinct roles: buttonStyle: This prop is used to apply styles directly to the inner button component [1][3]. Consequently, it is where you should define properties like backgroundColor and borderRadius to affect the appearance of the button [2]. containerStyle: This prop is used to apply styles to the outer wrapper (container) that encapsulates the button [1][3]. It is primarily used for positioning the button, setting margins, or managing how the button interacts with surrounding layout elements [3]. Summary Table Prop | Purpose | Primary Use Case --- | --- | --- buttonStyle | Styles the inner touchable button [1][3] | Background color, borderRadius, border width, padding [2] containerStyle | Styles the outer component container [1][3] | Margins, layout positioning, alignment [3] When customizing the appearance of the button, you should use buttonStyle. If you find that the borderRadius is not appearing correctly, ensure you are applying it to the buttonStyle prop [2]. If you are using a container for layout purposes, keep those styles in containerStyle to avoid layout conflicts [3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== src/components/button/index.tsx ==\n'
cat -n src/components/button/index.tsx

printf '\n== selectStyle.tsx matches ==\n'
rg -n "style=.*borderRadius|<Button|buttonStyle|containerStyle" src -g 'selectStyle.tsx' -A 4 -B 4

Repository: Muxi-X/ccnubox_rn

Length of output: 3504


style 应同时合并到 buttonStyle

containerStyle 只影响外层容器;当前 style 传进来后不会作用到实际按钮。像 selectStyle.tsx 里传入的 borderRadius: 10 会被静默丢掉,按钮仍然固定是 { borderRadius: 6 }。把 style 也并入 buttonStyle 才能让调用方的视觉配置生效。

建议修改
-      buttonStyle={[currentStyle?.button_style, { borderRadius: 6 }]}
+      buttonStyle={[currentStyle?.button_style, { borderRadius: 6 }, style]}
       containerStyle={[{ width: 200, height: 40 }, style]}
📝 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
<RNEButton
title={children}
onPress={onPress}
disabled={disabled || isLoading}
buttonStyle={[currentStyle?.button_style, { borderRadius: 6 }]}
containerStyle={[{ width: 200, height: 40 }, style]}
<RNEButton
title={children}
onPress={onPress}
disabled={disabled || isLoading}
buttonStyle={[currentStyle?.button_style, { borderRadius: 6 }, style]}
containerStyle={[{ width: 200, height: 40 }, style]}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/button/index.tsx` around lines 19 - 24, Update the RNEButton
props in the component to merge style into buttonStyle, preserving the existing
currentStyle?.button_style and borderRadius defaults while allowing
caller-provided visual properties such as borderRadius to take effect; keep
style in containerStyle only if container styling is still required.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

本次 PR 将项目中部分 UI 组件从 AntD 迁移到 ReactNativeElementUI(@rneui/themed),并新增统一的 Switch 封装层,以减少对 AntD 的依赖并统一交互与样式入口。

Changes:

  • @rneui/themed 重写 Button 封装层,并更新课程表提交按钮的 loading 传参方式
  • 新增 Switch 封装层,并将通知/推送订阅/样式设置页面的开关统一迁移到该封装
  • 将课程表弹窗底部的 AntD ghost Button 替换为 TouchableOpacity

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/modules/setting/components/selectStyle.tsx 将开关组件切换到新的 Switch 封装层
src/modules/setting/components/pushSubscriptionItem.tsx 将推送订阅开关切换到新的 Switch 封装层
src/modules/notification/component/NotiPicker.tsx 将通知选择器中的开关切换到新的 Switch 封装层
src/modules/courseTable/components/courseTable/ModalContent.tsx 将弹窗 footer 的 AntD ghost Button 替换为 TouchableOpacity
src/modules/courseTable/components/CourseDataForm.tsx 提交按钮迁移到新的 Button 封装,并改用 isLoading
src/components/switch/type.ts 新增 SwitchProps 类型定义
src/components/switch/index.tsx 新增 Switch 封装实现(基于 @rneui/themed)
src/components/button/type.ts 调整 ButtonProps 以适配 RNEUI Button(并扩展样式能力)
src/components/button/index.tsx Button 封装实现从 RectButton 迁移到 @rneui/themed Button

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/switch/type.ts Outdated
Comment thread src/components/switch/index.tsx Outdated
Comment thread src/components/button/type.ts
Comment thread src/components/button/index.tsx Outdated
Comment thread src/modules/courseTable/components/courseTable/ModalContent.tsx
Comment thread src/modules/courseTable/components/courseTable/ModalContent.tsx

@bingling-sama bingling-sama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

    1. 自定义 Button 的 style 现在只传给 RNEUI containerStyle,borderRadius/backgroundColor 这类视觉样式不会作用到真实按钮本体,现有 selectStyle 等调用点会出现样式回归。建议显式区分 buttonStyle/containerStyle,或至少把需要影响按钮本体的 style 合并进 buttonStyle。
    1. loadingProps 里 spinner color 写死 #fff,浅色按钮主题下可能不可见。建议从主题/按钮背景推导,或暴露 loadingProps/loadingColor 覆盖入口。
    1. ModalContent 里把 AntD ghost Button 换成裸 TouchableOpacity 后没有复用 styles.touchableBtn,删除/编辑按钮点击区域会变小;建议补 style 和 accessibilityRole。
    1. ButtonProps 直接从 RectButtonProps 缩窄成手写接口,后续 testID/accessibility/nativeID 等常见按钮属性会丢失。若迁移到 RNEUI,建议基于 RNE Button 的 props 做 Omit/扩展,而不是只保留当前几个字段。Switch 的命名/注释问题是小修,但也可以顺手整理。

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.

3 participants