首页 > 解决方案 > SafeAreaView 测量功能在本机反应中不起作用

问题描述

我的问题是我必须View使用基本measure功能进行测量。但是,如果SafeArea使用该功能,它将不起作用。

const headerRef = useRef(null);
...
  useEffect(() => {
    headerRef.current.measure( (ox, oy, width, height, px, py) => {
    set({
      ox: ox,
      oy: oy,
      width: width,
      height: height,
      px: px,
      py: py,
    });
  };);
  }, []);
...
<SafeAreaView style={styles.safeArea} ref={headerRef}>

错误是

TypeError : Cannot read property 'measure' of undefined

你怎么能解决这个问题?

有没有人和我有同样问题的人?

标签: reactjsreact-nativeviewmeasure

解决方案


我使用 just 解决了这个问题View,not SafeAreaViewSafeAreaView似乎没有应用这部分。

const headerRef = useRef(null);
...
  useEffect(() => {
    headerRef.current.measure(getViewSize); 
  }, []);
...
const getViewSize = (ox, oy, width, height, px, py) => {
    set({
      ox: ox,
      oy: oy,
      width: width,
      height: height,
      px: px,
      py: py,
    });
  };
...
<View style={styles.safeArea} ref={headerRef}>

推荐阅读