forked from qiuxiang/react-native-baidumap-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.js
40 lines (37 loc) · 977 Bytes
/
component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Base component, contains some utils
*
* @flow
*/
import { PureComponent } from 'react'
import { findNodeHandle, UIManager } from 'react-native'
export default class Component<T> extends PureComponent<T> {
/**
* Must be defined in subclass if need to call native component method
*/
nativeComponentName: string
/**
* Call native method
*/
call(command: string, params?: any[]) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager[this.nativeComponentName].Commands[command],
params,
)
}
/**
* Generate event handlers
*/
handlers(events: string[]) {
return events.reduce((handlers, name) => {
// $FlowFixMe: I want to keep this simple
const handler = this.props[name]
if (handler) {
/* eslint-disable no-param-reassign */
handlers[name.replace(/^on/, 'onBaiduMap')] = event => handler(event.nativeEvent)
}
return handlers
}, {})
}
}