Closed sitannsu closed 4 months ago
I've been fighting this all day too.
`import { StatusBar } from 'expo-status-bar'; import { Platform, StyleSheet, Text, View } from 'react-native'; import { Header } from './src/Components/Header'; import { useEffect, useState, useRef} from 'react'; import React from 'react'; import { PomodoroContainer } from './src/Components/PomodoroContainer'; import { PomodoroButton } from './src/Components/PomodoroButton'; import { Timer } from './src/Components/Timer'; import as Notifications from 'expo-notifications'; import as Device from 'expo-device'; import BackgroundService from 'react-native-background-actions';
const FOCUS_TIME_MINUTES = 0.1 60 1000; const BREAK_TIME_MINUTES = 0.05 60 1000; const LONG_BREAK_TIME_MINUTES = 0.1 60 1000; const BREAK_TIMES = 3; const FOCUS = "Focus"; const BREAK = "Break"
const sleep = (time) => new Promise((resolve) => setTimeout(() => resolve(null), time));
const veryIntensiveTask = async (taskDataArguments) => {
// Example of an infinite loop task
const { delay } = taskDataArguments;
await new Promise(async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log(i);
await BackgroundService.updateNotification({taskDesc: Running...${i}
});
await sleep(delay);
}
});
};
const options = {
taskName: 'Example',
taskTitle: 'ExampleTask title',
taskDesc: 'ExampleTask description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
linkingURI: 'pomodoro://chat/jane', // See Deep Linking for more info
parameters: {
delay: 1000,
},
};
export default function App() {
const [timerCount, setTimerCount] = useState
const startBackgroundService = async () => { await BackgroundService.start(veryIntensiveTask, options); await BackgroundService.updateNotification({taskDesc: 'Running...'}); } const stopBackgroundService = async () => { await BackgroundService.stop(); } const startTimer = async () =>{ let id = setInterval(() => setTimerCount(prev => prev - 1000), 1000); setTimerIntervalId(id); }
function stopTimer(){ if(timerIntervalId !== null){ clearInterval(timerIntervalId); setTimerIntervalId(null); } }
function resetTimer(){ if(timerIntervalId !== null){ stopTimer(); } setTimerCount(FOCUS_TIME_MINUTES); setTimerMode(FOCUS); }
return (
); }
const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', flexDirection: 'column', alignContent: 'center', alignItems: 'center', justifyContent: 'center', minHeight: '10%', width: '100%' } }); `
Did you find a solution?
PR #208 worked for me
Duplicate of #208