question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A bug occurs when using @react-navigation/material-bottom-tabs and @react-native-mapbox-gl/maps

See original GitHub issue

Describe the bug

  1. When I use @react-navigation/material-bottom-tabs with @react-native-mapbox-gl/maps , there is bug when I navigate to screen with MapView: it srinks to ~5px

To Reproduce

  1. create react native project
  2. install @react-navigation/material-bottom-tabs @react-native-mapbox-gl/maps
  3. copy and paste my code
  4. navigate a few times beetwen 2 screens by the bottom tab (should navigate Map > (other screen) > Map, first time you navigate to the map, it works fine. Bug happens on second time)

Example:

App.tsx

import { NavigationContainer } from '@react-navigation/native';
import { LocationsStackScreen } from './app/views/LocationsStackScreen';
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { MapScreen } from './app/views/MapScreen';

const Tab = createMaterialBottomTabNavigator();

function App() {
  return (
    <NavigationContainer>
      <Tab.Navigator
        initialRouteName="LocationsStack"
      >
        <Tab.Screen
          name="LocationsStack"
          component={LocationsStackScreen}
          options={{
            title: "Locations",
            tabBarIcon: 'map-marker',
          }}
        />
        <Tab.Screen
          name="Map"
          component={MapScreen}
          options={{
            tabBarIcon: 'map',
          }}
        />
      </Tab.Navigator>
    </NavigationContainer>
  );
}
export default App;

/views/MapScreen.tsx

import React from "react"
import { StyleSheet, View } from "react-native"
import MapboxGL from "@rnmapbox/maps";

MapboxGL.setAccessToken("pk.eyJ1IjoiYnVzeXN0cmlrZSIsImEiOiJjbDF6ZGlnYXQwa2J5M2luc2ZtdjJ5cGNsIn0.sZR8atlffH27nYUuq5sNig");

const styles = StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  container: {
    height: 300,
    width: 300,
    backgroundColor: "tomato"
  },
  map: {
    flex: 1
  }
});

export const MapScreen = () => {
    return (
      <View style={styles.page}>
        <View style={styles.container}>
          <MapboxGL.MapView style={styles.map} />
        </View>
      </View>
    );
}

/views/LocationsStackView.tsx

import React from 'react';
import { Text } from 'react-native';

export const LocationsStackScreen = () => {
  return (
      <Text>Locations stack view</Text>
  )
}

Startup:

npx react-native init MyApp --template react-native-template-typescript
cd MyApp 
yarn add rnmapbox/maps#main 
yarn add @react-navigation/native
yarn add react-native-screens react-native-safe-area-context
yarn add @react-navigation/material-bottom-tabs
react-native run-android

Expected behavior
I expected the map which doesn’t shrink when I navigate between pages

Actual behavior
The map shrinks when I navigate between pages (when I first time navigate to the screen with the map, it doesn’t srink, it happens only on second time)

Screenshots
image image

Versions (please complete the following information):

  • Platform: [Android]
  • Platform OS: [Android 11]
  • Device: [Realme 8]
  • Emulator/ Simulator: [using physical device]
  • Dev OS: [Win10]
  • @rnmapbox/maps Version [rnmapbox/maps#main] (i don’t know how to check)
  • Mapbox GL version [latest] (i don’t know how to check)
  • React Native Version [0.68]

Additional context
If I use @react-navigation/material-bottom-tabs instead of @react-navigation/material-bottom-tabs, when I second time go to the map screen, the application freezes and then crashes. But if I use custom bottom tabs navigation (https://reactnavigation.org/docs/custom-navigators) it works without the bug

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Cryspcommented, Aug 29, 2022

I think it’s because MapView unmounts incorrectly. If turn off detaching screens app does not freeze.

<Tab.Navigator detachInactiveScreens={false}>...</Tab.Navigator>

Referencing to https://stackoverflow.com/a/49351100/7024360

1reaction
wen-kaicommented, Jul 7, 2022

same issue here on Android and react-navigation. When a new screen is pushed on top of a screen with a Map rendered and the user presses “back” (navigation.goBack()) the app freezes and crashes. as a workaround we preserve the zoom, center, and bounds of the map and unmount onWillBlur of the view; however, this isn’t ideal of course as it impacts performance and requires unnecessary state management.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a bug (computer bug)? - TechTarget
Teamwork. This is a bug that arises when there is miscommunication between programmers. One example is when there are differences between the product ......
Read more >
What is bug tracking? - IBM
Bug tracking is the process of logging and monitoring bugs or errors during software testing. It is also referred to as defect tracking...
Read more >
Why Does Software Have Bugs?
A Software Bug is a failure or flaw in a program that produces undesired or incorrect ... Using object-oriented techniques can complicate, ...
Read more >
Software bug - Wikipedia
A software bug is an error, flaw or fault in the design, development, or operation of computer software that causes it to produce...
Read more >
6 Common Types of Software Bugs or Defects | BrowserStack
These bugs occur when an end-user enters a value or a parameter outside the limits of unintended use — for example, entering a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found