Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
Android package name changed, example app created
Browse files Browse the repository at this point in the history
  • Loading branch information
Talut TASGIRAN committed Jan 13, 2019
1 parent c82455c commit 0a8fa10
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 95 deletions.
85 changes: 43 additions & 42 deletions README.md
Expand Up @@ -77,52 +77,53 @@ This constant will provide you name and code of countries. (I.E: `[{code:'TR',na
### Sample Usage

```javascript
import React from 'react';
import {Picker,StyleSheet} from 'react-native';
import React, {Component} from 'react';
import {Picker, StyleSheet, Text, View} from 'react-native';
import RNCountry from "react-native-countries";

class App extends React.Component{
constructor(props){
super(props);
this.setState({
countryCode: "TR"
})
}

componentWillMount(){
let countryNamesWithCodes = RNCountry.getCountryNamesWithCodes;
countryNamesWithCodes.sort((a, b) => a.name.localeCompare(b.name));
this.setState({
countryNameListWithCode:countryNamesWithCodes
})
}

render(){
return(
<View style={styles.container}>
<Picker
selectedValue={this.state.countryCode}
style={styles.picker}
onValueChange={(itemValue, itemIndex) => this.setState({countryCode: itemValue})}>
{this.state.countryNameListWithCode.map((val)=>{
return <Picker.Item label={val.name} value={val.code} />
})}
</Picker>
</View>
)
}
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
countryCode: "TR"
}
}

componentWillMount() {
let countryNamesWithCodes = RNCountry.getCountryNamesWithCodes;
countryNamesWithCodes.sort((a, b) => a.name.localeCompare(b.name));
this.setState({
countryNameListWithCode: countryNamesWithCodes
})
}

render() {
return (
<View style={styles.container}>
<Picker
selectedValue={this.state.countryCode}
style={styles.picker}
onValueChange={(itemValue, itemIndex) => this.setState({countryCode: itemValue})}>
{this.state.countryNameListWithCode.map((val) => {
return <Picker.Item key={'country-item-' + val.code} label={val.name} value={val.code}/>
})}
</Picker>
<Text>Selected Country Code: {this.state.countryCode}</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container:{
flex:1,
justifyContent:'center',
alignItems:'center'
},
picker:{
height: 50,
width: 100
}
})
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
picker: {
height: 50,
width: 200
}
});
```


Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Expand Up @@ -20,7 +20,7 @@ android {
minSdkVersion 16
targetSdkVersion 28
versionCode 2
versionName "0.0.14"
versionName "0.1.0"
}
lintOptions {
abortOnError false
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactlibrary">
package="com.taluttasgiran">

</manifest>

2 changes: 1 addition & 1 deletion docs/manual-installation.md
Expand Up @@ -9,7 +9,7 @@
#### Android

1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import import com.taluttasgiran.ReactNativeCountriesPackage;` to the imports at the top of the file
- Add `import com.taluttasgiran.ReactNativeCountriesPackage;` to the imports at the top of the file
- Add `new ReactNativeCountriesPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
Expand Down
86 changes: 42 additions & 44 deletions example/App.js
@@ -1,49 +1,47 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import {Picker, StyleSheet, Text, View} from 'react-native';
import RNCountry from "react-native-countries";

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
countryCode: "TR"
}
}

type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
</View>
);
}
}
componentWillMount() {
let countryNamesWithCodes = RNCountry.getCountryNamesWithCodes;
countryNamesWithCodes.sort((a, b) => a.name.localeCompare(b.name));
this.setState({
countryNameListWithCode: countryNamesWithCodes
})
}

render() {
return (
<View style={styles.container}>
<Picker
selectedValue={this.state.countryCode}
style={styles.picker}
onValueChange={(itemValue, itemIndex) => this.setState({countryCode: itemValue})}>
{this.state.countryNameListWithCode.map((val) => {
return <Picker.Item key={'country-item-' + val.code} label={val.name} value={val.code}/>
})}
</Picker>
<Text>Selected Country Code: {this.state.countryCode}</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
picker: {
height: 50,
width: 200
}
});
1 change: 1 addition & 0 deletions example/android/app/build.gradle
Expand Up @@ -137,6 +137,7 @@ android {
}

dependencies {
implementation project(':react-native-countries')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
Expand Down
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.taluttasgiran.ReactNativeCountriesPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
Expand All @@ -22,7 +23,8 @@ public boolean getUseDeveloperSupport() {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
new MainReactPackage(),
new ReactNativeCountriesPackage()
);
}

Expand Down
2 changes: 2 additions & 0 deletions example/android/settings.gradle
@@ -1,3 +1,5 @@
rootProject.name = 'example'
include ':react-native-countries'
project(':react-native-countries').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-countries/android')

include ':app'

0 comments on commit 0a8fa10

Please sign in to comment.