4

我正在使用 react-native + native-base 并且正在使用简单的布局 - 页眉内容页脚。我在该部分中使用 MapView,我希望地图填充内容区域。如果我在 MapView 的样式中指定宽度和高度,则地图会显示得很好。如果我将 MapView 的样式设置为 flex : 1 地图不会显示

这是我的代码..我想要的只是让地图填充内容..

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View, 
  MapView
} from 'react-native';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Icon } from 'native-base';

class Project extends Component {
  render() {
    return (
            <Container> 
                <Header>
                    <Title>TEST</Title>
                </Header>

                <Content>
                    <MapView
                      style={styles.map}
                      showsUserLocation={true}
                    />
                </Content>

                <Footer>
                    <FooterTab>
                        <Button transparent>
                            <Icon name='ios-call' />
                        </Button>  
                    </FooterTab>
                </Footer>
            </Container>
        );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  map:{
    flex:1
  }
});

AppRegistry.registerComponent('Project', () => Project);

4

4 回答 4

5

尝试将您的包装<MapView>在 a<View>而不是<Content>

<View style={{flex: 1}}>
<MapView
  style={styles.map}
  showsUserLocation={true}/>
</View>
于 2016-11-10T09:19:31.897 回答
0

Native Base Container 是一个可滚动的视图,因此您无法在此容器中填充地图。如果您检查地图元素,高度为 0。

一种可能的解决方案是检测窗口尺寸,然后在代码中计算宽度和高度。但要小心调整窗口框架大小或旋转。

import Dimensions from 'Dimensions'; Dimensions.get('window').height; Dimensions.get('window').width;

于 2016-11-09T12:17:56.830 回答
0

我有如下:

<Container> 
<Header> 
<Title> My Map</Title> 
</Header> 

<Map />

<Container> 
于 2020-03-30T06:14:30.367 回答
0

如果要在 nativebase 的组件中添加地图,可以使用如下:

<Container> 
   <Header>
      <Title> Map </Title> 
   </Header>

  <Content contentContainerStyle={{ flex: 1 }}> 
      <MapView style={{flex: 1}} />
  </Content> 

   <Footer>
      <FooterTab>
         <Button transparent>
            <Icon name='ios-call' />
         </Button>  
       </FooterTab>
    </Footer>

</Container> 
于 2020-04-10T14:43:49.497 回答