react-native - React Native (Expo) - useWindowDimensions().width 未在方向更改时更新
问题描述
当设备方向改变时,我被基于屏幕尺寸的元素尺寸所困扰。这是我的代码
import React, { useEffect, useState } from 'react';
import { View, Text, TouchableOpacity, useWindowDimensions } from 'react-native';
const CleanSearchBar = (props) => {
const windowWidth = useWindowDimensions().width;
return (
<View>
<TouchableOpacity style={{left: (windowWidth - 127)}}>
<Text>text</Text>
</TouchableOpacity>
</View>);
}
它始终保持初始值。对此有什么帮助吗?谢谢
解决方案
推荐阅读
- xslt - 使用 XSLT 从 HTML 中消除 javascript
- java - 将结构化文本/Lua 文档解析为字符串或表格
- bash - 如何编写条件期望脚本来接受基于服务器的不同密码集?
- java - 检查 HashMap 是否为空而不导致 NullPointerException / IndexOutOfBoundsException?
- oracle - 将 BLOB 与 PLSQL 一起使用时遇到问题
- python - 这是2个代码之间的区别
- amazon-s3 - DBFS 使用什么 s3 存储桶?如何获取 DBFS 路径的 S3 位置
- windows - 如何将虚拟地址转换为物理地址(WinDbg)?
- jenkins - 在不同存储库上提交后触发 Jenkins 作业
- javascript - JavaScript 将对象从起始位置移动到结束位置