Open History to see the last commit
1import { requireNativeModule } from "expo";
2import { useEffect, useMemo, useState } from "react";
3import { AppState, Platform } from "react-native";
4import { createMessageTimeFormatter } from "./messageTimestamp";
5
6function systemUses24HourClock() {
7 if (Platform.OS !== "android") return undefined;
8 return requireNativeModule<{ is24HourFormat(): boolean }>("T3NativeControls").is24HourFormat();
9}
10
11export function useMessageTimeFormatter() {
12 const [is24Hour, setIs24Hour] = useState(systemUses24HourClock);
13 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Refresh the native clock preference when Android returns to the foreground.
14 useEffect(() => {
15 if (Platform.OS !== "android") return;
16 const subscription = AppState.addEventListener("change", (state) => {
17 if (state === "active") setIs24Hour(systemUses24HourClock());
18 });
19 return () => subscription.remove();
20 }, []);
21 return useMemo(() => createMessageTimeFormatter(is24Hour), [is24Hour]);
22}