Commit 99d41b03 authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS animateTo 方法

parent a6012200
...@@ -2,6 +2,8 @@ import React, {PropTypes, Component} from 'react' ...@@ -2,6 +2,8 @@ import React, {PropTypes, Component} from 'react'
import { import {
View, View,
UIManager, UIManager,
NativeModules,
Platform,
findNodeHandle, findNodeHandle,
requireNativeComponent, requireNativeComponent,
} from 'react-native' } from 'react-native'
...@@ -159,11 +161,19 @@ class MapView extends Component { ...@@ -159,11 +161,19 @@ class MapView extends Component {
} }
_sendCommand(command, params = null) { _sendCommand(command, params = null) {
switch (Platform.OS) {
case 'android':
UIManager.dispatchViewManagerCommand( UIManager.dispatchViewManagerCommand(
findNodeHandle(this), findNodeHandle(this),
UIManager.AMapView.Commands[command], UIManager.AMapView.Commands[command],
params, params,
) )
break;
case 'ios':
params[1] = 300
NativeModules.AMapViewManager[command](findNodeHandle(this), params)
break;
}
} }
render() { render() {
......
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h" #import "AMapMarker.h"
#import "AMapModel.h" #import "AMapModel.h"
...@@ -44,6 +45,26 @@ RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) ...@@ -44,6 +45,26 @@ RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag data:(NSArray *)data) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
AMapView *mapView = (AMapView *) viewRegistry[reactTag];
NSDictionary *params = data[0];
CFTimeInterval duration = [data[1] doubleValue] / 1000;
if (params[@"zoomLevel"]) {
[mapView setZoomLevel:[params[@"zoomLevel"] floatValue] animated: YES];
}
if (params[@"coordinate"]) {
NSDictionary *coordinate = params[@"coordinate"];
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(
[coordinate[@"latitude"] doubleValue],
[coordinate[@"longitude"] doubleValue]) animated:YES];
}
if (params[@"tilt"]) {
[mapView setCameraDegree:[params[@"tilt"] floatValue] animated:YES duration:duration];
}
}];
}
- (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate { - (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (mapView.onPress) { if (mapView.onPress) {
mapView.onPress(@{ mapView.onPress(@{
......
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