Reputation: 356
I am newbie in React Native. I would like to add in footer bar in my App. Here is my full code in dashboard.js file but it does not work:-
import React, { memo } from 'react';
import Background from '../components/Background';
import Logo from '../components/Logo';
import Header from '../components/Header';
import Paragraph from '../components/Paragraph';
import Button from '../components/Button';
import {Container, Footer, Title, Icon} from 'native-base';
const Dashboard = ({ navigation }) => (
<Background>
<Logo />
<Header>Let’s start</Header>
<Paragraph>
Your amazing app starts here. Open you favourite code editor and start
editing this project.
</Paragraph>
<Button mode="outlined" onPress={() => navigation.navigate('HomeScreen')}>
Logout
</Button>
**<Container>
<Footer>
<Button transparent>
<Icon size={30} color={'#fff'} name={'ios-telephone'} />
</Button>
<Title>Footer</Title>
<Button transparent >
<Icon size={25} color={'#fff'} name={'chatbox'}/>
</Button>
</Footer>
</Container>**
</Background>
);
export default memo(Dashboard);
The error show that the fontfamily issue caused in native-base.
Therefore, I did some research and getting this solution.
async componentDidMount() {
await Font.loadAsync({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
});
this.setState({ isReady: true });
}
But I have no idea how to add this in my code, anyone can help for this? Appreciated.
Upvotes: 0
Views: 676
Reputation: 4641
First you need to keep an initial state as false until data is loaded
state = {
isReady: false
}
Then inside componentDidMount you can load data & when the data is loaded change state.
async componentDidMount() {
try {
await Font.loadAsync({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
});
this.setState({ isReady: true })
} catch (error) {
console.log('error loading fonts', error);
}
}
Finally render your data
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{
this.state.isReady ?
<Text style={{ fontFamily: 'Roboto', fontSize: 56 }}>Hello, world!</Text>
:
<View style={{ flex: 1, padding: 20 }}>
<ActivityIndicator />
</View>
}
</View>
)
}
You can apply the same scenario for functional component, But use useEffect() instead of componentDidMount()
Upvotes: 1