私は2つの画面を持っています。 最初の画面はHomeScreen、2番目の画面はProfileScreenです。 私はHomeScreenでFlatListを使用しました。私は別の画面に移動するためにプッシュしたいと思います。あなたが実装にthis
のコンテキストを失っていること画面の変更FlatList onPress
class ProfileScreen extends Component {
static navigationOptions = {
title: 'Profile',
};
render() {
const { navigate } = props.navigation;
return <Text>Hello, I am profile!</Text>;
}
}
class HomeScreen extends Component {
static navigationOptions = {
title: 'Home',
};
constructor(props) {
super(props);
this.state = {
data: [],
};
}
getScreen() {
this.props.navigation.navigate('Profile')
}
render() {
return (
<View>
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<TouchableHighlight underlayColor= 'transparent' onPress= {this.getScreen}>
<View style= {{width: 300, height: 'auto'}} >
<Text> {item.title} </Text>
<View style= {{width: 300, height: 1, backgroundColor: 'red', marginBottom: 30, marginTop: 15}} />
</View>
</TouchableHighlight>
)}
/>
</View>
);
}
}
const AppNavigator = StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen }
});
this.props.navigationを使用して、この行を最後に追加してください。デフォルトのAppNavigatorをエクスポートします –
私は理解できませんでした、あなたはそれを説明できますか? – tersintersi
change const {navigation} = this.props.navigation –