如何在react-navigation

时间:2018-01-19 18:15:29

标签: react-native react-navigation

我的问题是,我希望图像溢出抽屉 并且不适合视图宽度

我使用contentComponent来拥有自定义抽屉。

以下链接中的答案显示了我想要实现的目标。 但问题是,宽度和高度是绝对的 值。这不适用于平板电脑,iphone和Android手机。 有什么想法吗?

export default StyleSheet.create({
  ...ApplicationStyles.screen,
  container: {
    //marginTop: Metrics.navBarHeight,
    flex: 1,
    flexDirection: 'column',
    alignItems: 'stretch',
  },
  contentContainer: {
    backgroundColor: 'transparent'
  },
  drawerImage: {
    position: 'absolute',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    opacity: 0.05,
    backgroundColor: 'green'
    // resizeMode: "stretch"
  },


 render () {
    const { navigation } = this.props
    return (
      <View style={styles.container}>
        <Image source={Images.drawerBackground} style={styles.drawerImage}/>
        <ScrollView style={styles.contentContainer}>
          <SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}>
            <DrawerButton
              iconName='ios-map'
              text='Map'
              onPress={() => navigation.navigate('MapView')}
            />
            <DrawerButton
              iconName='md-trending-up'
              text='Elevation'
              onPress={() => navigation.navigate('Elevation')}
            />
            <DrawerButton
              iconName='md-people'
              text='Friends'
              onPress={() => navigation.navigate('Friends')}
            />
            <DrawerButton
              iconName='md-person'
              text='Profile'
              onPress={() => navigation.navigate('Profile')}
            />
            <DrawerButton
              iconName='md-settings'
              text='Settings'
              onPress={() => navigation.navigate('Settings')}
            />
            <View style={styles.checkinBtn}>
              <CheckinButton
                iconName='md-pin'
                text='Checkin Location'
                onPress={() => navigation.navigate('Settings')}
              />
            </View>
          </SafeAreaView>
        </ScrollView>
        <View style={styles.footer}>
          <Text style={styles.text}>
            ........
          </Text>
        </View>
      </View>
    )
  }
}

enter image description here How to set a background Image of Navigator in React-Native

2 个答案:

答案 0 :(得分:1)

尝试使用ImageBackground代替Image并将所有元素包装到其中 请参阅官方文档here

答案 1 :(得分:0)

import { ImageBackground } from "react-native";

 <ImageBackground source={require('../../assets/images/AImg.png')} style={{ width: 100, height: 100}}>

//ur view/text flows here.....

</ImageBackground>

导入并添加ImageBackground https://facebook.github.io/react-native/docs/images.html#background-image-via-nesting