React_Native_Tutorial/js/components/Quote.js

79 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2022-01-04 12:23:46 +01:00
import React, { Component } from 'react';
import { Text, StyleSheet, View } from 'react-native'
2021-12-29 12:29:29 +01:00
export default class Quote extends Component {
render() {
2021-12-29 14:06:22 +01:00
const { text, author } = this.props // destructuring
2021-12-29 12:29:29 +01:00
return (
2021-12-29 18:11:32 +01:00
// Methode 1
2022-01-21 23:54:30 +01:00
2021-12-29 18:11:32 +01:00
/* <Fragment>
<Text style={styleText}>{text}</Text>
<Text style={styleAuthor}>&mdash; {author}</Text>
</Fragment>);
*/
// Methode 2
2022-01-04 12:23:46 +01:00
/*<Fragment>
2021-12-29 18:11:32 +01:00
<Text style={styles.text}>{text}</Text>
<Text style={styles.author}>&mdash; {author}</Text>
2021-12-29 12:29:29 +01:00
</Fragment>);
2022-01-04 12:23:46 +01:00
*/
2021-12-29 18:11:32 +01:00
2022-01-04 12:23:46 +01:00
// View -> Style
<View style={styles.container}>
<Text style={styles.text}>{text}</Text>
<Text style={styles.author}>&mdash; {author}</Text>
</View>);
2021-12-29 12:29:29 +01:00
}
2021-12-29 14:06:22 +01:00
}
2021-12-29 18:11:32 +01:00
2021-12-29 14:06:22 +01:00
// Styling in React Native mit JavaScript
2021-12-29 18:11:32 +01:00
// Methode 1
2021-12-29 14:06:22 +01:00
const styleText = { fontSize: 25, fontWeight: 'bold', color: 'black' };
2021-12-29 18:11:32 +01:00
const styleAuthor = { fontSize: 15, fontsStyle: 'italic', color: 'red' };
// Methode 2
// StyleSheet.create({...styles...})
const styles = StyleSheet.create({
2022-01-04 12:23:46 +01:00
container: {
//paddingLeft: 20,
//paddingRight:20.
paddingHorizontal: 20, // -> padding (left and right)
borderColor: 'red',
margin: 25,
borderRadius: 20,
backgroundColor: 'white',
//Shadow for Android
elevation: 5,
//Shadow for IOS and Web
shadowOpacity: 0.25,
shadowOffset: {
width: 0,
height: 0.75,
},
shadowRadius: 1.5,
},
2021-12-29 18:11:32 +01:00
text: {
fontSize: 25,
fontWeight: 'bold',
color: 'black',
textAlign: 'center',
2022-01-04 12:23:46 +01:00
// View Style
2021-12-29 18:11:32 +01:00
},
author: {
fontSize: 15,
fontStyle: 'italic',
2022-01-04 12:23:46 +01:00
textAlign: 'right',
2021-12-29 18:11:32 +01:00
color: 'green'
}
});