android - React Native + Expo:将重点放在 useEffect 在 Android Box 中不起作用
问题描述
我在 React-Native 中创建了一个简单的主页,其中包含一个应该自动聚焦的图像,因此当用户单击 Android Box 的中心按钮时,它会转到另一个页面。
此代码适用于我计算机中的 Expo,但是当我在 Android Box 中的 Expo Go 上对其进行测试时,出现错误:
未捕获的错误:TypeError:l.current.focus 不是函数。(在 'l.current.focus()' 中,'l.current.focus' 未定义)
我的代码如下:
import { StyleSheet, Image, View, TouchableWithoutFeedback } from 'react-native';
import * as React from 'react';
const HomeScreen = ({navigation}) => {
const goToNextScreen = React.useRef()
React.useEffect(() => {
goToNextScreen.current.focus()
}, []);
return (
<View style={styles.container}>
<TouchableWithoutFeedback
ref={goToNextScreen}
onPressOut={() => navigation.navigate('NextPage')}>
<Image
source={require('../assets/img/logo.png')}
/>
</TouchableWithoutFeedback>
</View>
);
}
export default HomeScreen;
有人可以指出我正确的方向吗?
解决方案
推荐阅读
- c# - 在 C# 中使用 JSON 动态序列化和反序列化
- html - 文本对齐如何在 HTML/CSS 中工作
- python - 如果消息有一定数量的反应,则将消息提取到另一个通道 - discord.py 重写
- r - 如何下载小于 3.6 的 R 版本的包“markovchain”
- timestamp - Postman:测试不同时间戳的断言
- powershell - Powershell 使用 System.Windows.Forms.SaveFileDialog 将目录位置选择到变量中
- react-native - 接收react-native应用程序ble发送的数据
- sml - 展平 SML 获取问题的数据类型列表
- javascript - 随机消息回复 Discord.js 2020
- google-bigquery - 如何在 Bigquery 中更改列模式