1. npx react-native init Union --template react-native-template-typescript
    1. Run instructions for Android:
    2. • Have an Android emulator running (quickest way to get started), or a device connected.
    3. • cd "/Users/david/ReactNative/Union" && npx react-native run-android
    4. Run instructions for iOS:
    5. • cd "/Users/david/ReactNative/Union" && npx react-native run-ios
    6. - or -
    7. • Open Union/ios/Union.xcworkspace in Xcode or run "xed -b ios"
    8. • Hit the Run button
    9. Run instructions for macOS:
    10. • See https://aka.ms/ReactNativeGuideMacOS for the latest up-to-date instructions.

    删除为空应用
    App.tsx

    1. import React from 'react';
    2. import { View } from 'react-native';
    3. const App = () => {
    4. return (
    5. <View />
    6. )
    7. };
    8. export default App;
    1. cd Union
    2. npm install --save @react-navigation/native
    3. npm install --save @react-navigation/native-stack
    4. npm install --save @react-navigation/bottom-tabs
    5. npm install --save react-native-screens
    6. npm install --save react-native-safe-area-context
    7. npm install --save react-native-vector-icons
    8. npm install --save-dev @types/react-native-vector-icons
    9. npm install --save react-native-linear-gradient
    10. npm install --save react-native-safe-area-context
    11. npm install --save create-react-class
    12. npm install --save-dev @types/create-react-class
    13. npm install --save @react-native-community/datetimepicker
    14. npm install --save react-native-qrcode-svg
    15. npm install --save @react-native-community/netinfo
    16. npm install --save @react-native-picker/picker
    17. npm install --save @react-native-community/slider
    18. npm install --save react-native-webview
    19. npm install --save react-native-gesture-handler
    20. npm install --save pinyin-pro
    21. //npm install --save react-native-share
    22. //npm install @ant-design/icons-react-native
    23. cd ./ios && pod install
    24. cd ..
    25. npx install-expo-modules
    26. npm install -g expo-cli
    27. expo install expo-constants
    1. npm install --save-dev babel-plugin-module-resolver
    2. npm start -- --reset-cache
    3. react-native start "--reset-cache"
    1. import React, { useState } from 'react';
    2. import { StyleSheet, Text, View, Platform, } from 'react-native';
    3. import { NavigationContainer } from '@react-navigation/native';
    4. import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
    5. import Ionicons from 'react-native-vector-icons/Ionicons';
    6. Ionicons.loadFont().then();
    7. const styles = StyleSheet.create({
    8. redDot: {
    9. top: Platform.OS === "ios" ? 4 : 9,
    10. left: 4,
    11. minWidth: 10,
    12. maxHeight: 10,
    13. borderRadius: 5,
    14. fontSize: 6,
    15. lineHeight: 9,
    16. alignSelf: undefined,
    17. },
    18. });
    19. function HomeScreen() {
    20. return (
    21. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
    22. <Text>Home!</Text>
    23. </View>
    24. );
    25. }
    26. function PersonScreen() {
    27. return (
    28. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
    29. <Text>Person!</Text>
    30. </View>
    31. );
    32. }
    33. function SettingsScreen() {
    34. return (
    35. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
    36. <Text>Settings!</Text>
    37. </View>
    38. );
    39. }
    40. const Tab = createBottomTabNavigator();
    41. const App = () => {
    42. const [showReddot, setShowRdddot] = useState(true);
    43. return (
    44. <NavigationContainer>
    45. <Tab.Navigator
    46. screenOptions={({ route }) => ({
    47. tabBarActiveTintColor: 'green',
    48. tabBarInactiveTintColor: 'gray',
    49. tabBarIcon: ({ focused, color, size }) => {
    50. let iconName: string;
    51. if (route.name === 'Home') {
    52. iconName = focused? 'chatbubbles' : 'chatbubbles-outline';
    53. } else if (route.name === 'Settings') {
    54. iconName = focused ? 'settings' : 'settings-outline';
    55. } else if (route.name === 'Person') {
    56. iconName = focused ? 'person' : 'person-outline';
    57. } else {
    58. iconName = ""
    59. }
    60. // You can return any component that you like here!
    61. return <Ionicons name={iconName} size={size} color={color} />;
    62. },
    63. })}
    64. >
    65. <Tab.Screen name="Home" component={HomeScreen} options={{ tabBarBadge: 3 }}/>
    66. <Tab.Screen name="Person" component={PersonScreen} />
    67. <Tab.Screen name="Settings" component={SettingsScreen} options={ showReddot? {
    68. tabBarBadgeStyle: styles.redDot,
    69. tabBarBadge: ""} : {}}/>
    70. </Tab.Navigator>
    71. </NavigationContainer>
    72. );
    73. }
    74. export default App;

    运行

    1. npx react-native start
    1. npx react-native run-ios

    https://github.com/react-native-linear-gradient/react-native-linear-gradient
    https://github.com/th3rdwave/react-native-safe-area-context

    https://github.com/oblador/react-native-vector-icons