Added complete callback for flyTo

This commit is contained in:
Nick
2017-09-26 20:12:07 -07:00
parent 8efab247e8
commit 32cdc559b6
7 changed files with 46 additions and 25 deletions
+15 -1
View File
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { requireNativeComponent } from 'react-native';
import { isFunction, runNativeCommand } from '../utils';
import { isFunction, runNativeCommand, noop } from '../utils';
const DEFAULT_CENTER_COORDINATE = {
type: 'Point',
@@ -27,8 +27,11 @@ class MapView extends React.Component {
};
static EventTypes = {
// UI Interaction events
Press: 'press',
LongPress: 'longpress',
// Map change events
RegionWillChange: 'regionwillchange',
RegionIsChanging: 'regionischanging',
RegionDidChange: 'regiondidchange',
@@ -42,6 +45,9 @@ class MapView extends React.Component {
DidFinishRenderingMap: 'didfinishrenderingmap',
DidFinishRenderingMapFully: 'didfinishrenderingmapfully',
DidFinishLoadingStyle: 'didfinishloadingstyle',
// Animation completion events
FlyToComplete: 'flytocomplete',
};
static propTypes = {
@@ -174,6 +180,11 @@ class MapView extends React.Component {
* This event is triggered when a style has finished loading.
*/
onDidFinishLoadingStyle: PropTypes.func,
/**
* This event is triggered when a fly to animation is cancelled or completed
*/
onFlyToComplete: PropTypes.func,
};
static defaultProps = {
@@ -261,6 +272,9 @@ class MapView extends React.Component {
case MapView.EventTypes.DidFinishLoadingStyle:
propName = 'onDidFinishLoadingStyle';
break;
case MapView.EventTypes.FlyToComplete:
propName = 'onFlyToComplete';
break;
}
if (propName.length) {
+4 -20
View File
@@ -11,35 +11,19 @@ export function isFunction (fn) {
}
export function runNativeCommand (module, name, nativeRef, args = []) {
// android native command
const managerInstance = NativeModules.UIManager[module];
if (!managerInstance) {
throw new Error(`Could not find ${module}`);
}
// get react tag so we can find, this component on the otherside
const handle = findNodeHandle(nativeRef);
if (!handle) {
throw new Error(`Could not find handle for native ref ${module}.${name}`);
}
NativeModules.UIManager.dispatchViewManagerCommand(
handle,
managerInstance.Commands[name],
args,
);
return;
// android native command
if (IS_ANDROID) {
return;
}
// ios native command
const method = managerInstance[name];
if (!method) {
throw new Error(`Could not find method ${name} on module ${module}`);
}
method(handle, ...args);
}
function getManagerInstance (module) {
const obj = IS_ANDROID ? NativeModules.UIManager : NativeModules;
return obj[module];
}