裕-Ant Design Mobile添加到RN工程

郜光明
2023-12-01

首先创建RN工程,参照我的另一篇文章:创建RN工程

1. 添加组件库:

npm install @ant-design/react-native --save
npm add babel-plugin-import

// 遇到了几个错误:
npm install --save babel-preset-react-native@5
npm add @react-native-community/viewpager
npm add @react-native-community/slider
npm install --save @react-native-community/segmented-control
npm install @react-native-community/cameraroll --save
npm install @react-native-community/async-storage --save

2. JS:

import {Button, Provider, Toast} from '@ant-design/react-native';

<Provider>
  <Button onPress={() => Toast.info('This is a toast tips')}>Antd</Button>
</Provider>

3. .babelrc:

{
  "plugins": [
    ["import", { libraryName: "@ant-design/react-native" }] // 与 Web 平台的区别是不需要设置 style
  ]
}
 类似资料: