[[oktatas:telefon:react_native|< React Native]]
====== React Native gombok ======
* **Szerző:** Sallai András
* Copyright (c) 2021, Sallai András
* Szerkesztve: 2021, 2023, 2024
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Nyomógomb =====
import { StyleSheet, SafeAreaView, Button } from 'react-native';
Alert osztály:
import { StyleSheet, SafeAreaView, Button, Alert } from 'react-native';
prompt iOS-en:
Androidon nem működik.
===== Gomb más stílussal =====
//...
BUTTON
const styles = StyleSheet.create({
//...
runButton: {
backgroundColor: 'blue',
marginTop: 10,
padding: 10,
borderRadius: 3,
},
runText: {
color: 'white',
paddingLeft: 10,
paddingRight: 10,
fontSize: 22,
}
});
===== 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, View } from 'react-native';
import Button from './components/Button';
export default function App() {
const [num, setNum] = useState('');
return (
Gomb teszt
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'aqua',
alignItems: 'center',
justifyContent: 'center',
},
});
===== Pressable =====
A Button elavultnak számít, helyette a Pressable-t ajánlják.
Növel
Stílus:
button: {
backgroundColor: 'dodgerblue',
paddingVertical: 8,
paddingHorizontal: 8,
borderRadius: 3,
margin: 10,
alignItems: 'center',
},
buttonText: {
color: 'white',
fontSize: 14,
textTransform: 'uppercase',
},
Dokumentáció: https://reactnative.dev/docs/pressable (2024)
==== Pressable külön fájlban ====
import { Pressable, StyleSheet, Text } from "react-native";
export default function Button(props) {
return (
{props.title}
);
}
const styles = StyleSheet.create({
button: {
backgroundColor: 'dodgerblue',
paddingVertical: 8,
paddingHorizontal: 8,
borderRadius: 3,
margin: 10,
alignItems: 'center',
},
text: {
color: 'white',
fontSize: 14,
textTransform: 'uppercase',
},
});