
โ ๊ธฐ๋ณธ Component
View
Container ์ญํ (div ๊ฐ์ ๋๋)
style ์์ฑ๋ ์๊ณ ์น๊ณผ ๊ฑฐ์ ๋น์ทํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅํ๋ ์ฌ์ฉํ ์ ์๋ ์คํ์ผ์ด ๋ช๋ช ์กด์ฌํ๋ค.
Text
React Native์ ์๋ ๋ชจ๋ text๋ค์ Text component ์์ ๋ค์ด๊ฐ์ผ ํ๋ค.
ActivityIndicator
๋ก๋ฉ ํ์
<ActivityIndicator size="large" color="black" />
TouchableOpacity
๋๋ฅด๋ ์ด๋ฒคํธ๋ฅผ listenํ ์ค๋น๊ฐ ๋ View
๋๋ฅด๋ฉด ํฌ๋ช ๋ ๋ณ๊ฒฝ ์ ๋๋ฉ์ด์ ์ด ์ ์ฉ๋จ
onPress ์์ฑ์ ์ฝ๋ฐฑ ํจ์๋ฅผ ์ค์ ๋๋ ธ์ ๋ ๋์๋ ์ง์ ๊ฐ๋ฅ
hitSlop: ํฐ์น ๊ฐ๋ฅ ์์ญ ์ค์
TouchableHighlight
๋๋ ์ ๋ ์์์ ๋ฐฐ๊ฒฝ์์ด ๋ฐ๋๊ฒ ํด์ค(underlayColor)
onPress ์์ฑ์ ์ฝ๋ฐฑ ํจ์๋ฅผ ์ค์ ๋๋ ธ์ ๋ ๋์๋ ์ง์ ๊ฐ๋ฅ
TouchableWithoutFeedback
์๋ฌด ํจ๊ณผ ์๋ Touchable component
Pressable
Touchable ํ์ ๋๋
๋ ๋ง์ ์ค์ ๊ฐ๋ฅ
hitSlop: ํฐ์น ๊ฐ๋ฅ ์์ญ ์ค์
TextInput
React Native์์ ์ ์ ๊ฐ text๋ฅผ ์ ์ ์ ์๋ ์ ์ผํ ๋ฐฉ๋ฒ
keyboardType: ํค๋ณด๋ ํ์ ์ค์
returnKeyType: ์ํฐ์ ํ ์คํธ ์ข ๋ฅ ์ค์
multiline: ์ฌ๋ฌ ์ค๋ก ์ ๋ ฅ๊ฐ ํ์
secureTextEntry: ์ ๋ ฅ๊ฐ ์จ๊ธฐ๊ธฐ
placeholderTextColor: placeholder ์์ ์ง์
submitBehavior: "blurAndSubmit"(enter์ ํค๋ณด๋ ๋ซ๊ณ ์ ์ถ) | "newline"(enter์ ์ค๋ฐ๊ฟ) | "submit"(enter์ ํค๋ณด๋ ์ ์งํ๊ณ ์ ์ถ)
StyleSheet.create()
style object๋ค์ ๋ด๋ object
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.text}>Hello!</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
text: {
fontSize: 48,
},
});
StyleSheet.create ์ฌ์ฉ ์ด์ (ํ์๋ ์๋, inline style๋ก๋ ์ฌ์ฉ ๊ฐ๋ฅ):
1. ์๋ ์์ฑ ๊ธฐ๋ฅ ์ ๊ณต
2. ์คํ์ผ ์ปดํฌ๋ํธ๋ฅผ ์ ๋ฆฌํ๋๋ฐ ์ ์ฉ
โ Expo SDK
React Native์์๋ ํ์ Component, API๋ง ์ ๊ณตํ๋ค.
๋๋จธ์ง ํ์ํ ํจํค์ง๋ค์ Expo SDK์์ ๊ฐ์ ธ์ ์ฌ์ฉํด์ผ ํ๋ค.
AsyncStorage
npx expo install @react-native-async-storage/async-storage
string๋ง ์ ์ฅ ๊ฐ๋ฅํ๊ณ ๋ธ๋ผ์ฐ์ ์ localStorage์ฒ๋ผ ์๋ํ๋ค.(async await๋ฅผ ์ฌ์ฉํ๋ค๋ ์ ๋ง ๋ค๋ฆ)
โ Layout
React Native์๋ display: block, inline-block, grid ๊ฐ์ ํญ๋ชฉ์ด ์๋ค.
Flex box๋ง ์ฌ์ฉํ๋ค.
View
1. View๋ ๊ธฐ๋ณธ์ ์ผ๋ก Flex Box๋ค.
2. Flex Direction์ ๊ธฐ๋ณธ๊ฐ์ column์ด๋ค.(์น์์๋ ๊ธฐ๋ณธ๊ฐ์ด row)
3. ๋ธ๋ผ์ฐ์ ๊ฐ ์๋๊ธฐ ๋๋ฌธ์ overflow๊ฐ ์๋ค๊ณ ํด์ ์คํฌ๋กค ํ ์๋ ์๋ค.
4. ๋ ์ด์์์ ๋์์ธ ํ ๋ 99.8% width์ height๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค.(0.2%๋ ์์ด์ฝ์ด๋ ์๋ฐํ?)
๋น์จ๋ก ์ฌ์ฉํ๋ค.
<View style={{ flex: 1 }}>
<View style={{ flex: 1, backgroundColor: "tomato" }}></View>
<View style={{ flex: 1, backgroundColor: "teal" }}></View>
<View style={{ flex: 1, backgroundColor: "orange" }}></View>
</View>
ScrollView
1. ์คํฌ๋กค ํ ์ ์๊ฒ ํด์ค๋ค.
2. ScrollView๋ฅผ ์ฌ์ฉํ ๋ style์ ์ง์ ํ๊ณ ์ถ์ผ๋ฉด style prop์ด ์๋๋ผ contentContainerStyle์ ์ฌ์ฉํด์ผ ํ๋ค.
3. ๊ฐ๋ก ์คํฌ๋กค์ ๊ตฌํํ ๋ flex๋ฅผ ์ค ํ์๊ฐ ์๋ค.(overflow๊ฐ ๋ฐ์ํด์ผ ํ๊ธฐ ๋๋ฌธ)
4. pagingEnabled ์์ฑ์ผ๋ก ์คํฌ๋กค์ ํ๋ ฅ(sticky)์ ์ค ์ ์๋ค.(์ด๋์ ๋ ์์ญ์ ๋์ด๊ฐ์ผ๋ง ์คํฌ๋กค์ด ๋จ)
5. showsHorizontalScrollIndicator ์์ฑ์ผ๋ก indicator์ ํ์ ์ ๋ฌด๋ฅผ ์ค์ ํ ์ ์๋ค.(boolean)
6. indicatorStyle ์์ฑ์ผ๋ก indicator์ ์๊น์ ๋ฐ๊ฟ ์ ์๋ค.(ios๋ง ์ ์ฉ ๊ฐ๋ฅ)
Dimensions
1. ์ฌ์ฉ์์ ํ๋ฉด ํฌ๊ธฐ๋ฅผ ์ป์ ์ ์๋ค.
const { width, height } = Dimensions.get("window");
โ Location API
npx expo install expo-location
requestForegroundPermissionsAsync
์์น ๊ถํ ์์ฒญํ๊ธฐ
const ask = async () => {
const permission = await Location.requestForegroundPermissionsAsync();
console.log(permission);
};
useEffect(() => {
ask();
}, []);
getCurrentPositionAsync
์ ์ ์์น ์ ๋ณด ์ป๊ธฐ
const location = await Location.getCurrentPositionAsync({ accuracy: 5 });
reverseGeocodeAsync(location)
์ขํ(latitude, longitude)๋ฅผ ์ฌ๋์ด ์ฝ์ ์ ์๋ ์ฃผ์ ์ ๋ณด๋ก ๋ฐ๊ฟ์ฃผ๋ ํจ์
const location = await Location.reverseGeocodeAsync({
latitude,
longitude,
});


โ Platform API
ํ์ฌ ์ด๋ ํ๋ซํผ์์ ๋์ ์ค์ธ์ง ์ ์ ์๋ API
'๐ธ React Native' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| React Native - 26.01.20 ๊ธฐ์ค ์ต์ Components, API (0) | 2026.01.20 |
|---|---|
| React Native - Android Studio & Xcode ํ๊ฒฝ ์ธํ (m2 macOS) (0) | 2026.01.20 |
| React Native - ๋ฐฐํฌํ๊ธฐ (0) | 2026.01.19 |
| React Native - React Native์๋ง ์๋ CSS ์์ฑ (0) | 2026.01.19 |
| React Native - React Native ์์ํ๊ธฐ (0) | 2026.01.12 |