【问题标题】:react-native + native-base. Make MapView fill <Content> area反应原生 + 原生基础。使 MapView 填充 <Content> 区域
【发布时间】:2020-04-10 22:43:49
【问题描述】:

我正在使用 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);

【问题讨论】:

  • NativeBase 会为您提供解决方案。
  • 你找到答案了吗?同样的问题,在 android 4.4,genymotion 的真实设备中,标题不会出现
  • 不,我没有找到答案

标签: react-native native-base


【解决方案1】:

尝试将您的&lt;MapView&gt; 包装在&lt;View&gt; 中,而不是&lt;Content&gt;

<View style={{flex: 1}}>
<MapView
  style={styles.map}
  showsUserLocation={true}/>
</View>

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

      我有如下:

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

      【讨论】:

        【解决方案4】:

        如果你想在 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> 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-12-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-09-29
          • 1970-01-01
          • 2017-03-31
          相关资源
          最近更新 更多