13:40 - Modal hinzugefügt
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