그림자
그림자는 OS(Platform)마다 설정 방법이 다르다.
플랫폼 | 속성 |
iOS | shadowColor, shadowOffset, shadowOpacity, shadowRadius |
android | elevation |
다른 플랫폼의 설정들은 무시된다.
각각 설정은 아래와 같다
shadowColor | 색상 | "color" |
shadowOffset | 넓이/높이 | {width: number, height: number} object형식으로 작성해야 한다. |
shadowOpacity | 투명도 | 0과 1 사이의 수 |
shadowRadius | blur radius | 숫자 |
elevation | shadow크기 | 0을 포함한 정수 |
shadowOffset은 넓이와 높이라고 되어있지만 shadow의 위치라고 생각하면 된다. 음수도 가능하다.
아래 예시들을 보면 더 쉽게 이해할 수 있다.
(출처: https://livebook.manning.com/book/react-native-in-action/chapter-5/38 )
아래 사이트에서도 shadow속성을 조절해볼 수 있다.
https://ethercreative.github.io/react-native-shadow-generator/
React Native Shadow Generator
ethercreative.github.io
Platform
각각 다른 플랫폼의 설정을 따로 작성할 수 있다.
Platform을 import해줘야 사용할 수 있다.
import { ..., Platform } from "react-native";
shadow라는 style을 만들어 iOS와 android의 적용되는 코드를 따로 작성한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
const style = StyleSheet.create({
shadow: {
...Platform.select({
ios: {
shadowColor: '#ffffff',
shadowOffset: { width: 10, height: 10, },
shadowOpacity: 0.5,
shadowRadius: 10,
},
android: {
elevation: 20,
},
})
}
});
|
cs |
Platform은 Platform.OS로 확인할 수 있다.
<Text>{ Platform.OS === 'ios' ? 'ios' : 'android' }</Text>
위와 같이 작성하면 os에 맞는 text를 작성할 수 있다.
참고한 사이트
https://reactnative.dev/docs/shadow-props
Shadow Props · React Native
Props
reactnative.dev
https://reactnative.dev/docs/view-style-props#elevation
View Style Props · React Native
Example
reactnative.dev
https://blog.self-made.cloud/164
react-native, shadow에 대한 연구
react-native의 shadow 속성에 대해 좀더 자세히 알아보는 시간을 가졌습니다. 한번 살펴볼까요? 이것 하나면 끝! https://ethercreative.github.io/react-native-shadow-generator/ React Native Shadow Generato..
blog.self-made.cloud
https://ethercreative.github.io/react-native-shadow-generator/
React Native Shadow Generator
ethercreative.github.io
https://livebook.manning.com/book/react-native-in-action/chapter-5/38
Chapter 5: Styling in depth · React Native in Action
Platform-specific sizes and styles · Adding drop shadows to components · Moving and rotating components on the x- and y-axes · Scaling and skewing components · Using flexbox for layout
livebook.manning.com
'React Native' 카테고리의 다른 글
React Native - Styled Component 활용, Theme Provider (0) | 2021.12.13 |
---|---|
React Native - styled component (0) | 2021.12.07 |
React Native - flex와 정렬 (0) | 2021.12.07 |
React Native - style 적용하기 (0) | 2021.12.06 |
React Native - 이벤트 (0) | 2021.12.03 |