反应原生设计

设计与多媒体 社区

技能解读

当前原文的自动摘译,尚未人工审校。

何时使用此技能

使用 React Native 构建跨平台移动应用程序 使用 React Navigation 6+ 实现导航 使用 Reanimated 3 创建高性能动画 使用 StyleSheet 和样式化组件构建样式组件 为不同的屏幕尺寸构建响应式布局

详细部分:核心概念

最初是 SKILL.md 中的 6471 字节部分。移至references/details.md以适应 Codex 的 8 KB 技能体上限。

最佳实践

使用 TypeScript:定义导航和 prop 类型以确保类型安全 Memoize 组件:使用 React.memo 和 useCallback 防止不必要的重新渲染 在 UI 线程上运行动画:使用 Reanimated worklet 实现 60fps 动画 避免内联样式:使用 StyleSheet.create 提高性能 处理安全区域:使用 SafeAreaView 或 useSafeAreaInsets

常见问题

手势冲突:使用GestureDetector包裹手势并使用simultaneousHandlers导航类型错误:为所有导航器定义ParamList类型动画卡顿:使用runOnUI工作集将动画移动到UI线程内存泄漏:在useEffect中取消动画和清理效果字体加载:使用expo-font或react-native-asset 用于自定义字体

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
设计与多媒体
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@wshobson · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
未声明(默认跨平台)
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

输出预览 react-native-design.preview
import React from 'react';
import {
  View,
  Text,
  StyleSheet,
  Pressable,
  Image,
} from 'react-native';
import Animated, {
  useSharedValue,
  useAnimatedStyle,
  withSpring,
} from 'react-native-reanimated';

interface ItemCardProps {
  title: string;
  subtitle: string;
  imageUrl: string;
  onPress: () => void;
}

const AnimatedPressable = Animated.createAnimatedComponent(Pressable);

export function ItemCard({ title, subtitle, imageUrl, onPress }: ItemCardProps) {
  const scale = useSharedValue(1);

  const animatedStyle = useAnimatedStyle(() => ({
    transform: [{ scale: scale.value }],
  }));

  return (
    <AnimatedPressable
      style={[styles.card, animatedStyle]}
      onPress={onPress}
      onPressIn={() => { scale.value = withSpring(0.97); }}
      onPressOut={() => { scale.value = withSpring(1); }}
    >
      <Image source={{ uri: imageUrl }} style={styles.image} />
      <View style={styles.content}>
        <Text style={styles.title} numberOfLines={1}>
          {title}
        </Text>
        <Text style={styles.subtitle} numberOfLines={2}>
          {subtitle}
        </Text>
      </View>
    </AnimatedPressable>
  );
}

const styles = StyleSheet.create({
  card: {
    backgroundColor: '#ffffff',
    borderRadius: 16,
    overflow: 'hidden',
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.1,
    shadowRadius: 8,
    elevation: 4,
  },
  image: {
    width: '100%',
    height: 160,
    backgroundColor: '#f3f4f6',
  },
  content: {
    padding: 16,
    gap: 4,
  },
  title: {
    fontSize: 18,
    fontWeight: '600',
    color: '#1f2937',
  },
  subtitle: {
    fontSize: 14,
    color: '#6b7280',
    lineHeight: 20,
  },
});

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。