$ npm install react-native-pick-android --save
$ react-native link react-native-pick-android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.reactlibrary.RNPickAndroidPackage;
to the imports at the top of the file - Add
new RNPickAndroidPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-pick-android' project(':react-native-pick-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pick-android/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-pick-android')
import RNPickerAndroid from 'react-native-pick-android';
class Example extends React.Component {
state = {
data: 'b'
}
_onValueChange = (data: string) => {
console.log(data);
this.setState({ data })
}
render() {
const data = ["a", "b", "c"];
return(
<RNPickerAndroid
initData={this.state.data}
data={data}
onValueChange={this._onValueChange}
/>
)
}
}