[[oktatas:telefon:react_native|< React Native]]
====== Példák ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2021, 2023
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Számláló növelő =====
A példában osztályokat használunk:
import React, { Component} from 'react';
import { View, StyleSheet, Button, Text } from 'react-native';
export default class App extends Component {
constructor() {
super();
this.state = {
counter: 0
}
}
increment = () => {
this.setState({ counter: this.state.counter + 1 });
}
render() {
return (
Számláló: {this.state.counter}
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'skyblue',
alignItems: 'center',
justifyContent: 'center',
},
});
{{:oktatas:telefon:react_native:szamlalo_novelo.png?200|}}
===== Számláló kicsit másként =====
Teljes forráskód:
* https://github.com/oktat/mobil_count.git
import {
StyleSheet,
Text,
View,
TextInput,
Button
} from 'react-native';
import {useState} from 'react';
export default function App() {
const [counter, setCounter] = useState(0);
function increment() {
setCounter(counter + 1)
}
return (
Számláló
{counter}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#008',
alignItems: 'center',
justifyContent: 'center',
},
elso: {
color: '#fff',
fontSize: 30,
},
input: {
backgroundColor: 'lightblue',
width: '90%',
fontSize: 30,
},
});
===== Háromszög területe =====
import React from 'react';
import { Button, StyleSheet, Text, TextInput, View } from 'react-native';
export default function App() {
const [base, setBase] = React.useState('');
const [height, setHeight] = React.useState('');
const [area, setArea] = React.useState('');
const handleSubmit = () => {
let result = base*height/2;
setArea(result);
}
return (
Háromszög területe
Alap:
setBase(base)}
/>
Magasság:
setHeight(height)}
/>
Terület: {area}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
input: {
borderWidth: 1,
borderColor: '#777',
padding: 8,
margin: 10,
width: 200,
},
area: {
margin: 20,
},
head: {
margin: 20,
fontSize: 34,
}
});
{{:oktatas:telefon:react_native:haromszogterulete.png?200|}}
Expo:
* https://expo.dev/@sallaiandras/haromszogterulet