toolbarEnabled doesn't work still
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
- put toolbarEnabled={true} in MapView
- 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,
},
the same problem!
Same issue. I am not able to enable toolbar for maps.
As I noticed, toolbar starts to appear on marker press only after parent component's size (e.g.
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>
);
}
}
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>
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.