first commit
This commit is contained in:
43
滴滴淘/ddt_m/src/view/components/HOC/a.js
Normal file
43
滴滴淘/ddt_m/src/view/components/HOC/a.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
NativeModules,
|
||||
} from 'react-native';
|
||||
|
||||
const { HocNotificationService } = NativeModules;
|
||||
const Emitter = new NativeEventEmitter(HocNotificationService);
|
||||
|
||||
class BackgroundTimer {
|
||||
constructor() {
|
||||
this.uniqueId = 0;
|
||||
this.callbacks = {};
|
||||
|
||||
Emitter.addListener('HocNotificationService.timeout', (id) => {
|
||||
if (this.callbacks[id]) {
|
||||
const callbackById = this.callbacks[id];
|
||||
const { callback } = callbackById;
|
||||
if (!this.callbacks[id].interval) {
|
||||
delete this.callbacks[id];
|
||||
} else {
|
||||
RNBackgroundTimer.setTimeout(id, this.callbacks[id].timeout);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
runBackgroundTimer(callback, delay) {
|
||||
const EventEmitter = Platform.select({
|
||||
ios: () => NativeAppEventEmitter,
|
||||
android: () => DeviceEventEmitter,
|
||||
})();
|
||||
this.start(0);
|
||||
this.backgroundListener = EventEmitter.addListener(
|
||||
'backgroundTimer',
|
||||
() => {
|
||||
this.backgroundListener.remove();
|
||||
this.backgroundClockMethod(callback, delay);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default new BackgroundTimer();
|
||||
Reference in New Issue
Block a user