I am making react native expo app and i have a question.
I have 2 pages. In page1.js i set title of the page2.js and i have some problems with this. I have TouchableOpacity where i navigate to another page and there i set title of the createStackNavigator options. In createStackNavigator options i get the title that have been sent. It gives me error:
Warning: Failed prop type: Invalid prop onPress
of type boolean
supplied to TouchableOpacity
, expected function
.
And one more:
this.props.onPress is not a function
What have i done wrong? Code:
// page1.js
import React, { Component } from 'react';
import { StyleSheet, View, Button, Image, Text, TouchableOpacity, ScrollView, SafeAreaView, ActivityIndicator } from 'react-native';
import { Header } from 'react-navigation';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Icon from 'react-native-vector-icons/Ionicons'
import CoursesPlan from '../components/CoursesPlan'
const title = "a";
setTitle = (data) => {
title = data;
}
getTitle = () => {
return title;
}
class Page1 extends Component {
render() {
return (
<ScrollView>
<View style={styles.MainContainer}>
<TouchableOpacity
activeOpacity={.7}
onPress={() =>
setTitle("title"),
this.props.navigation.navigate('CourseOne', {
id: 1,
})}>
<CoursesPlan
number="1"
title="Что такое HTML?"/>
</TouchableOpacity>
</View>
</ScrollView>
);
}
}
export default createStackNavigator({
Main: {
screen: Main,
navigationOptions: {
header: null,
},
},
Page1: {
screen: Page1,
navigationOptions: ({ navigation }) => ({
headerTitle: getTitle(),
headerStyle: {
elevation: 0,
borderBottomWidth:1,
borderBottomColor: "#dddddd",
},
}),
},},{
initialRouteName: 'Main',
}
);