add function to check platform and return alert
This commit is contained in:
parent
92e211a21a
commit
d3db06a90c
10
src/lib/alert-messages/constants.ts
Normal file
10
src/lib/alert-messages/constants.ts
Normal 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.",
|
||||
},
|
||||
};
|
@ -1,10 +1,16 @@
|
||||
export const cameraPermissionsDenied = {
|
||||
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.",
|
||||
},
|
||||
import { Alert, Platform } from "react-native";
|
||||
import { CAMERA_PERMISSION_DENIED } from "./constants";
|
||||
|
||||
const ALERT_TYPE = {
|
||||
camera: CAMERA_PERMISSION_DENIED,
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
@ -1,8 +1,6 @@
|
||||
import React, { useCallback, useState } from "react";
|
||||
import {
|
||||
Alert,
|
||||
Keyboard,
|
||||
Platform,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
@ -12,7 +10,7 @@ import {
|
||||
import DropDownPicker from "react-native-dropdown-picker";
|
||||
// @ts-ignore
|
||||
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";
|
||||
|
||||
interface CameraScreenParams {
|
||||
@ -72,16 +70,9 @@ export default function RecordScreen({ navigation }): React.JSX.Element {
|
||||
// Location
|
||||
const [location, setLocation] = useState<string>("");
|
||||
|
||||
const { android, ios } = cameraPermissionsDenied;
|
||||
|
||||
const handleSubmit = () => {
|
||||
// Next block's alert message are OS specific
|
||||
if (!hasPermission) {
|
||||
if (Platform.OS === "android") {
|
||||
return Alert.alert(android.title, android.message);
|
||||
} else {
|
||||
return Alert.alert(ios.title, ios.message);
|
||||
}
|
||||
return showAlert("camera");
|
||||
}
|
||||
|
||||
// needs to pass info as params or store in a context/state provider
|
||||
|
Loading…
Reference in New Issue
Block a user