Created
July 4, 2018 11:41
-
-
Save behrends/f5037aa17e9323858046aa59155c49fd to your computer and use it in GitHub Desktop.
13:40 - Modal hinzugefügt
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
import React, { Component } from 'react'; | |
import { Button, Modal, StyleSheet, Text, View } from 'react-native'; | |
import Quote from './js/components/Quote'; | |
const data = [ | |
{ | |
text: | |
'Probleme kann man niemals mit derselben Denkweise lösen, durch die sie entstanden sind.', | |
author: 'Albert Einstein' | |
}, | |
{ | |
text: | |
'Man braucht nichts im Leben zu fürchten, man muss nur alles verstehen.', | |
author: 'Marie Curie' | |
}, | |
{ text: 'Nichts ist so beständig wie der Wandel.', author: 'Heraklit' } | |
]; | |
export default class App extends Component { | |
state = { index: 0, showModal: false }; // initialer Zustand | |
render() { | |
let index = this.state.index; // aktueller Zustand | |
const quote = data[index]; | |
let nextIndex = index + 1; | |
if (nextIndex === data.length) nextIndex = 0; | |
return ( | |
// JSX | |
<View style={styles.container}> | |
<Modal | |
visible={this.state.showModal} | |
onRequestClose={() => this.setState({ showModal: false })} | |
> | |
<Text style={{ fontSize: 100 }}>MODAL!!!</Text> | |
</Modal> | |
<Quote text={quote.text} author={quote.author} /> | |
<View style={{ marginBottom: 10 }}> | |
<Button | |
title="Neues Zitat" | |
onPress={() => this.setState({ showModal: true })} | |
/> | |
</View> | |
<Button | |
title="Nächstes Zitat" | |
onPress={() => this.setState({ index: nextIndex })} | |
/> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: 'white' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment