关于 mobile
mobile 是面向跨平台移动应用开发者的开发技能,涵盖 React Native 和 Flutter 的常见开发任务。内容包括组件、导航、性能优化及应用商店发布等实践示例。
主要功能
- 01提供 React Native 开发模式
- 02提供 Flutter 开发模式
- 03说明导航与状态管理方案
- 04给出移动性能优化建议
- 05涵盖原生模块与应用发布
适用场景
- 01构建移动应用列表页面
- 02实现页面导航与状态管理
- 03排查移动应用性能问题
- 04添加离线数据支持
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ htlin222/ dotfiles --skill mobile安装后在 Claude Code 中输入/mobile确认已加载。
详细介绍
移动开发
构建跨平台移动应用。
适用场景
- React Native 开发
- Flutter 开发
- 移动性能问题
- 原生模块集成
- 应用商店发布
React Native
组件结构
import React, { useState, useCallback } from "react";
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
interface Props {
title: string;
onPress: () => void;
}
export function Button({ title, onPress }: Props) {
const [pressed, setPressed] = useState(false);
const handlePress = useCallback(() => {
setPressed(true);
onPress();
}, [onPress]);
return (
<TouchableOpacity
style={[styles.button, pressed && styles.pressed]}
onPress={handlePress}
activeOpacity={0.7}
>
<Text style={styles.text}>{title}</Text>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
button: {
backgroundColor: "#007AFF",
padding: 16,
borderRadius: 8,
},
pressed: {
opacity: 0.8,
},
text: {
color: "white",
fontWeight: "600",
textAlign: "center",
},
});
导航
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
type RootStackParamList = {
Home: undefined;
Details: { id: string };
};
const Stack = createNativeStackNavigator<RootStackParamList>();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
Flutter
Widget 结构
class MyButton extends StatelessWidget {
final String title;
final VoidCallback onPressed;
const MyButton({
Key? key,
required this.title,
required this.onPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(title),
);
}
}
性能提示
- 使用 FlatList/ListView 处理长列表
- 使用 useCallback 缓存回调
- 避免内联样式(使用 StyleSheet)
- 延迟加载屏幕和图片
- 使用 Flipper/DevTools 进行性能分析
常见模式
| 模式 | React Native | Flutter |
|---|---|---|
| 状态 | useState/Redux | setState/Riverpod |
| 导航 | React Navigation | Navigator 2.0 |
| HTTP | fetch/axios | http/dio |
| 存储 | AsyncStorage | shared_preferences |
| 动画 | Animated/Reanimated | AnimationController |
示例
输入:“构建列表屏幕” **操作:**创建启用虚拟化、支持下拉刷新和分页的 FlatList
输入:“添加离线支持” **操作:**实现 AsyncStorage 缓存、同步队列和网络检测
评论
支持 Markdown