2022-07-01 01:42:42 +00:00
|
|
|
import React, {useState} from 'react';
|
2022-06-30 06:50:52 +00:00
|
|
|
import {
|
2022-07-01 01:42:42 +00:00
|
|
|
Button,
|
2022-06-30 06:50:52 +00:00
|
|
|
SafeAreaView,
|
|
|
|
StatusBar,
|
2022-07-01 01:42:42 +00:00
|
|
|
TextInput,
|
2022-06-30 06:50:52 +00:00
|
|
|
useColorScheme,
|
2022-07-01 01:42:42 +00:00
|
|
|
Vibration,
|
2022-06-30 06:50:52 +00:00
|
|
|
View,
|
|
|
|
} from 'react-native';
|
2022-07-01 01:42:42 +00:00
|
|
|
import BackgroundTimer from 'react-native-background-timer';
|
|
|
|
import {Notifications} from 'react-native-notifications';
|
|
|
|
import Sound from 'react-native-sound';
|
2022-06-30 06:50:52 +00:00
|
|
|
|
2022-07-01 01:42:42 +00:00
|
|
|
const App = () => {
|
|
|
|
const dark = useColorScheme() === 'dark';
|
|
|
|
const alarm = new Sound('argon.mp3', Sound.MAIN_BUNDLE, error => {
|
|
|
|
if (error) throw new Error(error);
|
|
|
|
});
|
|
|
|
const [timer, setTimer] = useState('0');
|
2022-06-30 06:50:52 +00:00
|
|
|
|
2022-07-01 01:42:42 +00:00
|
|
|
Notifications.registerRemoteNotifications();
|
|
|
|
Notifications.events().registerNotificationOpened(
|
|
|
|
(notification, completion) => {
|
|
|
|
console.log('Notification opened:', notification);
|
|
|
|
alarm.stop();
|
|
|
|
Vibration.cancel();
|
|
|
|
completion();
|
|
|
|
},
|
2022-06-30 06:50:52 +00:00
|
|
|
);
|
|
|
|
|
2022-07-01 01:42:42 +00:00
|
|
|
const press = () => {
|
|
|
|
BackgroundTimer.setTimeout(() => {
|
|
|
|
alarm.play(_onEnd => Vibration.cancel());
|
|
|
|
Vibration.vibrate([0, 400, 600], /*repeat=*/ true);
|
|
|
|
Notifications.postLocalNotification({
|
|
|
|
title: 'title',
|
|
|
|
body: 'body',
|
|
|
|
badge: 1,
|
|
|
|
identifier: 'identifier',
|
|
|
|
payload: {},
|
|
|
|
sound: 'sound',
|
|
|
|
thread: 'thread',
|
|
|
|
type: 'type',
|
|
|
|
});
|
|
|
|
}, Number(timer));
|
2022-06-30 06:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-07-01 01:42:42 +00:00
|
|
|
<SafeAreaView style={{flex: 1}}>
|
|
|
|
<StatusBar barStyle={dark ? 'light-content' : 'dark-content'} />
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
margin: 10,
|
|
|
|
alignItems: 'center',
|
|
|
|
}}>
|
|
|
|
<TextInput placeholder="Timer" value={timer} onChangeText={setTimer} />
|
|
|
|
</View>
|
|
|
|
<View style={{margin: 30, marginTop: 'auto'}}>
|
|
|
|
<Button title="Run timer" onPress={press} />
|
|
|
|
</View>
|
2022-06-30 06:50:52 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|