Files
iNaturalistReactNative/src/sharedHelpers/mail.ts
Ken-ichi Ueda 0ff55c14a2 fix: first obs button opens AI Camera, not advanced options
Also refactored email inbox opening to show errors and not rely on a 3rd
party.
2024-08-26 15:16:52 -07:00

41 lines
1.1 KiB
TypeScript

import { t } from "i18next";
import { Alert, Linking, Platform } from "react-native";
import Mailer from "react-native-mail";
function openInboxError() {
Alert.alert( t( "No-email-app-installed" ), t( "No-email-app-installed-body-check-other" ) );
}
export async function openInbox() {
let isSupported;
try {
isSupported = await Linking.canOpenURL( "message:0" );
} catch ( canOpenURLError ) {
openInboxError();
return;
}
if ( !isSupported ) openInboxError();
try {
await Linking.openURL( "message:0" );
} catch ( openURLError ) {
Alert.alert( t( "Something-went-wrong" ), openURLError.message );
}
}
export function composeEmail( emailAddress: string ) {
Mailer.mail( {
recipients: [emailAddress]
}, ( error: string ) => {
if ( Platform.OS === "ios" && error === "not_available" ) {
Alert.alert(
t( "No-email-app-installed" ),
t( "No-email-app-installed-body", { address: emailAddress } )
);
return;
}
if ( error ) {
Alert.alert( t( "Something-went-wrong" ), error );
}
} );
}