Skip to content
Source
Sign inSign up

androidNotifications.ts

57 lines1.8 KB

1import Constants from "expo-constants";
2import { requireOptionalNativeModule } from "expo";
3import { Linking, Platform } from "react-native";
4​
5interface AndroidAgentNotifications {
6 configure(deviceId: string, userId: string, scheme: string, ongoingEnabled: boolean): void;
7 clear(): void;
8 setThreadOnScreen?(path: string | null): void;
9 openLiveUpdateSettings?(): boolean;
10 showShowcaseActivity?(scheme: string, data: Record<string, string>): void;
12​
13const native =
14 Platform.OS === "android"
15 ? requireOptionalNativeModule<AndroidAgentNotifications>("T3AgentNotifications")
16 : null;
17​
18export function supportsAndroidAgentNotifications(): boolean {
19 return typeof native?.configure === "function" && typeof native?.clear === "function";
21​
22function appScheme(): string {
23 const scheme = Constants.expoConfig?.scheme;
24 return (Array.isArray(scheme) ? scheme[0] : scheme) ?? "t3code";
26​
27export function configureAndroidAgentNotifications(
28 deviceId: string,
29 userId: string,
30 ongoingEnabled: boolean,
31): void {
32 native?.configure?.(deviceId, userId, appScheme(), ongoingEnabled);
34​
35export function showAndroidShowcaseAgentActivity(data: Record<string, string>): boolean {
36 if (!native?.showShowcaseActivity) return false;
37 native.showShowcaseActivity(appScheme(), data);
38 return true;
40​
41export function clearAndroidAgentNotifications(): void {
42 native?.clear?.();
44​
45export function setAndroidThreadOnScreen(path: string | null): void {
46 native?.setThreadOnScreen?.(path);
48​
49export function supportsAndroidLiveUpdateSettings(): boolean {
50 return Platform.OS === "android" && Number(Platform.Version) >= 36;
52​
53export async function openAndroidLiveUpdateSettings(): Promise<void> {
54 if (!native?.openLiveUpdateSettings?.()) {
55 await Linking.openSettings();
56 }