Nativebase: react native maps are not showing with Native base

Created on 18 Oct 2016  路  11Comments  路  Source: GeekyAnts/NativeBase

Hi how to show the react native map inside the content.? is there is any solution?

Most helpful comment

Much better without Content:

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


export default class Events extends Component {
  state = {
    loading: true,
  }

  componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.setState({ loading: false });
    });
  }

  render() {
    const { width, height } = Dimensions.get('window');
    const ratio = width / height;

    const coordinates = {
      latitude: 37.78825,
      longitude: -122.4324,
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0922 * ratio,
    };

    return (
      <Container>
        <Header>
          <Title>Map</Title>
          <Button transparent>
            <Icon name="ios-menu" />
          </Button>
        </Header>

        <View style={styles.container}>
          {this.state.loading ? (
            <Loading />
          ) : (
            <MapView
              style={styles.map}
              initialRegion={coordinates}
            />
          )}
        </View>

        <Footer>
          <FooterTab>
            <Button transparent>
              Maps
              <Icon name="ios-map" />
            </Button>
          </FooterTab>
        </Footer>
      </Container>
    );
  }
}

const Loading = () => (
  <View style={styles.container}>
    <Text>Loading...</Text>
  </View>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  map: {
    marginTop: 1.5,
    ...StyleSheet.absoluteFillObject,
  },
});

All 11 comments

Can you get it to render inside <ScrollView> from react-native?

Is there a way to not render a Scrollview?

Made it work:
captura de pantalla 2016-12-25 a las 12 06 36

Not tested in Android.

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


export default class Events extends Component {
  state = {
    loading: true,
  }

  componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.setState({ loading: false });
    });
  }

  render() {
    const { width, height } = Dimensions.get('window');
    const ratio = width / height;

    const coordinates = {
      latitude: 37.78825,
      longitude: -122.4324,
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0922 * ratio,
    };


    return (
      <Container>
        <Header>
          <Title>Map</Title>
          <Button transparent>
            <Icon name="ios-menu" />
          </Button>
        </Header>

        <Content scrollEnabled={false}>
          <View style={{ width, height }}>
            {this.state.loading ? (
              <Loading />
            ) : (
              <MapView
                style={styles.map}
                initialRegion={coordinates}
              />
            )}
          </View>
        </Content>

        <Footer>
          <FooterTab>
            <Button transparent>
              Maps
              <Icon name="ios-map" />
            </Button>
          </FooterTab>
        </Footer>
      </Container>
    );
  }
}

const Loading = () => (
  <View style={styles.container}>
    <Text>Loading...</Text>
  </View>
);

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    justifyContent: 'center',
    alignItems: 'center',
  },
  map: {
    marginTop: 1.5,
    ...StyleSheet.absoluteFillObject,
  },
});

Much better without Content:

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


export default class Events extends Component {
  state = {
    loading: true,
  }

  componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.setState({ loading: false });
    });
  }

  render() {
    const { width, height } = Dimensions.get('window');
    const ratio = width / height;

    const coordinates = {
      latitude: 37.78825,
      longitude: -122.4324,
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0922 * ratio,
    };

    return (
      <Container>
        <Header>
          <Title>Map</Title>
          <Button transparent>
            <Icon name="ios-menu" />
          </Button>
        </Header>

        <View style={styles.container}>
          {this.state.loading ? (
            <Loading />
          ) : (
            <MapView
              style={styles.map}
              initialRegion={coordinates}
            />
          )}
        </View>

        <Footer>
          <FooterTab>
            <Button transparent>
              Maps
              <Icon name="ios-map" />
            </Button>
          </FooterTab>
        </Footer>
      </Container>
    );
  }
}

const Loading = () => (
  <View style={styles.container}>
    <Text>Loading...</Text>
  </View>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  map: {
    marginTop: 1.5,
    ...StyleSheet.absoluteFillObject,
  },
});

A huge thank you! The last solution had helped me.

Thank you so much! The last solution worked for me :)

馃憤

screen shot 2017-05-10 at 2 56 54 pm

I am still not able to render the map even after following your steps. I have raised an issue with react-native-maps as well

<MapView/> will work inside a ScrollView, just make sure you set a minHeight on it's containing view

  _renderMap() {
    if (!this.state.mapLoaded) {
      return (
        <View style={{ flex: 1, justifyContent: 'center' }}>
          <Spinner />
        </View>
      )
    }
    return (
      <View style={{ flex: 1, minHeight: 150 }}>
        <MapView initialRegion={this.state.region} style={{ flex: 1 }} />
      </View>
    )
  }
render() {
    const { navigation } = this.props
    return (
      <Container>
        <StatusBar barStyle="light-content" />
        <Content>
          <Text> {navigation.state.params.id} </Text>
          {this._renderMap()}
        </Content>
      </Container>
    )
  }
}

@mrpatiwi this also working in android

I had to set the view width to the device width, along with the mi-height, to render the mapview inside the modal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natashache picture natashache  路  3Comments

muthuraman007 picture muthuraman007  路  3Comments

Bundas picture Bundas  路  3Comments

nschurmann picture nschurmann  路  3Comments

maphongba008 picture maphongba008  路  3Comments