3
I have these two classes and want to move to two functions without using this. Only with Hoocks(useNavigation).
Página Home:
import React, { Component } from 'react'
import { Text, View, SafeAreaView, StatusBar, TouchableOpacity } from 'react-native';
import { CustomHeader } from '../CustomHeader'
export class HomeScreen extends Component{
render(){
return (
<SafeAreaView style={{ flex: 1}}>
<CustomHeader title="Home" isHome={true} navigation={this.props.navigation}/>
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Home!</Text>
<TouchableOpacity
style={{marginTop:20}}
onPress={() => this.props.navigation.navigate('HomeDetail')}
>
<Text>Go Home Detail</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
);
}
}
Custom header inserted inside the Home:
import React, { Component } from 'react'
import { Text, View, SafeAreaView, StatusBar, TouchableOpacity } from 'react-native';
import { MaterialIcons, MaterialCommunityIcons, Ionicons, AntDesign } from '@expo/vector-icons'
export class CustomHeader extends Component{
render(){
return(
<View style={{flexDirection: 'row', height: 50, }}>
<StatusBar hidden={true}/>
<View style={{flex:1, justifyContent: 'center'}}>
{
this.props.isHome?
<TouchableOpacity onPress={() => this.props.navigation.openDrawer()}>
<MaterialIcons name='menu' size={40} style={{marginLeft:9}} />
</TouchableOpacity>
:
<TouchableOpacity style={{flexDirection: 'row', alignItems: 'center'}} onPress={() => this.props.navigation.goBack()}>
<AntDesign name='back' size={40} style={{marginLeft: 9}}/>
<Text>Back</Text>
</TouchableOpacity>
}
</View>
<View style={{flex:1.5, justifyContent:'center'}}>
<Text style={{textAlign:'center'}}>{this.props.title}</Text>
</View>
<View style={{flex:1, }}></View>
</View>
)
}
}