user7609090
user7609090

Reputation: 11

react native TouchableHighlight have no behavior when press to open a another screen

Thanks for your reading,I am a beginner into React Native,I find a similar question title on this site, but my question is different from that.

I use TouchableHighlight to press to open a new screen,I have succeeded. But the button did not change color. is that normal?

There are some of my try:

Here is my code:

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableHighlight,
} from 'react-native';

import MyInfoOrder from './MyInfoOrder';

export default class MyInfo extends React.Component{
    _onPress(){
        console.log("tap");
    }
    _onPressMessage(){
        const { navigator } = this.props;
        if(navigator) {
            navigator.push({
                name: 'order',
                component: MyInfoOrder,
            })
        }
    }
    render(){
        return(
            <View style={styles.btnGroup}>
                        <TouchableHighlight style={[styles.btnItem]} onPress={this._onPressMessage.bind(this)}>
                            <View style={styles.btnItemView}>
                                <Image source={require('../images/myinfo/message.png')} style={styles.btnItemViewImage} />
                                <Text style={styles.btnItemViewText}>MyTest</Text>
                                <Image source={require('../images/more.png')} style={styles.btnItemViewArrow} />
                            </View>
                        </TouchableHighlight>
                        <View style={styles.lineStyle}></View>
                        <TouchableHighlight style={[styles.btnItem]} onPress={this._onPress}>
                            <View style={styles.btnItemView}>
                                <Image source={require('../images/myinfo/friends.png')} style={styles.btnItemViewImage} />
                                <Text style={styles.btnItemViewText}>MyTest</Text>
                                <Image source={require('../images/more.png')} style={styles.btnItemViewArrow} />
                            </View>
                        </TouchableHighlight>
                        <View style={styles.lineStyle}></View>
                        <TouchableHighlight style={[styles.btnItem]} onPress={this._onPress}>
                            <View style={styles.btnItemView}>
                                <Image source={require('../images/myinfo/col.png')} style={styles.btnItemViewImage} />
                                <Text style={styles.btnItemViewText}>MyTest</Text>
                                <Image source={require('../images/more.png')} style={styles.btnItemViewArrow} />
                            </View>
                        </TouchableHighlight>
                    </View>
        )
    }
}

const styles = StyleSheet.create({
    
    btnGroup:{
        marginBottom:30,
        borderRadius:10,
        backgroundColor:'#FFFFFF',
    },
    btnItem:{
        height:104,
        borderRadius:10,
    },
    btnItemView:{
        borderRadius:10,
        backgroundColor:'#FFFFFF',
        height:106,
        flexDirection:'row',
        alignItems:'center',
    },
    btnItemViewImage:{
        width:48,
        height:48,
        marginLeft:24,
        marginRight:24
    },
    btnItemViewText:{
        flex:1,
        fontSize:32,
        color:'#333333',
    },
    btnItemViewArrow:{
        width:30,
        height:30,
        marginRight:30
    },
    
})

I use: "react": "15.4.2", "react-native": "0.41.2", platform:android 6.0

Upvotes: 1

Views: 1492

Answers (2)

user8637708
user8637708

Reputation: 3773

Adjust "delayPressIn" props in TouchableHighlight to 0 and everything work as expected.

Upvotes: 3

Fantasim
Fantasim

Reputation: 976

if you want change color of TouchableHighlight when pressed you need to add underlayColor in props

Upvotes: 1

Related Questions