728x90
parent view의 속성 onLayout을 이용하면
event.nativeEvent.layout.height를 통해 height를 알 수 있다.
import React, {useState} from 'react';
import {View} from 'react-native';
export default ({routine, onMidBtnPress, children}: Props) => {
const [parentHeight, setParentHeight] = useState(0);
const onLayout = event => {
const {height} = event.nativeEvent.layout;
setParentHeight(height);
};
return (
<View style={{width: 100, height: 100}} onLayout={onLayout}>
<View
style={{
position: 'absolute',
width: '100%',
height: parentHeight,
backgroundColor: 'pink',
opacity: 0.5,
alignSelf: 'center',
}}
/>
</View>
);
};
출처
how get parent size in child view in react-native?
I cannot understand how can I send parent view's sizes to child component of this. In renderPager() I want calculate some parameters that depend on parent view size. I know that we can do it through
stackoverflow.com
'Solve Problem > React Native' 카테고리의 다른 글
[React Native] WebView 사용법 (0) | 2020.05.11 |
---|---|
[React Native] Gif 파일 표시하기 (4) | 2020.05.05 |
[React Native] library not found for -lAppAuth / Build input file cannot be found:에러 (0) | 2020.05.04 |
[React Native] react-redux hooks (0) | 2020.05.01 |
[React Native] 날씨 API, 역지오코딩(위도/경도 > 주소), 미세먼지 API (2) | 2020.04.29 |