Commit 6cc75801 authored by 7c00's avatar 7c00

Add eslint

parent a1ddb3d9
module.exports = {
parser: 'babel-eslint',
extends: ['airbnb'],
rules: {
semi: ['error', 'never'],
'react/jsx-filename-extension': 'off',
'react/require-default-props': 'off',
'import/no-extraneous-dependencies': 'off',
},
}
[ignore]
.*/node_modules/react-native/*
.*/example/node_modules/.*
[include]
[libs]
[lints]
[options]
.*/example/.*
<!--
进行问题反馈之前:
- 提供你正在使用的版本,以及 RN 版本
- 提供详细的错误信息,也许你需要 android studio 或 xcode
- 编译相关的问题(尤其是 iOS)需要你对编译过程有足够的了解
- 提供你正在使用的版本、RN 版本、设备信息
- 请尽可能详细地描述问题
- 编译相关的问题需要你对编译过程有所了解
以下情况 issue 会被 close:
- 确定是环境配置的问题,且没有提供足够的信息
- 问题不具备普遍性,且缺乏讨论
问题被关闭,仍然可以继续反馈,我会尽量回复
问题被关闭,仍可继续讨论
-->
example/
android/build/
Copyright (c) 2017 Qiu Xiang <i@7c00.cc>
Copyright (c) 2018 Qiu Xiang <i@7c00.cc>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
......
......@@ -160,17 +160,17 @@ import MapView from 'react-native-amap3d'
- [MultiPoint](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/MultiPoint.js#L5)
## 如何进行问题反馈
## 关于问题反馈
进行问题反馈之前:
- 提供你正在使用的版本,以及 RN 版本
- 提供详细的错误信息,也许你需要 android studio 或 xcode
- 编译相关的问题(尤其是 iOS)需要你对编译过程有足够的了解
- 提供你正在使用的版本、RN 版本、设备信息
- 请尽可能详细地描述问题
- 编译相关的问题需要你对编译过程有所了解
以下情况 issue 会被 close:
- 确定是环境配置的问题,且没有提供足够的信息
- 问题不具备普遍性,且缺乏讨论
问题被关闭,仍然可以继续反馈,我会尽量回复
问题被关闭,仍可继续讨论
[npm]: https://www.npmjs.com/package/react-native-amap3d
[version-badge]: https://badge.fury.io/js/react-native-amap3d.svg
......
This source diff could not be displayed because it is too large. You can view the blob instead.
declare module 'react-native' {
declare module.exports: any
}
\ No newline at end of file
......@@ -10,19 +10,32 @@
"maps"
],
"main": "src",
"files": [
"src",
"android/src",
"android/build.gradle",
"ios"
],
"repository": {
"type": "git",
"url": "https://github.com/qiuxiang/react-native-amap3d"
},
"scripts": {
"test": "flow"
"test": "eslint src && flow"
},
"peerDependencies": {
"react": ">=16",
"react-native": ">=0.47"
},
"devDependencies": {
"flow-bin": "^0.57.3",
"prop-types": "^15.6.0"
"babel-eslint": "^8.1.2",
"eslint": "^4.14.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"flow-bin": "^0.62.0",
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-native": "^0.51.0"
}
}
......@@ -3,10 +3,13 @@
*
* @flow
*/
import React, {PureComponent} from 'react'
import {findNodeHandle, UIManager} from 'react-native'
import { PureComponent } from 'react'
import { findNodeHandle, UIManager } from 'react-native'
export default class BaseComponent<T> extends PureComponent<T> {
export default class Component<T> extends PureComponent<T> {
/**
* 原生组件名称
*/
name: string
/**
......@@ -14,7 +17,7 @@ export default class BaseComponent<T> extends PureComponent<T> {
*
* @private
*/
_sendCommand(command: string, params?: any[]) {
sendCommand(command: string, params?: any[]) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager[this.name].Commands[command],
......
import {NativeModules, NativeEventEmitter} from 'react-native'
const {AMapOffline} = NativeModules
import { NativeModules, NativeEventEmitter } from 'react-native'
const { AMapOffline } = NativeModules
const eventEmitter = new NativeEventEmitter(AMapOffline)
export default {
......@@ -7,5 +8,5 @@ export default {
getCities: () => AMapOffline.getCities(),
download: name => AMapOffline.download(name),
remove: name => AMapOffline.remove(name),
addDownloadListener: callback => eventEmitter.addListener('download', callback)
addDownloadListener: callback => eventEmitter.addListener('download', callback),
}
......@@ -17,5 +17,4 @@ const Point = PropTypes.shape({
y: PropTypes.number.isRequired,
})
export {LatLng, Region, Point}
export { LatLng, Region, Point }
import {NativeModules} from 'react-native'
const {AMapUtils} = NativeModules
// @flow
import { NativeModules } from 'react-native'
const { AMapUtils } = NativeModules
export default {
distance: (lat1, lng1, lat2, lng2) => AMapUtils.distance(lat1, lng1, lat2, lng2)
/**
* 计算两点距离
*/
distance: (
lat1: number,
lng1: number,
lat2: number,
lng2: number,
) => AMapUtils.distance(lat1, lng1, lat2, lng2),
}
......@@ -27,5 +27,5 @@ export {
MultiPoint,
Navigation,
Utils,
Offline
Offline,
}
import PropTypes from 'prop-types'
import {ColorPropType, requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes'
import { ColorPropType, requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng } from '../PropTypes'
export default requireNativeComponent('AMapCircle', {
propTypes: {
......
import PropTypes from 'prop-types'
import {requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes'
import { requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng } from '../PropTypes'
/**
* 注意,热力图组件的 props 设置过一次之后便不能再更改
......
// @flow
import React from 'react'
import PropTypes from 'prop-types'
import {requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng, Region} from '../PropTypes'
import BaseComponent from '../BaseComponent'
import { requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng, Region } from '../PropTypes'
import Component from '../Component'
type Target = {
zoomLevel?: number,
......@@ -12,7 +12,7 @@ type Target = {
rotation?: number,
}
export default class MapView extends BaseComponent<any> {
export default class MapView extends Component<any> {
static propTypes = {
...ViewPropTypes,
......@@ -193,18 +193,18 @@ export default class MapView extends BaseComponent<any> {
onStatusChangeComplete: PropTypes.func,
}
name = 'AMapView'
/**
* 动画过渡到某个状态(坐标、缩放级别、倾斜度、旋转角度)
*/
animateTo(target: Target, duration?: number = 500) {
this._sendCommand('animateTo', [target, duration])
this.sendCommand('animateTo', [target, duration])
}
render() {
return <AMapView {...this.props}/>
return <AMapView {...this.props} />
}
name = 'AMapView'
}
const AMapView = requireNativeComponent('AMapView', MapView)
/* eslint-disable class-methods-use-this */
import React from 'react'
import PropTypes from 'prop-types'
import {Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View} from 'react-native'
import {LatLng, Point} from '../PropTypes'
import BaseComponent from '../BaseComponent'
import { Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View } from 'react-native'
import { LatLng, Point } from '../PropTypes'
import Component from '../Component'
export default class Marker extends BaseComponent {
const style = StyleSheet.create({
overlay: {
position: 'absolute',
},
})
export default class Marker extends Component {
static propTypes = {
...ViewPropTypes,
......@@ -135,52 +142,50 @@ export default class Marker extends BaseComponent {
onInfoWindowPress: PropTypes.func,
}
_renderInfoWindow(view) {
if (view) {
return <InfoWindow style={style.overlay}>{view}</InfoWindow>
componentDidUpdate() {
if (this.icon && Platform.OS === 'android') {
setTimeout(() => this.sendCommand('update'), 0)
}
}
_renderCustomMarker(icon) {
if (icon) {
this._icon = <View style={style.overlay}>{icon()}</View>
return this._icon
}
}
name = 'AMapMarker'
active() {
this._sendCommand('active')
this.sendCommand('active')
}
lockToScreen(x, y) {
this._sendCommand('lockToScreen', [x, y])
this.sendCommand('lockToScreen', [x, y])
}
componentDidUpdate() {
if (this._icon && Platform.OS === 'android') {
setTimeout(() => this._sendCommand('update'), 0)
renderCustomMarker(icon) {
if (icon) {
this.icon = <View style={style.overlay}>{icon()}</View>
return this.icon
}
return null
}
render() {
return <AMapMarker {...this.props}>
{this._renderCustomMarker(this.props.icon)}
{this._renderInfoWindow(this.props.children)}
</AMapMarker>
renderInfoWindow(view) {
if (view) {
return <InfoWindow style={style.overlay}>{view}</InfoWindow>
}
return null
}
name = 'AMapMarker'
render() {
return (
<AMapMarker {...this.props}>
{this.renderCustomMarker(this.props.icon)}
{this.renderInfoWindow(this.props.children)}
</AMapMarker>
)
}
}
const AMapMarker = requireNativeComponent('AMapMarker', Marker)
const InfoWindow = requireNativeComponent('AMapInfoWindow', {
propTypes: {
...ViewPropTypes,
}
})
const style = StyleSheet.create({
overlay: {
position: 'absolute',
},
})
import React, {PureComponent} from 'react'
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import {requireNativeComponent, ViewPropTypes} from 'react-native'
import { requireNativeComponent, ViewPropTypes } from 'react-native'
export default class MultiPoint extends PureComponent {
static propTypes = {
......@@ -9,14 +9,12 @@ export default class MultiPoint extends PureComponent {
/**
* 节点
*/
points: PropTypes.arrayOf(
PropTypes.shape({
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired,
title: PropTypes.string,
subtitle: PropTypes.string,
})
).isRequired,
points: PropTypes.arrayOf(PropTypes.shape({
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired,
title: PropTypes.string,
subtitle: PropTypes.string,
})).isRequired,
/**
* 图标
......@@ -29,14 +27,14 @@ export default class MultiPoint extends PureComponent {
onItemPress: PropTypes.func,
}
_onItemPress = event => {
onItemPress = ({ nativeEvent }) => {
if (this.props.onItemPress) {
this.props.onItemPress(this.props.points[event.nativeEvent.index])
this.props.onItemPress(this.props.points[nativeEvent.index])
}
}
render() {
return <AMapMultiPoint {...this.props} onItemPress={this._onItemPress}/>
return <AMapMultiPoint {...this.props} onItemPress={this.onItemPress} />
}
}
......
import PropTypes from 'prop-types'
import {ColorPropType, requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes'
import { ColorPropType, requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng } from '../PropTypes'
export default requireNativeComponent('AMapPolygon', {
propTypes: {
......
import React, {PureComponent} from 'react'
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import {ColorPropType, Platform, processColor, requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes'
import { ColorPropType, Platform, processColor, requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng } from '../PropTypes'
export default class Polyline extends PureComponent {
static propTypes = {
......@@ -66,7 +66,7 @@ export default class Polyline extends PureComponent {
},
}),
}
return <AMapPolyline {...props}/>
return <AMapPolyline {...props} />
}
}
......
// @flow
import React from 'react'
import PropTypes from 'prop-types'
import {ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes'
import BaseComponent from '../BaseComponent'
import { ViewPropTypes } from 'react-native'
import { LatLng } from '../PropTypes'
import Component from '../Component'
export default class Base extends BaseComponent<any> {
export default class Base extends Component<any> {
static propTypes = {
...ViewPropTypes,
......@@ -24,13 +23,13 @@ export default class Base extends BaseComponent<any> {
* 路线规划
*/
calculateRoute(start: LatLng, end: LatLng, way: LatLng[] = []) {
this._sendCommand('calculateRoute', [start, end, way])
this.sendCommand('calculateRoute', [start, end, way])
}
/**
* 开始导航
*/
start() {
this._sendCommand('start')
this.sendCommand('start')
}
}
// @flow
import React from 'react'
import {requireNativeComponent} from 'react-native'
import { requireNativeComponent } from 'react-native'
import Base from './Base'
export default class Drive extends Base {
render() {
return <AMapDrive {...this.props}/>
return <AMapDrive {...this.props} />
}
name = 'AMapDrive'
......
// @flow
import React from 'react'
import {requireNativeComponent} from 'react-native'
import { requireNativeComponent } from 'react-native'
import Base from './Base'
export default class Ride extends Base {
render() {
return <AMapRide {...this.props}/>
return <AMapRide {...this.props} />
}
name = 'AMapRide'
}
const AMapRide = requireNativeComponent('AMapRide', Ride)
// @flow
import React from 'react'
import {requireNativeComponent} from 'react-native'
import { requireNativeComponent } from 'react-native'
import Base from './Base'
export default class Walk extends Base {
render() {
return <AMapWalk {...this.props}/>
return <AMapWalk {...this.props} />
}
name = 'AMapWalk'
}
const AMapWalk = requireNativeComponent('AMapWalk', Walk)
......@@ -2,4 +2,4 @@ import Drive from './Drive'
import Ride from './Ride'
import Walk from './Walk'
export default {Drive, Ride, Walk}
export default { Drive, Ride, Walk }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment