To have NativeBase components running onto your native apps, all you need to do is create a fresh React Native project and install the NativeBase command line tools.
System Requirementsreact-native init AwesomeNativeBase
This will walk you through creating a new React Native project in /User/localhost/AwesomeNativeBase
Installing react-native package from npm...
Setting up new React Native app in /User/localhost/AwesomeNativeBase
[email protected] /User/localhost/AwesomeNativeBase
└── [email protected]
To run your app on iOS:
cd /User/localhost/AwesomeNativeBase
react-native run-ios
- or -
Open /User/localhost/AwesomeNativeBase/ios/AwesomeNativeBase.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd /User/localhost/AwesomeNativeBase
react-native run-android
cd AwesomeNativeBase
npm install native-base --save
[email protected] /User/localhost/AwesomeNativeBase
└─┬ [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
└─┬ [email protected]
├── [email protected]
└─┬ [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└─┬ [email protected]
└── [email protected]
You've successfully setup NativeBase with your React Native app. Your React Native app is now all set to run on iOS and Android simulator.
The peer dependencies included from any npm package does not automatically get installed. Your application will need to depend on it explicitly. NativeBase includes React Native Vector Icons as one of its peer dependency. So here we help you with the setup.
$rnpm link
$react-native link react-native-vector-icons
node_modules/react-native-vector-icons
and select the folder Fonts.$rnpm link
$react-native link react-native-vector-icons
android/app/build.gradle
and add the following:apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] // font filenames
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
android/app/src/main/assets/fonts
.
android/settings.gradle
and add the following:
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
android/app/build.gradle
and add the following:
dependencies {
. . .
compile project(':react-native-vector-icons')
}
android/app/src/main/java/com/awesomenativebase/MainActivity.java
and add the following:
package com.awesomenativebase;
. . .
import com.oblador.vectoricons.VectorIconsPackage;
. . .
public class MainActivity extends ReactActivity {
. . .
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
. . .
new VectorIconsPackage(),
. . .
);
}
}
android/app/src/main/java/com/awesomenativebase/MainApplication.java
and add the following:
package com.awesomenativebase;
. . .
import com.oblador.vectoricons.VectorIconsPackage;
. . .
public class MainApplication extends Application implements ReactApplication {
. . .
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
. . .
new VectorIconsPackage(),
. . .
);
}
}