How do I set the height a React Navigation modal view so once it has appeared it will only cover about half of the screen from the bottom up, and the view below remains visi
if you want to use react native Modal you can make parent view transparent and add a view at the bottom
<Modal
animationType="slide"
transparent={true}
visible={props.visible}
>
<View
style={{
backgroundColor:'transparent',
flex:1,
justifyContent:'flex-end'
}}>
<View
style={{
backgroundColor:'green',
height:'20%'
}}>
<Text>Hello World!</Text>
<TouchableHighlight
onPress={props.closeModal}>
<Text>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>
For react-navigation v3.x you can use the prop transparentCard: true, you can see more details here: https://stackoverflow.com/a/55598127/6673414
Here's an example of how to achieve this in react-navigation
v3.x:
const TestRootStack = createStackNavigator(
{
TestRoot: TestRootScreen,
TestModal: {
screen: TestModalScreen,
navigationOptions: {
/**
* Distance from top to register swipe to dismiss modal gesture. Default (135)
* https://reactnavigation.org/docs/en/stack-navigator.html#gestureresponsedistance
*/
gestureResponseDistance: { vertical: 1000 }, // default is 135 },
},
},
},
{
headerMode: 'none',
mode: 'modal',
transparentCard: true,
},
);
const AppContainer = createAppContainer(TestRootStack);
class TestRootScreen extends React.Component {
render() {
return (
<SafeAreaView style={styles.container}>
<Button title="Show Modal" onPress={() => this.props.navigation.navigate('TestModal')} />
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'blue',
alignItems: 'center',
justifyContent: 'center',
},
});
class TestModalScreen extends React.Component {
render() {
return (
<SafeAreaView style={styles.container}>
<View style={styles.innerContainer} />
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'transparent',
justifyContent: 'flex-end',
},
innerContainer: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
top: 100,
backgroundColor: 'red',
},
});
In your stacknavigator you can set these options:
mode: 'modal',
headerMode: 'none',
cardStyle:{
backgroundColor:"transparent",
opacity:0.99
}
And in your modal screen:
class ModalScreen extends React.Component {
render() {
return (
<View style={{ flex: 1 ,flexDirection: 'column', justifyContent: 'flex-end'}}>
<View style={{ height: "50%" ,width: '100%', backgroundColor:"#fff", justifyContent:"center"}}>
<Text>Testing a modal with transparent background</Text>
</View>
</View>
);
}
}
Also you can refer to this expo snack https://snack.expo.io/@yannerio/modal that I've created to show how it works, or you could use React Native Modal