import { ... } from 'react-native'
Alert
Alert.alert()
Native Alert Dialog(경고창) 생성.
alert(
title:string,
message?: string,
button?: {
text: string
style: "cancel" | "defult" | "destructive"
onPress: function
...
}[],
options?: AlertOptions
)
Platform.OS
android
| ios
| macos
| web
| windows
console.log(Platform.OS) // 'android'
console.log(Platform.OS) // 'ios'
Platform.select()
const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
android: {
backgroundColor: 'green',
},
ios: {
backgroundColor: 'red',
},
default: {
backgroundColor: 'blue',
},
}),
},
});
Dimensions
.get(dim: "window" | "screeen")
"window"
나 "screen"
의 차이가 없음"screen"
: 상태표시줄을 포함한 화면 정보"window"
: 상태표시줄을 제외한 화면의 정보const deviceWidth = Dimensions.get("window").width // 상태표시줄을 제외한 화면의 너비
const deviceHeight = Dimensions.get("window").height // 상태표시줄을 제외한 화면의 높이
// StyleSheet 내에서 활용 가능
const styles = StyleSheet.create({
customStyle: {
width: deviceWidth - 16,
height: deviceHeight / 3
}
})
useWindowDismensions
사용 권장useWindowDismensions
const MyComponent = () => {
const { width, height } = useWindowDimensions()
const customWidth = width - 16
return (
// 스타일 병합을 통해 값 전달
<View style={[styles.customStyle, { width: customWidth }]}>
...
</View>
)
}
const styles = StyleSheet.create({
customStyle: {
...
}
})