mcpField
M
mobile

mobile

github.com/htlin222开发7836 次安装3 周前更新
代码仓库

关于 mobile

mobile 是面向跨平台移动应用开发者的开发技能,涵盖 React Native 和 Flutter 的常见开发任务。内容包括组件、导航、性能优化及应用商店发布等实践示例。

主要功能

  1. 01提供 React Native 开发模式
  2. 02提供 Flutter 开发模式
  3. 03说明导航与状态管理方案
  4. 04给出移动性能优化建议
  5. 05涵盖原生模块与应用发布

适用场景

  1. 01构建移动应用列表页面
  2. 02实现页面导航与状态管理
  3. 03排查移动应用性能问题
  4. 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 NativeFlutter
状态useState/ReduxsetState/Riverpod
导航React NavigationNavigator 2.0
HTTPfetch/axioshttp/dio
存储AsyncStorageshared_preferences
动画Animated/ReanimatedAnimationController

示例

输入:“构建列表屏幕” **操作:**创建启用虚拟化、支持下拉刷新和分页的 FlatList

输入:“添加离线支持” **操作:**实现 AsyncStorage 缓存、同步队列和网络检测

评论

支持 Markdown