source

반응 네이티브 응용 프로그램에서 클릭 기능이 작동하지 않습니다.

itover 2023. 4. 2. 10:22
반응형

반응 네이티브 응용 프로그램에서 클릭 기능이 작동하지 않습니다.

나는 원어민 반응을 처음 본다.사용자가 텍스트를 클릭하면 함수를 호출하기 위해 다음과 같은 코드를 작성했습니다.

var login = React.createClass({
     openPopup: function(){
        console.log("function called");
     },
     render: function(){
        return (
           <View onClick={this.openPopup}>
              <Text>
                 Login
              </Text>
           </View>
        );
     }
});

위 코드에 잘못된 부분이 있습니까?로그인 텍스트를 클릭해도 콘솔에서 피드백을 받을 수 없습니다.

편집 이 질문은 네이티브에 따라 다릅니다.스택 오버플로의 다른 질문과는 중복되지 않습니다.

이거 드셔보세요.

<TouchableOpacity onPress={this.openPopup}> 
    <View> <Text>...</Text> </View> 
</TouchableOpacity>

다음 래퍼 구성 요소 중 하나를 사용해야 합니다.아래는 크로스 플랫폼에서도 사용할 수 있는 목록입니다.

터치 가능한 하이라이트

<TouchableHighlight onPress={this.openPopup}>
    <View>...</View>
</TouchableHighlight>

터치 가능한 불투명도

<TouchableOpacity onPress={this.openPopup}>
    <View>...</View>
</TouchableOpacity>

터치 가능피드백 없음

<TouchableWithoutFeedback onPress={this.openPopup}>
    <View>...</View>
</TouchableWithoutFeedback>

상기 사항은 폐지되는 방향으로 나아가고 있습니다.프레스 가능 체크

layout_Provider= () => {

 this.rowRenderer= this.rowRenderer.bind(this);}
}

<TouchableOpacity
 style={styles.container}
 onPress={this.GoToEditActivity.bind(this, data.student_id, data.student_name, data.student_class, data.student_subject)}
 >

 <Image style={styles.image}
 source={{uri: data.student_pic}}/>
 {/*source={{uri: "http://homepages.cae.wisc.edu/~ece533/images/barbara.png"}}/>*/}

 <View style={styles.textContainer}>
 <Text style={styles.name}> {data.student_id}</Text>
 <Text style={styles.email}> {data.student_name}</Text>
 </View>
 <View style={styles.textContainer}>
 <Text style={styles.name}> {data.student_class}</Text>
 <Text style={styles.email}> {data.student_subject}</Text>
 </View>

</TouchableOpacity>
GoToEditActivity(student_id, student_name, student_class, student_subject) {

 console.log("GoToEditActivity ---------------------- student_id " + student_id);
 console.log("GoToEditActivity ---------------------- student_name " + student_name);
 console.log("GoToEditActivity ---------------------- student_class " + student_class);
 console.log("GoToEditActivity ---------------------- student_subject " + student_subject);

 this.props.navigation.navigate('EditActivity', {

 ID : student_id,
 NAME : student_name,
 CLASS : student_class,
 SUBJECT : student_subject,

 });
}

언급URL : https://stackoverflow.com/questions/34543190/onclick-function-is-not-working-in-react-native-application

반응형