2016-03-08 32 views
1

我在Android平台上构建了一个地图Native UI组件。当在视图中导入视图时,因为此React Native Android Native UI组件@ReactProps不执行

<AMapView style={styles.mapContainer} mode={2} onRegionChange={this._onReginChange.bind(this)}/> 

onRegionChange事件被执行,但属性方法不执行。 enter link description here

class AMapCustomView extends Component { 
    constructor(props) { 
     super(props) 
     this._onRegionChange = this._onRegionChange.bind(this) 
    } 

    _onRegionChange(event: Event) { 
     if (!this.props.onRegionChange) { 
      return 
     } 
     this.props.onRegionChange(event.nativeEvent) 
    } 

    render() { 
     return <RCTAMap {...this.props} onRegionChange={this._onRegionChange}/> 
    } 
} 

AMapCustomView.propTypes = { 
    ...View.propTypes, 
    mode: PropTypes.number, 
    onRegionChange: PropTypes.func 
} 

var RCTAMap = requireNativeComponent('RCTAMap', AMapCustomView) 

module.exports = AMapCustomView; 

Java代码:

@Override 
public Map getExportedCustomDirectEventTypeConstants() { 
    return MapBuilder.of(
      AMapLocationEvent.EVENT_NAME, MapBuilder.of("registrationName", "onRegionChange") 
    ); 
} 


@ReactProp(name="mode", defaultInt = 1) 
public void setMode(AMapView mapView, int type) { 
    Log.d(TAG, "mode:" + type); 
} 

回答

3

确保你import com.facebook.react.uimanager.annotations.ReactProp;,我觉得用来改变路径和老ReactProp将在近期没有更多的工作作出反应原生版本。

+0

谢谢你。是的,这也让我感到非常困惑 - 我不知道为什么,但Android Studio IDE自动完成了建议的“import com.facebook.react.uimanager.ReactProp;”在“import com.facebook.react.uimanager.annotations.ReactProp;”之前。为什么它甚至建议非注释版本,因为该路径似乎不存在? –