[[oktatas:telefon:react_native|< React Native]]
====== React Native - Bevitel ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2023
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Triangle =====
==== Terület TextInputban ====
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
import { TextInput } from 'react-native';
function calcTriangleArea(base, height) {
return base * height / 2;
}
export default function App() {
const [base, setBase] = useState('');
const [height, setHeight] = useState('');
const [area, setArea] = useState('');
function startCalc() {
let result = calcTriangleArea(base, height);
setArea(result);
}
return (
Triangle
Háromszög területszámítás
Alap
setBase(base)}
/>
Magasság
setHeight(height)}
/>
Számít
Terület
{/* TERÜLET */}
setArea(area)}
value={area}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'aqua',
alignItems: 'center',
justifyContent: 'center',
},
button: {
backgroundColor: 'blue',
marginTop: 10,
padding: 10,
borderRadius: 3,
},
butotnText: {
color: 'white',
paddingLeft: 10,
paddingRight: 10,
fontSize: 22,
},
input: {
backgroundColor: 'white',
height: 30,
}
});
==== Terület Textben ====
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
import { TextInput } from 'react-native';
function calcTriangleArea(base, height) {
return base * height / 2;
}
export default function App() {
const [base, setBase] = useState('');
const [height, setHeight] = useState('');
const [area, setArea] = useState('');
function startCalc() {
let result = calcTriangleArea(base, height);
setArea(result);
}
return (
Triangle
Háromszög területszámítás
Alap
setBase(base)}
/>
Magasság
setHeight(height)}
/>
Számít
Terület
{area}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'aqua',
alignItems: 'center',
justifyContent: 'center',
},
button: {
backgroundColor: 'blue',
marginTop: 10,
padding: 10,
borderRadius: 3,
},
butotnText: {
color: 'white',
paddingLeft: 10,
paddingRight: 10,
fontSize: 22,
},
input: {
backgroundColor: 'white',
height: 30,
}
});
===== A gomb külön fájlban =====
import React from 'react';
import { StyleSheet, Text, TouchableHighlight } from 'react-native';
const Button = (props) => {
return (
Számít
);
}
export default Button;
const styles = StyleSheet.create({
button: {
backgroundColor: 'blue',
marginTop: 10,
padding: 10,
borderRadius: 3,
},
buttonText: {
color: 'white',
paddingLeft: 10,
paddingRight: 10,
fontSize: 22,
},
});
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
import { TextInput } from 'react-native';
import Button from './components/Button';
function calcTriangleArea(base, height) {
return base * height / 2;
}
export default function App() {
const [base, setBase] = useState('');
const [height, setHeight] = useState('');
const [area, setArea] = useState('');
function startCalc() {
let result = calcTriangleArea(base, height);
setArea(result);
}
return (
Triangle
Háromszög területszámítás
Alap
setBase(base)}
/>
Magasság
setHeight(height)}
/>
Terület
{area}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'aqua',
alignItems: 'center',
justifyContent: 'center',
},
input: {
backgroundColor: 'white',
height: 30,
}
});