-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
34 lines (27 loc) · 851 Bytes
/
index.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
/*
* @providesModule react-native-telephony
*/
import { NativeModules, NativeAppEventEmitter, Platform } from 'react-native'
const RNTelephony = Platform.OS === 'ios' ? {} : NativeModules.Telephony
const EVENT_PHONE_STATE = 'phoneState'
const PHONE_STATE_LISTENER = 'Telephony-PhoneStateListener'
const telephony = RNTelephony
if (Platform.OS === 'android' && telephony) {
telephony.addEventListener = (events, handler) => {
RNTelephony && RNTelephony.startListener(events)
NativeAppEventEmitter.addListener(
PHONE_STATE_LISTENER,
(result) => {
handler(result);
}
);
}
telephony.removeEventListener = () => {
RNTelephony && RNTelephony.stopListener()
NativeAppEventEmitter.removeEventListener(
PHONE_STATE_LISTENER,
() => {}
);
}
}
export default telephony