react-native-anavi
Version:
react native amap navigation component, Android + iOS
106 lines (88 loc) • 2.82 kB
JavaScript
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View } from 'react-native';
import { LatLngPropType, PointPropType, mapEventsPropType } from '../prop-types';
import Component from './component';
const style = StyleSheet.create({
overlay: {
position: 'absolute'
}
});
const events = ['onInfoWindowPress', 'onPress', 'onDrag', 'onDragEnd', 'onDragStart'];
/**
* @ignore
*/
export default class Marker extends Component {
constructor(...args) {
super(...args);
_defineProperty(this, "nativeComponent", 'AMapMarker');
_defineProperty(this, "icon", void 0);
}
componentDidUpdate() {
if (this.icon && Platform.OS === 'android') {
setTimeout(() => this.call('update'), 0);
}
}
active() {
this.call('active');
}
update() {
this.call('update');
}
lockToScreen(x, y) {
this.call('lockToScreen', [x, y]);
}
renderCustomMarker(icon) {
if (icon) {
this.icon = /*#__PURE__*/React.createElement(View, {
style: style.overlay
}, icon());
return this.icon;
}
return null;
}
/* eslint-disable class-methods-use-this */
renderInfoWindow(view) {
if (view) {
// @ts-ignore
return /*#__PURE__*/React.createElement(InfoWindow, {
style: style.overlay
}, view);
}
return null;
}
render() {
const props = { ...this.props,
...this.handlers(events)
};
return /*#__PURE__*/React.createElement(AMapMarker, props, this.renderCustomMarker(this.props.icon), this.renderInfoWindow(this.props.children));
}
} // @ts-ignore
_defineProperty(Marker, "propTypes", { ...ViewPropTypes,
...mapEventsPropType(events),
coordinate: LatLngPropType.isRequired,
title: PropTypes.string,
description: PropTypes.string,
color: Platform.select({
android: PropTypes.oneOf(['azure', 'blue', 'cyan', 'green', 'magenta', 'orange', 'red', 'rose', 'violet', 'yellow']),
ios: PropTypes.oneOf(['red', 'green', 'purple'])
}),
icon: PropTypes.func,
image: PropTypes.string,
opacity: PropTypes.number,
draggable: PropTypes.bool,
flat: PropTypes.bool,
zIndex: PropTypes.number,
anchor: PointPropType,
centerOffset: PointPropType,
active: PropTypes.bool,
clickDisabled: PropTypes.bool,
infoWindowDisabled: PropTypes.bool
});
const AMapMarker = requireNativeComponent('AMapMarker', Marker); // @ts-ignore
const InfoWindow = requireNativeComponent('AMapInfoWindow', {
propTypes: { ...ViewPropTypes
}
});
//# sourceMappingURL=marker.js.map