[[oktatas:telefon:react_native|< React Native]]
====== Saját komponens ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2021
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Szeparátor =====
const Separator = () => (
);
const App = () => (
Első
Második
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
marginHorizontal: 16,
},
separator: {
marginVertical: 8,
borderBottomColor: 'black',
borderBottomWidth: StyleSheet.hairlineWidth,
width: '100%',
},
});
export default App;
===== Szöveg fejrésszel =====
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { Text } from "react-native";
import Header from './components/header';
export default function App() {
return (
Törzsrész
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
body: {
fontSize: 22,
}
});
A komponenst egy components nevű könyvtárba helyezzük le.
import React from "react";
import { StyleSheet, Text, View } from "react-native";
export default function Header() {
return (
Fejrész
);
}
const styles = StyleSheet.create({
header: {
height: 80,
width: '100%',
backgroundColor: 'coral',
position: 'absolute',
top: 0,
},
title: {
fontSize: 32,
textAlign: 'center',
paddingTop: 10,
fontWeight: 'bold',
color: 'white',
},
});
===== Lista =====
==== A lista ====
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { FlatList, Text } from "react-native";
import Header from './components/header';
const DATA = [
{ id: '1', task: 'Angular tanulás' },
{ id: '2', task: 'Laravel tanulás' },
];
const Item = ({ task }) => (
{task}
);
export default function App() {
const renderItem = ({ item }) => (
);
return (
item.id}
style={styles.list}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
item: {
padding: 10,
backgroundColor: '#005588',
},
task: {
color: 'white',
fontSize: 32,
},
list: {
width: '100%',
},
});
==== Saját komponens ====
import React from "react";
import { StyleSheet, Text, View } from "react-native";
export default function Header() {
return (
Tennivalók
);
}
const styles = StyleSheet.create({
header: {
height: 80,
width: '100%',
backgroundColor: 'coral',
},
title: {
fontSize: 32,
textAlign: 'center',
paddingTop: 10,
},
});