简体   繁体   English

React Native Map 渲染在一切之上

[英]React Native Map Renders On Top Of Everything

I am working on a little map application using react-native-maps.我正在使用 react-native-maps 开发一个小地图应用程序。 I am trying to render a floating action button on top of the map, but while I do see it flashing for a second, as soon as the map renders, it sits right on top of the button.我正在尝试在地图顶部渲染一个浮动操作按钮,但是虽然我确实看到它闪烁了一秒钟,但一旦地图渲染,它就位于按钮的正上方。 I will paste my render code and styles below:我将在下面粘贴我的渲染代码和样式:

render() {
        return (
          <View style={{flex:1, backgroundColor: '#f3f3f3'}}>
            <MapView ref="map" mapType="terrain" style={styles.map} region={this.state.region} onRegionChange={this.onRegionChange}>
              <MapView.Marker coordinate={{latitude: this.state.region.latitude, longitude: this.state.region.longitude}}>
                <View style={styles.radius}>
                  <View style={styles.marker} />
                </View>
              </MapView.Marker>
            </MapView>

            <ActionButton buttonColor="rgba(231,76,60,1)" style={styles.actionButton}>
              <ActionButton.Item buttonColor='#9b59b6' title="New Task" onPress={() => console.log("notes tapped!")}>
                <Icon name="rocket" style={styles.actionButtonIcon} />
              </ActionButton.Item>
              <ActionButton.Item buttonColor='#3498db' title="Notifications" onPress={() => {}}>
                <Icon name="rocket" style={styles.actionButtonIcon} />
              </ActionButton.Item>
              <ActionButton.Item buttonColor='#1abc9c' title="All Tasks" onPress={() => {}}>
                <Icon name="rocket" style={styles.actionButtonIcon} />
              </ActionButton.Item>
            </ActionButton>
          </View>
        );
      }
    }

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  map: {
    width: width,
    height: height,
    zIndex: 998
  },
  radius: {
    height: 50,
    width: 50,
    borderRadius: 50 / 2,
    overflow: 'hidden',
    backgroundColor: 'rgba(0, 122, 255, 0.1)',
    borderWidth: 1,
    borderColor: 'rgba(0, 122, 255, 0.3)',
    alignItems: 'center',
    justifyContent: 'center'
  },
  marker: {
    height: 20,
    width: 20,
    borderWidth: 3,
    borderColor: 'white',
    borderRadius: 20 / 2,
    overflow: 'hidden',
    backgroundColor: '#007AFF'
  },
  actionButton: {
    position: 'absolute',
    width: 20,
    height: 20,
    top: 10,
    left: 10,
    zIndex: 999
  },
  actionButtonIcon: {
    fontSize: 20,
    height: 22,
    color: 'white'
  }
});

I had the same problem.我有同样的问题。 I solved it by giving the map a negative z-index.我通过给地图一个负的 z-index 来解决它。
Also, I used flex: 1, instead of width and height, but that shouldn't make a difference.另外,我使用了flex: 1,而不是宽度和高度,但这应该没有区别。

Like:喜欢:

  map: {
    width: width,
    height: height,
    zIndex: -1
  },
  actionButton: {
    position: 'absolute',
    width: 20,
    height: 20,
    top: 10,
    left: 10,
    zIndex: 10
  },

这是一个长镜头,但尝试添加position: 'absolute'到您的地图样式并设置其坐标,看看会发生什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM