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);
}
謝謝你。是的,這也讓我感到非常困惑 - 我不知道爲什麼,但Android Studio IDE自動完成了建議的「import com.facebook.react.uimanager.ReactProp;」在「import com.facebook.react.uimanager.annotations.ReactProp;」之前。爲什麼它甚至建議非註釋版本,因爲該路徑似乎不存在? –