import React, { useState } from "react"; import { View, Text, TextInput, Pressable, StyleSheet, Alert, Platform } from "react-native"; import * as Notifications from "expo-notifications"; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowBanner: true, shouldShowList: true, shouldPlaySound: true, shouldSetBadge: false }) }); export default function App() { const [time, setTime] = useState("07:00"); const [active, setActive] = useState(false); const [alarmId, setAlarmId] = useState(null); const [message, setMessage] = useState( "Настрой время и включи будильник" ); async function enableAlarm() { const match = time.trim().match(/^([01]\d|2[0-3]):([0-5]\d)$/); if (!match) { Alert.alert("Неверное время", "Введи время в формате 07:00"); return; } try { const permission = await Notifications.requestPermissionsAsync(); if (!permission.granted) { Alert.alert( "Нет разрешения", "Разреши уведомления Roman Alarm в настройках iPhone." ); return; } if (alarmId) { await Notifications.cancelScheduledNotificationAsync(alarmId); } const hour = Number(match[1]); const minute = Number(match[2]); const id = await Notifications.scheduleNotificationAsync({ content: { title: "⏰ Roman Alarm", body: "Пора вставать! Начни свой день.", sound: "default" }, trigger: { type: Notifications.SchedulableTriggerInputTypes.DAILY, hour, minute } }); setAlarmId(id); setActive(true); setMessage("Будильник включён на " + time); } catch (error) { setMessage("Не удалось включить будильник: " + error.message); } } async function disableAlarm() { try { if (alarmId) { await Notifications.cancelScheduledNotificationAsync(alarmId); } setAlarmId(null); setActive(false); setMessage("Будильник выключен"); } catch (error) { setMessage("Не удалось выключить: " + error.message); } } return ( ◷ Roman Alarm Твой день начинается здесь ВРЕМЯ БУДИЛЬНИКА Формат: часы и минуты, например 07:30 {active ? "Выключить будильник" : "Включить будильник"} {message} Уведомления приходят через iOS. Разреши звук уведомлений для приложения и проверь режимы Фокусирования. ); } const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: "#0b1020", padding: 24, paddingTop: Platform.OS === "ios" ? 80 : 50 }, logo: { color: "#9587ff", fontSize: 30, fontWeight: "bold", textAlign: "center" }, subtitle: { color: "#aab5ce", textAlign: "center", marginTop: 10, marginBottom: 40 }, card: { backgroundColor: "#182238", borderRadius: 24, padding: 24, alignItems: "center" }, caption: { color: "#9aa8c5", fontSize: 12, letterSpacing: 2 }, time: { color: "white", fontSize: 56, fontWeight: "bold", textAlign: "center", marginVertical: 18, minWidth: 200 }, hint: { color: "#9aa8c5", fontSize: 12, marginBottom: 24 }, button: { backgroundColor: "#6557f5", borderRadius: 15, padding: 17, width: "100%", alignItems: "center" }, offButton: { backgroundColor: "#34415a" }, buttonText: { color: "white", fontSize: 16, fontWeight: "bold" }, status: { color: "#b7c5df", marginTop: 20, textAlign: "center" }, note: { color: "#8d9ab4", marginTop: 25, textAlign: "center", lineHeight: 21 } });