react-native-maps icon indicating copy to clipboard operation
react-native-maps copied to clipboard

toolbarEnabled doesn't work still

Open greenais opened this issue 7 years ago • 5 comments

Bug

toolbarEnabled={true} in MapView doesn't bring Google toolbar up as expected. There was corresponding issue but it was closed long ago while problem still persists. None of the offerd there hacks worked for me with the most recent version of RNM

Environment info

React native info output:

 ystem:
    OS: Windows 8.1
    CPU: (4) x64 Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
    Memory: 891.43 MB / 7.93 GB
  Binaries:
    Node: 10.16.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.3.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5791312

Library version: 0.25.0 "react-native": "0.60.5",

Steps To Reproduce

  1. put toolbarEnabled={true} in MapView
  2. draw markers, tap any

Describe what you expected to happen: Toolbar appears

Reproducible sample code


<
View style={styles.container}>
          <MapView
            style={styles.map}
            region={this.state.mapDimensions}
            mapType='standard'
            zoomEnabled={true}
            zoomControlEnabled={true}
            toolbarEnabled={true}
            showsCompass={false}
          >
            {this.state.markers2show.map((marker) => this._renderMarker(marker))}
          </MapView>
 </View>

const styles = StyleSheet.create({
  rootContainer: {
    flex: 1
  },
  
  container: {
    width: cWidth,
    height: cHeight,
    justifyContent: 'flex-end',
    alignItems: 'center',
    backgroundColor: '#ffffff',
    marginHorizontal: 0,
    marginTop: globalStyles.viewMarginTop,
    marginBottom: globalStyles.viewMarginBottom,
  },
  
  map: {
    ...StyleSheet.absoluteFillObject,
  },


greenais avatar Aug 27 '19 09:08 greenais

the same problem!

AndreyMashukov avatar Oct 28 '19 23:10 AndreyMashukov

Same issue. I am not able to enable toolbar for maps.

Gl0ntz avatar Nov 15 '19 09:11 Gl0ntz

As I noticed, toolbar starts to appear on marker press only after parent component's size (e.g. , , etc.) updated at least one time after finish of map loading. So, the solution is just to change the size of map container by -1 or 1 (seems, that user won't notice that):

class myMap extends Component { 
    constructor(props) {
        super(props);
        this.state = {
              bottom: -1 
               }
    }
       fixToolbar = () => {
          if(this.state.bottom === -1){
            this.setState({
              bottom: 0
            })
          } 
        }
    render() { 
      return (
        <View style ={styles.container}>
          <MapView
            style={ [styles.map, { bottom:this.state.bottom}] }
            region={region} 
            toolbarEnabled={true} >
            {
              this.props.markers.map((marker) =>
               (<Marker
                   onPress={() => this.fixToolbar()}
                  />
                  ))
                  }
          </MapView>
        </View>
      );
    }
  }

fl1ckje avatar Feb 03 '20 18:02 fl1ckje

As I noticed, toolbar starts to appear on marker press only after parent component's size (e.g. , , etc.) updated at least one time after finish of map loading. So, the solution is just to change the size of map container by -1 or 1 (seems, that user won't notice that):

class myMap extends Component { 
    constructor(props) {
        super(props);
        this.state = {
              bottom: -1 
               }
    }
       fixToolbar = () => {
          if(this.state.bottom === -1){
            this.setState({
              bottom: 0
            })
          } 
        }
    render() { 
      return (
        <View style ={styles.container}>
          <MapView
            style={ [styles.map, { bottom:this.state.bottom}] }
            region={region} 
            toolbarEnabled={true} >
            {
              this.props.markers.map((marker) =>
               (<Marker
                   onPress={() => this.fixToolbar()}
                  />
                  ))
                  }
          </MapView>
        </View>
      );
    }
  }

I just tested using onMarkerPress event from <MapView /> component which is no need to pass fixToolbar method on each <Marker /> component. Hope it works for you too. :bow:

<MapView initialRegion={initialRegion} style={[styles.map, { bottom: this.state.bottom}]} onMarkerPress={this.fixToolbar}>
  ... // Polygon, Polyline, Marker components here.
</MapView>

jeffryang24 avatar Jul 13 '20 04:07 jeffryang24

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 02 '20 16:10 stale[bot]