React Navigation modal height

后端 未结 4 1176
执念已碎
执念已碎 2020-12-31 07:33

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

4条回答
  •  独厮守ぢ
    2020-12-31 08:25

    Here's an example of how to achieve this in react-navigation v3.x:

    App Container

    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);
    

    Root Screen

    class TestRootScreen extends React.Component {
      render() {
        return (
          
            

    Modal Screen

    class TestModalScreen extends React.Component {
      render() {
        return (
          
            
          
        );
      }
    }
    
    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',
      },
    });
    
    

提交回复
热议问题