import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
export default function App() {
const name = 'Gummy';
return (
<View
style={{
flex:1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text style={{fontSize:30, marginBottom:10}}>Button Component</Text>
<Button title="Button" onPress={() => alert('Click!!!')}/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 30,
}
});
src/App.js
// 커스텀 컴포넌트 MyButton 컴포넌트를 사용해보겠다
import React from 'react';
import { Text, View } from 'react-native';
import MyButton from './components/MyButton';
const App = () => {
const name = 'Gummy';
return (
<View
style={{
flex:1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text
style={{
fontSize:30, marginBottom:10,
}}
>
My Button Component
</Text>
<MyButton />
</View>
);
}
export default App;
src/components/MyButton.js
import React from "react"; // 리액트 호출
import { TouchableOpacity, Text } from "react-native"; // 리액트 네이티브에서 제공하는 컴포넌트 추가
const MyButton = () => {
return (
<TouchableOpacity
style={{
backgroundColor: '#3498db',
padding: 16,
margin: 10,
borderRadius: 8,
}}
onPress={() => alert('Click!!!')}
>
<Text style={{ color: 'white', fontSize: 24}}>My Button</Text>
</TouchableOpacity>
);
};
export default MyButton;
App.js
import App from './src/App';
export default App;
실행 결과(오예!)