react native 引入 ant组件

561 阅读1分钟

前言

项目目前维护情况

安装

npm install @ant-design/react-native --save
or
yarn add @ant-design/react-native

安装依赖

npm install @react-native-community/cameraroll @react-native-picker/picker @react-native-community/segmented-control @react-native-community/slider react-native-pager-view
or
yarn add @react-native-community/cameraroll @react-native-picker/picker @react-native-community/segmented-control @react-native-community/slider react-native-pager-view


配置按需引入

  • 安装依赖
    npm i babel-plugin-import or yarn add babel-plugin-import

  • 配置 babel.config.js

//babel.config.js
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  "plugins": [ // ant按需引入
    ["import", { libraryName: "@ant-design/react-native" }] // 与 Web 平台的区别是不需要设置 style
  ]
};