Javascript 点击改变谷歌地图的主题-反应本机

Javascript 点击改变谷歌地图的主题-反应本机,javascript,react-native,Javascript,React Native,我有react本地地图,我正在将自定义地图主题设置为this.state.mapTheme constructor() { super(); this.state = { mapTheme: Themes.SANANDREAS } } 我有这样的渲染方法: render() { return ( <Container style ={styles.container}> <Bu

我有react本地地图,我正在将自定义地图主题设置为
this.state.mapTheme

constructor() {
    super();
    this.state = {
        mapTheme: Themes.SANANDREAS
    }
}
我有这样的渲染方法:

render() {
    return (
        <Container style ={styles.container}>      
            <Button rounded style={styles.contributeButton} onPress={() => {
                this.setState({
                    mapTheme: Themes.BROWNTHEME
                })
            }} iconLeft light>
              <Icon name='hand' />
              <Text>Contribute</Text>
            </Button>
            <MapView
                style={styles.map}
                provider = { MapView.PROVIDER_GOOGLE }
                customMapStyle = { this.state.mapTheme }
            ></MapView>
        </Container>
);}
render(){
返回(
{
这是我的国家({
mapTheme:Themes.BROWNTHEME
})
}}iconLeft light>
贡献
);}
这一切似乎都在工作,但当我在按下按钮时更改状态时,会调用render方法,但主题会调用 不要改变。我的两个主题都在发挥作用,但在媒体上什么也没发生。重新加载页面,但不使用新主题。我做错了什么?

考虑到组件的生命周期功能,如果传递了新的样式道具,它不会自动更新样式。在“ref”的帮助下直接更改主题后,您应该通过调用
\u updateStyle
来强制执行:

setMapRef = ref => this.mapRef = ref;

handleButtonClick = () => {
  this.setState({ mapTheme: Themes.BROWNTHEME }, () => {
    this.mapRef._updateStyle();
  })
}

render() {
  return (
     <Container>      
       <Button onPress={this.handleButtonClick}
         title="Update map theme"
       />
       <MapView
         ref={this.setMapRef}
         customMapStyle={this.state.mapTheme}
       />
     </Container>
  );
}
setMapRef=ref=>this.mapRef=ref;
把手按钮点击=()=>{
this.setState({mapTheme:Themes.BROWNTHEME},()=>{
this.mapRef._updateStyle();
})
}
render(){
返回(
);
}

是的,它成功了,有没有任何方法可以将过渡动画化?我建议谷歌转到
setNativeProps
+
animation
,因为
\u updateStyle
正在使用
setNativeProps
。但是,这似乎不是一个容易的主题来分别设置所有地图颜色的动画。嘿,我正在尝试使用google maps react在reactjs中实现相同的主题更改。是否有任何等效于
\u updateStyle()
函数的方法?我快速查看了实现,我猜
restyleMap
方法可能是等效的:
this.\u map=map}>
只是为了确保,这就是引用映射的方式,对吗?