Im learning react native and cant get my page to scroll, I have tried to simplify it and use simple text and not my call back but literally nothing is working
Any help would be great
My results screen:
import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, ActivityIndicator, ScrollView, useWindowDimensions } from 'react-native';
import RenderHTML from 'react-native-render-html';
const ProgressScreen = ({ route }) => {
const { plan, loading, error } = route.params || {};
const [parsedPlan, setParsedPlan] = useState(null);
const { width } = useWindowDimensions();
useEffect(() => {
if (plan) {
try {
const parsedData = JSON.parse(plan);
setParsedPlan(parsedData);
} catch (e) {
console.error('Error parsing plan data:', e);
}
}
}, [plan]);
if (loading) {
return (
<View style={styles.container}>
<ActivityIndicator size="large" color="#fff" />
<Text style={styles.loadingText}>Loading...</Text>
</View>
);
}
if (error) {
return (
<View style={styles.container}>
<Text style={styles.errorText}>{error}</Text>
</View>
);
}
if (!parsedPlan) {
return (
<View style={styles.container}>
<Text style={styles.errorText}>No plan data available</Text>
</View>
);
}
return (
<ScrollView style={styles.container} contentContainerStyle={styles.scrollContent}>
<Text style={styles.titleText}>{parsedPlan.title}</Text>
<Text style={styles.greetingText}>{parsedPlan.greeting}</Text>
<Text style={styles.heading}>Ingredients:</Text>
{parsedPlan.ingredients && (
<RenderHTML
contentWidth={width}
source={{ html: parsedPlan.ingredients }}
baseStyle={{ color: '#fff' }}
/>
)}
<Text style={styles.heading}>Instructions:</Text>
{parsedPlan.instructions && (
<RenderHTML
contentWidth={width}
source={{ html: parsedPlan.instructions }}
baseStyle={{ color: '#fff' }}
/>
)}
<Text style={styles.heading}>Nutritional Value:</Text>
<Text style={styles.nutritionalText}>{parsedPlan.nutritional_value}</Text>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgb(9, 9, 11)',
},
scrollContent: {
padding: 20, // padding for the content inside the ScrollView
},
loadingText: {
color: '#fff',
marginTop: 10,
},
errorText: {
color: 'red',
},
titleText: {
fontSize: 24,
color: '#fff',
marginBottom: 10,
},
greetingText: {
fontSize: 16,
color: '#fff',
marginBottom: 20,
},
heading: {
fontSize: 20,
color: '#fff',
marginTop: 20,
},
nutritionalText: {
fontSize: 16,
color: '#fff',
marginTop: 10,
},
});
export default ProgressScreen;
for context my screen thats navigating us to the progressScreen
import React, {useState} from 'react';
import {View, TextInput, Button, Text, StyleSheet, Image, TouchableOpacity, ActivityIndicator} from 'react-native';
import axios from 'axios';
const CustomCheckbox = ({isChecked, onPress}) => {
return (
<TouchableOpacity onPress={onPress} style={[styles.checkboxBase, isChecked && styles.checkboxChecked]}>
{isChecked && <View style={styles.checkboxInner} />}
</TouchableOpacity>
);
};
const MainScreen = ({navigation}) => {
const [loading, setLoading] = useState(false);
const [textInput, setTextInput] = useState('');
const [selectedPeople, setSelectedPeople] = useState('1');
const [checkboxes, setCheckboxes] = useState({
lowFODMAP: false,
glutenFree: false,
dairyFree: false,
vegetarian: false,
vegan: false,
lowCalorie: false,
});
const handleCookPress = async () => {
try {
setLoading(true);
const response = await axios.post('endpoint', {
content: textInput,
fodmap: checkboxes.lowFODMAP || false,
dairy: checkboxes.dairyFree || false,
gluten: checkboxes.glutenFree || false,
veggie: checkboxes.vegetarian || false,
vegan: checkboxes.vegan || false,
calorie: checkboxes.lowCalorie || false,
people: selectedPeople || 1,
});
if (response.data.status === 200) {
setLoading(false);
navigation.navigate('ProgressScreen', { plan: response.data.data, loading: false });
} else {
setLoading(false);
navigation.navigate('ProgressScreen', { error: response.data.message, loading: false });
}
} catch (error) {
console.error('Axios error:', error.response || error.message);
navigation.navigate('ProgressScreen', { error: 'An error occurred', loading: false });
}
};
const handleCheckboxChange = (key) => {
setCheckboxes({...checkboxes, [key]: !checkboxes[key]});
};
return (
<View style={styles.container}>
<Image
source={{uri: '/img/icon.fb33606c.png'}} // Replace with your image URL
style={styles.image}
resizeMode="contain"
/>
<TextInput
style={styles.input}
placeholder="I would like to make a cherry pie..."
placeholderTextColor="#ccc"
value={textInput}
onChangeText={setTextInput}
/>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.lowFODMAP}
onPress={() => handleCheckboxChange('lowFODMAP')}
/>
<Text style={styles.label}>Low FODMAP</Text>
</View>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.glutenFree}
onPress={() => handleCheckboxChange('glutenFree')}
/>
<Text style={styles.label}>Gluten and Wheat Free</Text>
</View>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.dairyFree}
onPress={() => handleCheckboxChange('dairyFree')}
/>
<Text style={styles.label}>Dairy Free</Text>
</View>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.vegetarian}
onPress={() => handleCheckboxChange('vegetarian')}
/>
<Text style={styles.label}>Vegetarian</Text>
</View>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.vegan}
onPress={() => handleCheckboxChange('vegan')}
/>
<Text style={styles.label}>Vegan</Text>
</View>
<View style={styles.checkboxContainer}>
<CustomCheckbox
isChecked={checkboxes.lowCalorie}
onPress={() => handleCheckboxChange('lowCalorie')}
/>
<Text style={styles.label}>Low Calorie</Text>
</View>
<TouchableOpacity
style={styles.button}
onPress={handleCookPress}
disabled={loading} // Optionally disable the button while loading
>
{loading ? (
<ActivityIndicator size="small" color="#ffffff" />
) : (
<Text style={styles.buttonText}>Get me a recipe</Text>
)}
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: 'rgb(9, 9, 11)',
},
image: {
width: '100%',
height: 200,
marginBottom: 20,
marginTop: 30,
},
input: {
borderWidth: 1,
borderColor: '#fff',
color: '#fff',
padding: 10,
marginBottom: 20,
borderRadius: 5,
},
checkboxContainer: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 10,
},
label: {
marginLeft: 8,
color: '#fff',
},
button: {
backgroundColor: 'rgb(140, 7, 24)',
padding: 15,
borderRadius: 10,
alignItems: 'center',
marginTop: 20,
},
buttonText: {
color: '#fff',
fontSize: 16,
fontWeight: 'bold',
},
checkboxBase: {
width: 24,
height: 24,
borderRadius: 10,
borderWidth: 2,
borderColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
checkboxChecked: {
backgroundColor: '#fff',
},
checkboxInner: {
width: 12,
height: 12,
borderRadius: 10,
backgroundColor: 'rgb(140, 7, 24)',
},
});
export default MainScreen;
I have tried to use just lipsum text and not use API data but its not working.