add function to check platform and return alert

This commit is contained in:
Loewy 2024-02-12 12:51:04 -08:00
parent 92e211a21a
commit d3db06a90c
3 changed files with 27 additions and 20 deletions

View File

@ -0,0 +1,10 @@
export const CAMERA_PERMISSION_DENIED = {
android: {
title: "In order to use the camera, you need to grant app permissions.",
message: "Please go to Railbird > App Info and grant permissions. ",
},
ios: {
title: "In order to use the camera, you need to grant app permissions.",
message: "Please go to Settings > Railbird > Camera and grant permissions.",
},
};

View File

@ -1,10 +1,16 @@
export const cameraPermissionsDenied = { import { Alert, Platform } from "react-native";
android: { import { CAMERA_PERMISSION_DENIED } from "./constants";
title: "In order to use the camera, you need to grant app permissions.",
message: "Please go to Railbird > App Info and grant permissions. ", const ALERT_TYPE = {
}, camera: CAMERA_PERMISSION_DENIED,
ios: { };
title: "In order to use the camera, you need to grant app permissions.",
message: "Please go to Settings > Railbird > Camera and grant permissions.", export const showAlert = (alertType: string) => {
}, const alert = ALERT_TYPE[alertType];
if (!alert) {
console.error("No alert matches this alert type:", alertType);
return;
}
const { title, message } = alert[Platform.OS];
Alert.alert(title, message);
}; };

View File

@ -1,8 +1,6 @@
import React, { useCallback, useState } from "react"; import React, { useCallback, useState } from "react";
import { import {
Alert,
Keyboard, Keyboard,
Platform,
Text, Text,
TextInput, TextInput,
TouchableOpacity, TouchableOpacity,
@ -12,7 +10,7 @@ import {
import DropDownPicker from "react-native-dropdown-picker"; import DropDownPicker from "react-native-dropdown-picker";
// @ts-ignore // @ts-ignore
import { useCameraPermission } from "react-native-vision-camera"; import { useCameraPermission } from "react-native-vision-camera";
import { cameraPermissionsDenied } from "../../lib/alert-messages"; import { showAlert } from "../../lib/alert-messages";
import { recordStyles as styles } from "./styles"; import { recordStyles as styles } from "./styles";
interface CameraScreenParams { interface CameraScreenParams {
@ -72,16 +70,9 @@ export default function RecordScreen({ navigation }): React.JSX.Element {
// Location // Location
const [location, setLocation] = useState<string>(""); const [location, setLocation] = useState<string>("");
const { android, ios } = cameraPermissionsDenied;
const handleSubmit = () => { const handleSubmit = () => {
// Next block's alert message are OS specific
if (!hasPermission) { if (!hasPermission) {
if (Platform.OS === "android") { return showAlert("camera");
return Alert.alert(android.title, android.message);
} else {
return Alert.alert(ios.title, ios.message);
}
} }
// needs to pass info as params or store in a context/state provider // needs to pass info as params or store in a context/state provider