Commit eded323f authored by Malsha Jayakody's avatar Malsha Jayakody

new changes

parent fbc714d4
This diff is collapsed.
import React, { useState } from 'react'; import React, {useState} from 'react';
import { View, StyleSheet, Image, TouchableOpacity, PermissionsAndroid, Text, ScrollView } from 'react-native'; import {
import { launchCamera, launchImageLibrary } from 'react-native-image-picker'; View,
import { COLORS, IMGS, ROUTES } from '../../../constants'; StyleSheet,
Image,
TouchableOpacity,
PermissionsAndroid,
Text,
ScrollView,
ActivityIndicator,
} from 'react-native';
import {launchCamera, launchImageLibrary} from 'react-native-image-picker';
import {COLORS, IMGS, ROUTES} from '../../../constants';
import Button from '../../../components/Button'; import Button from '../../../components/Button';
import axios from 'axios'; // Import Axios import axios from 'axios'; // Import Axios
const Camera = ({ navigation }) => { const Camera = ({navigation}) => {
const [cameraPhoto, setCameraPhoto] = useState(); const [cameraPhoto, setCameraPhoto] = useState();
const [galleryPhoto, setGalleryPhoto] = useState(); const [galleryPhoto, setGalleryPhoto] = useState();
const REACT_APP_API_URL='https://us-central1-skin-condition-detection.cloudfunctions.net/predict'; const REACT_APP_API_URL =
'https://us-central1-skin-condition-detection.cloudfunctions.net/predict';
const [prediction, setPrediction] = useState(null); const [prediction, setPrediction] = useState(null);
const [loading, setLoading] = useState(false);
const [photo, setPhoto] = useState(null); const [photo, setPhoto] = useState(null);
let options = { let options = {
saveToPhotos: true, saveToPhotos: true,
mediaType: 'photo', mediaType: 'photo',
...@@ -41,7 +49,7 @@ const Camera = ({ navigation }) => { ...@@ -41,7 +49,7 @@ const Camera = ({ navigation }) => {
} }
}; };
const submitPhoto = async (photoUri) => { const submitPhoto = async photoUri => {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append('file', { formData.append('file', {
...@@ -66,7 +74,6 @@ const Camera = ({ navigation }) => { ...@@ -66,7 +74,6 @@ const Camera = ({ navigation }) => {
} }
}; };
const handleContinue = () => { const handleContinue = () => {
let route; // Variable to store the route name let route; // Variable to store the route name
...@@ -98,13 +105,11 @@ const Camera = ({ navigation }) => { ...@@ -98,13 +105,11 @@ const Camera = ({ navigation }) => {
} else { } else {
// Handle the scenario where prediction or prediction.class is undefined // Handle the scenario where prediction or prediction.class is undefined
// Maybe navigate to an error page or show an alert // Maybe navigate to an error page or show an alert
console.log("No valid prediction available."); console.log('No valid prediction available.');
// navigation.navigate(ROUTES.DEFAULT_ROUTE); // Example fallback // navigation.navigate(ROUTES.DEFAULT_ROUTE); // Example fallback
} }
}; };
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.topContainer}> <View style={styles.topContainer}>
...@@ -113,31 +118,49 @@ const Camera = ({ navigation }) => { ...@@ -113,31 +118,49 @@ const Camera = ({ navigation }) => {
<Image style={styles.babyImage} source={IMGS.sk_1} /> <Image style={styles.babyImage} source={IMGS.sk_1} />
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
<TouchableOpacity onPress={openGallery} style={[styles.button, styles.buttonLeft]}> <TouchableOpacity
onPress={openGallery}
style={[styles.button, styles.buttonLeft]}>
<Image source={IMGS.sk_3} style={styles.buttonImage} /> <Image source={IMGS.sk_3} style={styles.buttonImage} />
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={openCamera} style={[styles.button, styles.buttonRight]}> <TouchableOpacity
onPress={openCamera}
style={[styles.button, styles.buttonRight]}>
<Image source={IMGS.sk_2} style={styles.buttonImage} /> <Image source={IMGS.sk_2} style={styles.buttonImage} />
</TouchableOpacity> </TouchableOpacity>
</View> </View>
{photo && ( {photo && (
<View style={styles.photoContainer}> <View style={styles.photoContainer}>
<Image source={{ uri: photo }} style={styles.photo} /> <Image source={{uri: photo}} style={styles.photo} />
</View> </View>
)} )}
</View> </View>
<Text style={styles.descriptionText}>'Use phone camera or select a photo from the gallery that clearly shows your skin.'</Text> <Text style={styles.descriptionText}>
'Use phone camera or select a photo from the gallery that clearly shows
your skin.'
</Text>
<View style={styles.bottomContainer}> <View style={styles.bottomContainer}>
{loading ? (
<View style={styles.loaderContainer}>
<ActivityIndicator size="large" color={COLORS.primary} />
</View>
) : (
<>
{!prediction && ( {!prediction && (
<> <>
<Text style={styles.resultsHeading}>Results will appear below</Text> <Text style={styles.resultsHeading}>
Results will appear below
</Text>
</> </>
)} )}
{prediction && ( {!loading && prediction && (
<View style={styles.predictionContainer}> <View style={styles.predictionContainer}>
<Text style={styles.predictionText}>Diagnosed Condition | හඳුනාගත් සමේ ආසාදනය: {prediction.class}</Text> <Text style={styles.predictionText}>
<Text style={styles.predictionText}>How sure are we | නිරවද්යතාව: {prediction.confidence}</Text> Diagnosed Condition | හඳුනාගත් සමේ ආසාදනය: {prediction.class}
</Text>
<Text style={styles.predictionText}>
How sure are we | නිරවද්යතාව: {prediction.confidence}
</Text>
</View> </View>
)} )}
<Button <Button
...@@ -145,6 +168,8 @@ const Camera = ({ navigation }) => { ...@@ -145,6 +168,8 @@ const Camera = ({ navigation }) => {
style={styles.nextButton} style={styles.nextButton}
onPress={handleContinue} onPress={handleContinue}
/> />
</>
)}
</View> </View>
</View> </View>
); );
...@@ -170,7 +195,6 @@ const styles = StyleSheet.create({ ...@@ -170,7 +195,6 @@ const styles = StyleSheet.create({
// This creates the curve effect for the background // This creates the curve effect for the background
}, },
buttonContainer: { buttonContainer: {
flexDirection: 'row', flexDirection: 'row',
marginTop: -26, marginTop: -26,
...@@ -225,18 +249,17 @@ const styles = StyleSheet.create({ ...@@ -225,18 +249,17 @@ const styles = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
marginHorizontal: 10, marginHorizontal: 10,
marginBottom: -10, marginBottom: -10,
marginTop:-40 marginTop: -40,
}, },
bottomContainer: { bottomContainer: {
flex: 2, flex: 2,
justifyContent: 'flex-end', justifyContent: 'flex-end',
marginBottom: 2, marginBottom: 2,
marginTop:20, marginTop: 20,
alignItems: 'center', alignItems: 'center',
backgroundColor: COLORS.blue, backgroundColor: COLORS.blue,
borderTopRightRadius: 75, borderTopRightRadius: 75,
borderTopLeftRadius: 75, borderTopLeftRadius: 75,
}, },
nextButton: { nextButton: {
width: '90%', width: '90%',
...@@ -245,13 +268,12 @@ const styles = StyleSheet.create({ ...@@ -245,13 +268,12 @@ const styles = StyleSheet.create({
backgroundColor: COLORS.white, backgroundColor: COLORS.white,
borderRadius: 20, borderRadius: 20,
alignSelf: 'center', alignSelf: 'center',
}, },
photoContainer: { photoContainer: {
elevation: 4, // Android shadow elevation: 4, // Android shadow
shadowColor: '#000', // iOS shadow shadowColor: '#000', // iOS shadow
shadowOffset: { width: 0, height: 2 }, // iOS shadow shadowOffset: {width: 0, height: 2}, // iOS shadow
shadowOpacity: 0.1, // iOS shadow shadowOpacity: 0.1, // iOS shadow
shadowRadius: 2, // iOS shadow shadowRadius: 2, // iOS shadow
borderRadius: 10, borderRadius: 10,
...@@ -276,11 +298,11 @@ const styles = StyleSheet.create({ ...@@ -276,11 +298,11 @@ const styles = StyleSheet.create({
// Add shadows if you like for better visual separation // Add shadows if you like for better visual separation
elevation: 4, // Android shadow elevation: 4, // Android shadow
shadowColor: '#000', // iOS shadow shadowColor: '#000', // iOS shadow
shadowOffset: { width: 0, height: 2 }, // iOS shadow shadowOffset: {width: 0, height: 2}, // iOS shadow
shadowOpacity: 0.1, // iOS shadow shadowOpacity: 0.1, // iOS shadow
shadowRadius: 2, // iOS shadow shadowRadius: 2, // iOS shadow
bottom:75, bottom: 75,
top:-10 top: -10,
}, },
resultsHeading: { resultsHeading: {
fontSize: 16, fontSize: 16,
...@@ -289,18 +311,20 @@ const styles = StyleSheet.create({ ...@@ -289,18 +311,20 @@ const styles = StyleSheet.create({
padding: 10, padding: 10,
textAlign: 'center', textAlign: 'center',
marginBottom: 90, marginBottom: 90,
marginLeft:0 marginLeft: 0,
}, },
resultImage: { resultImage: {
width: 100, // Set your desired width width: 100, // Set your desired width
height: 100, // Set your desired height height: 100, // Set your desired height
alignSelf: 'center', alignSelf: 'center',
marginVertical: 20, // Adjust margin as needed marginVertical: 20, // Adjust margin as needed
}, },
loaderContainer: {
}); flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default Camera; export default Camera;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment