Kawai ToDo ๋ฐ๋ผ ๋ง๋ค๊ธฐ
Dimensions API#
import {Dimensions} from 'react-native';const windowWidth = Dimensions.get('window').width;const windowHeight = Dimensions.get('window').height;
or;
const {height, width} = Dimensions.get('window');์ฌ์ฉํ๋ ํธ๋ํฐ(์๋์ฐ ๊ฐ์ฒด)์ ๊ฐ๋ก ๋๋น, ์ธ๋ก ๋๋น๋ฅผ ๊ตฌํ ์ ์๋ค.
Platform Specific Code#
Platform Specific Code ยท React Native
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({ height: Platform.OS === 'ios' ? 200 : 100,});import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({ container: { flex: 1, ...Platform.select({ ios: { backgroundColor: 'red', }, android: { backgroundColor: 'blue', }, }), },});Shadow Props#
...Platform.select({ ios: { shadowColor: "rgb(50, 50, 50)", shadowOpacity: 0.5, shadowRadius: 5, shadowOffset: { height: -1, width: 0 } }, android: { elevation: 3 }})shadow ๋ iOS์ Android์์ ์์ฑ์ด ๋ค๋ฅด๋ค. Android๋ elevation ์ผ๋ก ์ฌ์ฉํ๋ค .
ScrollView#
์คํฌ๋กค๋ทฐ ์ปดํฌ๋ํธ ์์ ToDo ์ปดํฌ๋ํธ๋ฅผ ๋ฃ๋๋ค.
<ScrollView> <ToDo /></ScrollView>TextInput#
placeholderTextColor: ํ๋ ์ด์คํ๋ ํ ์คํธ ์๊นonChangeText: ํ ์คํธ๊ฐ ๋ฐ๋๋ฉด ์คํ๋ ์ฝ๋ฐฑํจ์autoCorrect: ํ ์คํธ ์๋์์ (false๋ก ํ๋๊ฒ ํธํ ๋ฏ)returnKeyType: ํค๋ณด๋ ๋ ์ด์์์์ ํ์๋ ๋ฌธ๊ตฌ
<TextInput returnKeyType={'done'} />
setState#
ํจ์ํ setState๊ฐ ๋ฆฌ์กํธ(React)์ ๋ฏธ๋์ด๋ค(Functional setState is the future of React)
๋๊ตฌ๋ ์ง ํ๋ ๋ฆฌ์กํธ 4ํธ: props ์ state
_toggleComplete = () => { this.setState((prevState) => { return { isCompleted: !prevState.isCompleted, }; });};๐
setState์ updater ํจ์๋ฅผ ๋ฃ๋ ๊ฒ์ด ์ดํด๋์ง ์์.
setStateํจ์์ ํ๋ผ๋ฏธํฐ๋ก ํจ์๋ฅผ ๋ฃ๋ ๊ฒ์ด ์ด๋ค ์๋ฏธ์ธ๊ฐ?setStateํจ์๋ก ์ ๋ฌ๋๋ ํจ์์ ํ๋ผ๋ฏธํฐ๋ ์ด๋์ ๋ฐ์์ค๋ ๊ฒ์ธ๊ฐ?