-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before moving styles to separate file
- Loading branch information
1 parent
b2532e9
commit 9fb5c45
Showing
6 changed files
with
104 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
} from 'react-native'; | ||
|
||
import {Colors} from 'react-native/Libraries/NewAppScreen'; | ||
import AsyncStorage from '@react-native-community/async-storage'; | ||
|
||
import ContactCard from './components/ContactCard'; | ||
import FancyButton from './components/FancyButton'; | ||
|
@@ -22,11 +23,11 @@ export default class App extends Component { | |
super(); | ||
this.state = { | ||
items: [ | ||
{id: 0, firstName: 'Oleg', lastName: 'Shyshkov', cell: '+38098816004', email: "[email protected]"}, | ||
{id: 1, firstName: 'Вікторія', lastName: 'Шишкова', cell: 'немає', email: "немає"}, | ||
{id: 2, firstName: 'Andrii', lastName: 'Shyshkov', cell: '+380978458000', email: "[email protected]"}, | ||
{id: 3, firstName: 'Надія', lastName: 'Шишкова', cell: '+380679087261', email: "[email protected]"}, | ||
{id: 4, firstName: 'Тетяна', lastName: 'Шишкова', cell: '+380977460988', email: "[email protected]"} | ||
// {id: 0, firstName: 'Oleg', lastName: 'Shyshkov', cell: '+38098816004', email: "shyshkov.o.a@gmail.com"}, | ||
// {id: 1, firstName: 'Вікторія', lastName: 'Шишкова', cell: 'немає', email: "немає"}, | ||
// {id: 2, firstName: 'Andrii', lastName: 'Shyshkov', cell: '+380978458000', email: "andrii@gmail.com"}, | ||
// {id: 3, firstName: 'Надія', lastName: 'Шишкова', cell: '+380679087261', email: "nadia@gmail.com"}, | ||
// {id: 4, firstName: 'Тетяна', lastName: 'Шишкова', cell: '+380977460988', email: "shyshkova.t.v@icloud.com"} | ||
], | ||
isPortrait: true, | ||
screenWidth: Dimensions.get('window').width, | ||
|
@@ -35,15 +36,45 @@ export default class App extends Component { | |
itemData: {}, | ||
isNewContact: false | ||
} | ||
// this.getFromLocal(); | ||
} | ||
|
||
getFromLocal = async () => { | ||
try { | ||
const value = await AsyncStorage.getItem('contacts'); | ||
const arr = JSON.parse(value) | ||
this.setState({items: arr}) | ||
// console.log(this.state.items); | ||
} catch (e) { | ||
console.info(e); | ||
} | ||
} | ||
|
||
|
||
saveToLocal = async (data) => { | ||
try { | ||
await AsyncStorage.setItem('contacts', JSON.stringify(data)); | ||
// await AsyncStorage.setItem('contacts', JSON.stringify([])); | ||
} catch (error) { | ||
console.info(error); | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
console.log("did mount"); | ||
this.getFromLocal(); | ||
|
||
Dimensions.addEventListener('change', ({window: {width, height}}) => { | ||
width < height ? this.setState({isPortrait: true}) : this.setState({isPortrait: false}); | ||
this.setState({screenWidth: Dimensions.get('window').width}) | ||
}) | ||
} | ||
|
||
// shouldComponentUpdate(props, state) { | ||
// console.log("shoud update"); | ||
// return true; | ||
// } | ||
|
||
addItem = () => { | ||
this.setState({ | ||
items: [...this.state.items, {id: new Date().getTime(), firstName: 'Oleg', lastName: 'Shyshkov', cell: '+38098816004', email: "[email protected]"}], | ||
|
@@ -65,6 +96,12 @@ export default class App extends Component { | |
// }, 3000); | ||
} | ||
|
||
saveInput = (val) => { | ||
console.log(val); | ||
this.setState({items: [...this.state.items, val]}); | ||
this.saveToLocal([...this.state.items, val]); | ||
} | ||
|
||
render () { | ||
let index; | ||
return ( | ||
|
@@ -78,6 +115,7 @@ export default class App extends Component { | |
isPortrait={this.state.isPortrait} | ||
itemData={this.state.itemData} | ||
isNewContact={this.state.isNewContact} | ||
inputData={this.saveInput} | ||
/> | ||
|
||
<View style={{height: 55, marginTop: -5, backgroundColor: '#67B826', justifyContent: "space-between", alignItems: 'center', flexDirection: 'row'}}> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters