reactjs - 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
你怎么能解决这个问题?
有没有人和我有同样问题的人?
解决方案
我使用 just 解决了这个问题View
,not SafeAreaView
。SafeAreaView
似乎没有应用这部分。
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}>
推荐阅读
- protractor - 返回值在量角器中未定义
- python - 从 jupyter 查询雪花
- scala - 在 build.sbt 中,父项目中的依赖项未反映在子模块中
- java - Android Studio - 尽管其中没有任何零值,但计算结果为 0
- c# - 为什么我无法正确调用此 API,将对象传递到请求正文?
- jsf - Jsf - primefaces 中rich:toggleControl 的替代方案
- sql - 在一个查询中使用左连接从多个表中删除
- typescript - 使用 Vue.js + TypeScript 在 Onsen 中调用 `this.$ons.notification.alert(...)` 时编译后出错
- android - 如何将 Firebase 数据提取到变量中
- python-3.x - 在本地(Python)测试 Alexa Skills 的最佳方法是什么?