当前位置: 首页 > Skill >

React Native

React Native

1.0.0 2026.11.19 浏览:150
获取Skill文件查看使用说明
作者:周禾许可证:
本文目录展开

React Native Development Rules

Component Performance

  • FlatList for any list over 10 items — ScrollView with map loads everything in memory, FlatList virtualizes
  • keyExtractor must return stable unique strings — using index causes bugs on reorder and deletion
  • React.memo prevents re-renders when props unchanged — wrap pure display components
  • useCallback for functions passed to child components — new function reference triggers child re-render
  • Avoid inline styles in render — creates new object every render, extract to StyleSheet.create

State Management

  • useState is fine for component-local state — don't add Redux/Zustand for a toggle
  • Lift state to lowest common ancestor only — higher causes unnecessary re-renders
  • useMemo for expensive computations — but don't overuse, caching has overhead
  • Context re-renders all consumers on any change — split contexts by update frequency
  • Avoid storing derived data in state — compute during render from source state

Navigation

  • React Navigation is the standard — Expo Router for file-based routing in Expo projects
  • Stack screens stay mounted by default — clean up subscriptions and timers in useEffect cleanup
  • Pass serializable params only — functions and complex objects break deep linking and state persistence
  • useFocusEffect for screen-specific side effects — runs on focus, not just mount
  • navigation.reset for auth flows — clears back stack, prevents returning to login after sign-in

Styling

  • StyleSheet.create outside component body — creates styles once, not every render
  • Flexbox defaults differ from web — flexDirection: 'column', no display: flex needed
  • Dimensions in density-independent pixels — don't use pixel values from design tools directly
  • Platform.select for platform-specific styles — cleaner than conditionals in style objects
  • No CSS inheritance — text styles don't cascade, each Text needs explicit styling

Native Modules

  • Expo modules cover most needs — avoid ejecting for common features like camera, location, notifications
  • expo-dev-client enables native modules without full eject — best of both worlds
  • React Native New Architecture (Fabric, TurboModules) is opt-in — check library compatibility before enabling
  • Native crashes don't show in JS debugger — check Xcode/Android Studio logs

Performance Debugging

  • Hermes engine should be enabled — significantly faster startup and lower memory
  • InteractionManager.runAfterInteractions defers heavy work — keeps animations smooth
  • useNativeDriver: true for animations — runs on UI thread, not JS thread
  • console.log in production kills performance — remove or use __DEV__ guard
  • Flipper for debugging — network, layout, performance profiling

Images

  • Use resizeMode appropriately — cover crops, contain letterboxes, stretch distorts
  • Prefetch images for smooth UX: Image.prefetch(url) before displaying
  • Local images need explicit dimensions — remote images can use aspect ratio if one dimension set
  • SVGs via react-native-svg — better scaling than PNGs for icons
  • Cache remote images with react-native-fast-image — default Image has no persistent cache

Common Mistakes

  • async in useEffect directly — must define async function inside, then call it
  • Missing key warnings in lists — always use unique, stable keys
  • Assuming web React patterns work — no DOM, no CSS, different event system
  • Forgetting cleanup in useEffect — subscriptions, timers, listeners leak without cleanup return
  • Testing only on one platform — iOS and Android differ in behavior, test both regularly

Platform Differences

  • Android needs explicit overflow: 'hidden' for border radius clipping — iOS clips by default
  • Shadows: iOS uses shadow* props, Android uses elevation
  • StatusBar behavior differs — test visibility and color on both platforms
  • Back button is Android-only — handle with BackHandler or navigation listeners
  • Push notifications setup differs significantly — platform-specific configuration required

Build & Release

  • npx react-native clean for unexplained build failures — clears caches and derived data
  • iOS: cd ios && pod install after adding native dependencies — often forgotten step
  • Android: cd android && ./gradlew clean for stubborn build issues
  • EAS Build (Expo) simplifies CI/CD — handles signing, versioning, submission
  • Test release builds locally before submitting — development and production behavior differ

相关文章

更多
PHP无法获取React Native Fetch POST参数的兼容解决方案

React Native使用fetch发起网络请求时,默认以application/json格式发送数据,导致PHP端$_POST变量为空数组。本文介绍两种处理思路:一是前端构建表单数据,二是服务端直接读取php://input流并解码。针对多端(iOS、Android、Web)共用同一接口的场景,提出通过自定义Header标识应用来源,在服务端增加钩子函数进行动态解码的兼容方案,无需大幅修改现有接口代码。

2026.07.09 793
emil-design-eng:打磨现有组件与动效取舍指南

emil-design-eng 是一款专注于界面设计与动画优化的技能工具,日安装量约 3279。它不替换现有组件库,而是通过提供基于 Emil Kowalski 设计理念的评审意见,帮助开发者解决进场别扭、边缘生硬等具体问题。该工具强调将设计判断视为可训练的能力,建议从指出具体动作和曲线入手,而非笼统评价。其功能涵盖从新建动画到审查删减的全流程,支持 React Native 和 Expo 环境,旨在提升界面的自然感与交互流畅度。

2026.11.07 552
design-mobile-apps衔接移动端设计与实现

通过Sleek Skill生成可编辑的设计稿件,再交由Agent编写React Native代码,可减少设计意图在实现时的走样。该流程需配置Sleek账号与API密钥,利用/api/v1/*接口获取HTML及渲染结果进行视觉对稿,但交互逻辑与无障碍属性仍需人工验收。

2026.11.18 482
React Native 跨平台通用选择弹出框封装与使用

本文介绍如何在 React Native 中封装一个适用于 iOS 和 Android 的选择弹出框组件。该组件利用动画实现平滑的显示隐藏效果,通过布尔值控制状态,并支持自定义选项数组、字体颜色及回调方法。文章提供了核心代码实现逻辑及在 Demo 中的调用示例,帮助开发者快速集成通用的用户交互界面。

2025.11.17 178
Skill 文件
  • SKILL.md
    • React Native Development Rules
    • Component Performance
    • State Management
    • Navigation
    • Styling
    • Native Modules
    • Performance Debugging
    • Images
    • Common Mistakes
    • Platform Differences
    • Build & Release
  • 项目或源文件

相关 Skill

更多
OpenHarmony React Native Performance OpenHarmony React Native Performance OpenHarmony React Native 性能静态检查与优化。基于 ohos_react_native 性能文档,适用于编写或审查 OpenHarmony React Native 代码,涵盖 bundle‑harmony、生命周期、TurboModule、RNAbility、Hermes 字节码及 React 渲染优化。
react-native-architecture react-native-architecture 使用 Expo、导航、原生模块、离线同步和跨平台模式构建生产级 React Native 应用。适用于开发移动应用、实现原生集成或架构 React Native
Orderly Sdk React Hooks Orderly Sdk React Hooks Orderly React SDK 钩子使用参考指南,包括 useOrderEntry、usePositionStream、useOrderbookStream、useCollateral 等。
React Native Maps React Native Maps Author: q15004040209-creator
React Flow Code Review React Flow Code Review 审查 React Flow 代码,检测反模式、性能问题和最佳实践。适用于审查使用 @xyflow/react 的代码,检查常见错误...