请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

把TouchableOpacity代码拷贝到项目中,也无法触发onPress 的打印

实在是不知道为什么模拟器onPress后打印不出来log

正在回答 回答被采纳积分+3

2回答

FE大公爵 2024-04-02 23:03:04
应该不会,你把完整的页面代码发出来
0 回复 有任何疑惑可以回复我~
  • 提问者 Krane #1
    /**
     * Sample React Native App
     * https://github.com/facebook/react-native
     *
     * @format
     */
    
    import React, {useState} from 'react';
    import {SafeAreaView, StatusBar, StyleSheet, View, TouchableOpacity, Text} from 'react-native';
    
    function App(): React.JSX.Element {
      const [count, setCount] = useState(0);
      const onPress = () => {
        console.log('test');
        setCount(prevCount => prevCount + 1);
      };
      return (
        <View>
          <View style={styles.container}>
            <View style={styles.countContainer}>
              <Text>Count: {count}</Text>
            </View>
            <TouchableOpacity style={styles.button} onPress={onPress}>
              <Text>Press Here</Text>
            </TouchableOpacity>
          </View>
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      container: {
        width: '100%',
        height: '100%',
        flexDirection: 'column',
        alignItems: 'center',
        backgroundColor: 'white',
      },
      button: {
        alignItems: 'center',
        backgroundColor: '#DDDDDD',
        padding: 10,
      },
      countContainer: {
        alignItems: 'center',
        padding: 10,
      },
    });
    
    export default App;
    回复 有任何疑惑可以回复我~ 2024-04-03 06:35:04
  • 提问者 Krane #2
    copy了个官方例子, 然后放到app里试了,也不行,难道模拟器的事情?
    回复 有任何疑惑可以回复我~ 2024-04-03 06:35:56
  • 提问者 Krane #3
    "react": "18.2.0",
    "react-native": "0.73.6"
    回复 有任何疑惑可以回复我~ 2024-04-03 06:36:50
提问者 Krane 2024-04-02 22:31:29

Unable to dispatch touch to JS as the catalyst instance has not been attached

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号