反应导航模态高度

mat*_*hew 7 modal-dialog react-native react-navigation

如何设置React Navigation模式视图的高度,一旦它出现,它将仅从底部向上覆盖屏幕的大约一半,并且下面的视图仍然可见?

更新:我正在尝试创建类似于App Store购买模式的ux流程,其中某种StackNavigator嵌套在填充屏幕下半部分的模式中.

App Store模式

Yan*_*rio 9

在stacknavigator中,您可以设置以下选项:

  mode: 'modal',
    headerMode: 'none',
    cardStyle:{
      backgroundColor:"transparent",
      opacity:0.99
  }
Run Code Online (Sandbox Code Playgroud)

在您的模态屏幕中:

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>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

你也可以参考我创建的世博小吃https://snack.expo.io/@yannerio/modal来展示它是如何工作的,或者你可以使用 React Native Modal

  • @RomitKumar 添加此属性 `transparentCard: true` 以使其与 v3.x 一起使用,您可以在此处看到它正在运行 https://snack.expo.io/@yannerio/ashamed-truffle (2认同)
  • iOS中的@YanciNerio不透明度为0.5也改变了主屏幕的不透明度,将其更改为1然后会出现同样的问题,模态屏幕的背景将是白色而不是透明 (2认同)

des*_*ond 5

这是在react-navigationv3.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);
Run Code Online (Sandbox Code Playgroud)

根屏

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',
  },
});
Run Code Online (Sandbox Code Playgroud)

模态筛

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',
  },
});

Run Code Online (Sandbox Code Playgroud)