first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View 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();