update
This commit is contained in:
parent
4d24511bf8
commit
57976bcd72
8
App.js
8
App.js
|
@ -1,6 +1,6 @@
|
||||||
import React, { Component } from 'react'; // Bei React bzw. Nativ immer importieren!
|
import React, { Component } from 'react'; // Bei React bzw. Nativ immer importieren!
|
||||||
import { StatusBar } from 'expo-status-bar';
|
import { StatusBar } from 'expo-status-bar';
|
||||||
import { Button, StyleSheet, Text, View } from 'react-native';
|
import { Button, StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
import Quote from './js/components/Quote';
|
import Quote from './js/components/Quote';
|
||||||
|
|
||||||
|
@ -15,19 +15,23 @@ export default class App extends Component {
|
||||||
state = { index: 0 }; //initialer Zustand
|
state = { index: 0 }; //initialer Zustand
|
||||||
|
|
||||||
// Darstellung der Komponente im UI
|
// Darstellung der Komponente im UI
|
||||||
// Render wird automatisch ausgeführt
|
// Render wird automatisch ausgeführt:
|
||||||
// a) Komponente erscheint im Ui (initialer Zustand)
|
// a) Komponente erscheint im Ui (initialer Zustand)
|
||||||
// b) Zustand ändert sich (state) => this.setstate(...)
|
// b) Zustand ändert sich (state) => this.setstate(...)
|
||||||
|
// c) probs sich ändern
|
||||||
render() {
|
render() {
|
||||||
let index = this.state.index;
|
let index = this.state.index;
|
||||||
const quote = data[index];
|
const quote = data[index];
|
||||||
let nextIndex = index + 1;
|
let nextIndex = index + 1;
|
||||||
if (nextIndex === data.length) nextIndex = 0;
|
if (nextIndex === data.length) nextIndex = 0;
|
||||||
|
let prevIndex = index - 1;
|
||||||
|
if (index === 0) prevIndex = data.length - 1;
|
||||||
return (
|
return (
|
||||||
//JSX
|
//JSX
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Quote text={quote.text} author={quote.author} />
|
<Quote text={quote.text} author={quote.author} />
|
||||||
<Button title="Nächstes Zitat" onPress={() => this.setState({ index: nextIndex })} />
|
<Button title="Nächstes Zitat" onPress={() => this.setState({ index: nextIndex })} />
|
||||||
|
<Button title="Letztes Zitat" onPress={() => this.setState({ index: prevIndex })} />
|
||||||
<StatusBar style="auto" />
|
<StatusBar style="auto" />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,10 +3,15 @@ import { Text } from 'react-native'
|
||||||
|
|
||||||
export default class Quote extends Component {
|
export default class Quote extends Component {
|
||||||
render() {
|
render() {
|
||||||
|
const { text, author } = this.props // destructuring
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Text>{this.props.text}</Text>
|
<Text style={styleText}>{text}</Text>
|
||||||
<Text>{this.props.author}</Text>
|
<Text style={styleAuthor}>— {author}</Text>
|
||||||
</Fragment>);
|
</Fragment>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Styling in React Native mit JavaScript
|
||||||
|
const styleText = { fontSize: 25, fontWeight: 'bold', color: 'black' };
|
||||||
|
const styleAuthor = { fontSize: 17, fontsStyle: 'italic', color: 'red' };
|
Loading…
Reference in New Issue
Block a user