I tried to get a photo as background and TextButtons on foreground.
Here is my App.js:
...
const stackOptions = {
cardStyle: { backgroundColor: 'transparent', shadowColor: 'transparent' },
transparentCard: true,
transitionConfig: () => ({
containerStyle: {
backgroundColor: 'transparent',
},
}),
};
const options = {
header: () => null,
cardStyle: {
backgroundColor: 'transparent',
},
};
const App = () => {
return (
<ImageBackground
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
source={require('./bg-img.png')}>
... stack screens inside stack navigator with options and nav container
</ImageBackground>
);
};
export default App;
Here is my HomeScreen.js
...
export const HomeScreen = ({ navigation }) => {
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.options}>
<TextButton style={styles} text={menu.schedule} dir={menu.schedule} navigation={navigation} />
<TextButton style={styles} text={menu.news} dir={menu.news} navigation={navigation} />
<TextButton style={styles} text={menu.stats} dir={menu.stats} navigation={navigation} />
<TextButton style={styles} text={menu.loginRegister} dir={menu.loginRegister} navigation={navigation} />
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
options: {
justifyContent: 'center',
alignItems: 'center',
},
optionButton: {
fontSize: 35,
padding: 40,
},
});
ImageBackground is covering all of the components. If I comment out alignItems, here is the output:
If I set width for 200, this is what's happening:
<ImageBackground
style={{
flex: 1,
justifyContent: 'center',
width: 200,
}}
source={require('./bg-img.png')}
resizeMode="cover">
Versions:
"react-navigation": "2.2.0", "react": "17.0.2", "react-native": "0.65.1", "react-native-screens": "^3.8.0",