Fix the screen make it flow better and make sense for a fitness workout app. make it…
- User
Fix the screen make it flow better and make sense for a fitness workout app. make it look better
import React, { useState, useContext } from 'react'; import { View, StyleSheet, ScrollView, Alert } from 'react-native'; import { Text, Button, ProgressBar, Card, Chip, useTheme } from 'react-native-paper'; import { AuthContext } from '../../context/AuthContext'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNPickerSelect from 'react-native-picker-select';
const STEPS = { FITNESS_GOALS: 0, SCHEDULE: 1, EXERCISES: 2, REST_RECOVERY: 3, REVIEW: 4, };
const RoutineCreationScreen = ({ navigation }) => { const theme = useTheme(); const { user } = useContext(AuthContext); const [currentStep, setCurrentStep] = useState(STEPS.FITNESS_GOALS); const [routineData, setRoutineData] = useState({ goal: '', customGoal: '', schedule: { frequency: '', duration: '', preferredDays: [], timeOfDay: '', intensity: '', }, exercises: [], rest: { restDays: [], cooldownRoutine: [], restBetweenSets: '30', }, routineName: '', });
const fitnessGoals = [ { label: 'Build Muscle', value: 'muscle', icon: 'dumbbell' }, { label: 'Lose Weight', value: 'weight', icon: 'scale' }, { label: 'Increase Flexibility', value: 'flexibility', icon: 'yoga' }, { label: 'Improve Endurance', value: 'endurance', icon: 'run' }, { label: 'Toning', value: 'toning', icon: 'human' }, { label: 'General Fitness', value: 'general', icon: 'heart-pulse' }, ];
const renderStepContent = () => { switch (currentStep) { case STEPS.FITNESS_GOALS: return ( Select Your Fitness Goals {fitnessGoals.map((goal) => ( <Chip key={goal.value} onPress={() => updateRoutineData('goal', goal.value)} selected={routineData.goal === goal.value} style={styles.goalChip} icon={() => } > {goal.label} ))} {routineData.goal === 'custom' && ( <TextInput label="Custom Goal" value={routineData.customGoal} onChangeText={(text) => updateRoutineData('customGoal', text)} style={styles.input} /> )} );
case STEPS.SCHEDULE: return ( <View> <Text style={styles.stepTitle}>Choose Your Workout Schedule</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('frequency', value)} items={[ { label: '1 day per week', value: '1' }, { label: '2 days per week', value: '2' }, { label: '3 days per week', value: '3' }, { label: '4 days per week', value: '4' }, { label: '5 days per week', value: '5' }, { label: '6 days per week', value: '6' }, { label: '7 days per week', value: '7' }, ]} placeholder={{ label: 'Select workout frequency', value: null }} value={routineData.schedule.frequency} style={pickerSelectStyles} /> <Text style={styles.inputLabel}>Workout Duration</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('duration', value)} items={[ { label: '30 minutes', value: '30' }, { label: '45 minutes', value: '45' }, { label: '60 minutes', value: '60' }, { label: '90 minutes', value: '90' }, ]} placeholder={{ label: 'Select workout duration', value: null }} value={routineData.schedule.duration} style={pickerSelectStyles} /> <Text style={styles.inputLabel}>Preferred Days</Text> <View style={styles.daysContainer}> {['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].map((day) => ( <Chip key={day} onPress={() => togglePreferredDay(day)} selected={routineData.schedule.preferredDays.includes(day)} style={styles.dayChip} > {day} </Chip> ))} </View> </View> ); // Add cases for EXERCISES, REST_RECOVERY, and REVIEW steps default: return null; }};
const updateRoutineData = (field, value) => { setRoutineData((prev) => ({ ...prev, [field]: value, })); };
const updateSchedule = (field, value) => { setRoutineData((prev) => ({ ...prev, schedule: { ...prev.schedule, [field]: value, }, })); };
const togglePreferredDay = (day) => { setRoutineData((prev) => { const currentDays = prev.schedule.preferredDays; const updatedDays = currentDays.includes(day) ? currentDays.filter((d) => d !== day) : [...currentDays, day];
return { ...prev, schedule: { ...prev.schedule, preferredDays: updatedDays, }, }; });};
const handleNext = () => { if (currentStep < STEPS.REVIEW) { setCurrentStep(currentStep + 1); } else { // Handle routine creation Alert.alert('Success', 'Routine created successfully!'); navigation.goBack(); } };
const handleBack = () => { if (currentStep > STEPS.FITNESS_GOALS) { setCurrentStep(currentStep - 1); } else { navigation.goBack(); } };
return ( <ProgressBar progress={(currentStep + 1) / (Object.keys(STEPS).length)} color={theme.colors.primary} style={styles.progressBar} />
{renderStepContent()} <View style={styles.buttonContainer}> <Button mode="outlined" onPress={handleBack}> {currentStep === STEPS.FITNESS_GOALS ? 'Cancel' : 'Back'} </Button> <Button mode="contained" onPress={handleNext}> {currentStep === STEPS.REVIEW ? 'Create Routine' : 'Next'} </Button> </View> </ScrollView>); };
const styles = StyleSheet.create({ container: { flex: 1, padding: 16, }, progressBar: { marginBottom: 16, }, stepTitle: { fontSize: 24, fontWeight: 'bold', marginBottom: 16, }, goalsContainer: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-between', }, goalChip: { margin: 4, width: '48%', }, inputLabel: { fontSize: 16, marginTop: 16, marginBottom: 8, }, daysContainer: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-between', }, dayChip: { margin: 4, }, buttonContainer: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 24, }, });
const pickerSelectStyles = StyleSheet.create({ inputIOS: { fontSize: 16, paddingVertical: 12, paddingHorizontal: 10, borderWidth: 1, borderColor: 'gray', borderRadius: 4, color: 'black', paddingRight: 30, }, inputAndroid: { fontSize: 16, paddingHorizontal: 10, paddingVertical: 8, borderWidth: 0.5, borderColor: 'gray', borderRadius: 8, color: 'black', paddingRight: 30, }, });
export default RoutineCreationScreen;
- Assistant
Absolutely! I'll help you enhance the
RoutineCreationScreenfor your fitness workout app by improving its flow, functionality, and visual appeal. Here's a comprehensive approach to refining your screen:-
Complete All Steps: Ensure that all steps (
EXERCISES,REST_RECOVERY,REVIEW) are implemented to provide a complete user experience. -
Enhanced Styling: Improve the overall UI with better spacing, consistent styling, and responsive layouts to make the app more visually appealing.
-
Handle Custom Goals: Add an option for users to input custom fitness goals.
-
Input Validation: Implement basic validation to ensure users provide necessary information before proceeding.
-
Optimized Component Structure: Refactor the code for better readability and maintenance.
-
Accessibility Improvements: Ensure that interactive elements are accessible.
Let's go through these enhancements step-by-step.
1. Complete All Steps
We'll implement the
EXERCISES,REST_RECOVERY, andREVIEWsteps to provide a full routine creation process.2. Enhanced Styling
Improve the styles to ensure consistency and a better visual hierarchy. We'll make use of React Native Paper's theming capabilities for cohesive styling.
3. Handle Custom Goals
Add a "Custom Goal" option in the fitness goals with corresponding input fields.
4. Input Validation
Ensure that users cannot proceed to the next step without selecting or entering required information.
5. Optimized Component Structure
Refactor state management and helper functions for clarity.
6. Accessibility Improvements
Ensure that all interactive elements are easily accessible and appropriately labeled.
Refactored Code
Below is the complete refactored and enhanced
RoutineCreationScreencomponent incorporating all the improvements:import React, { useState, useContext } from 'react'; import { View, StyleSheet, ScrollView, Alert } from 'react-native'; import { Text, Button, ProgressBar, Chip, useTheme, TextInput, Checkbox, } from 'react-native-paper'; import { AuthContext } from '../../context/AuthContext'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNPickerSelect from 'react-native-picker-select'; const STEPS = { FITNESS_GOALS: 0, SCHEDULE: 1, EXERCISES: 2, REST_RECOVERY: 3, REVIEW: 4, }; const RoutineCreationScreen = ({ navigation }) => { const theme = useTheme(); const { user } = useContext(AuthContext); const [currentStep, setCurrentStep] = useState(STEPS.FITNESS_GOALS); const [routineData, setRoutineData] = useState({ goal: '', customGoal: '', schedule: { frequency: '', duration: '', preferredDays: [], timeOfDay: '', intensity: '', }, exercises: [], rest: { restDays: [], cooldownRoutine: [], restBetweenSets: '', }, routineName: '', }); const fitnessGoals = [ { label: 'Build Muscle', value: 'muscle', icon: 'dumbbell' }, { label: 'Lose Weight', value: 'weight', icon: 'scale' }, { label: 'Increase Flexibility', value: 'flexibility', icon: 'yoga' }, { label: 'Improve Endurance', value: 'endurance', icon: 'run' }, { label: 'Toning', value: 'toning', icon: 'human' }, { label: 'General Fitness', value: 'general', icon: 'heart-pulse' }, { label: 'Custom Goal', value: 'custom', icon: 'pencil' }, ]; const renderStepContent = () => { switch (currentStep) { case STEPS.FITNESS_GOALS: return renderFitnessGoalsStep(); case STEPS.SCHEDULE: return renderScheduleStep(); case STEPS.EXERCISES: return renderExercisesStep(); case STEPS.REST_RECOVERY: return renderRestRecoveryStep(); case STEPS.REVIEW: return renderReviewStep(); default: return null; } }; const renderFitnessGoalsStep = () => ( <View> <Text style={styles.stepTitle}>Select Your Fitness Goals</Text> <View style={styles.goalsContainer}> {fitnessGoals.map((goal) => ( <Chip key={goal.value} onPress={() => updateRoutineData('goal', goal.value)} selected={routineData.goal === goal.value} style={styles.goalChip} icon={() => ( <Icon name={goal.icon} size={20} color={routineData.goal === goal.value ? '#fff' : theme.colors.primary} /> )} > {goal.label} </Chip> ))} </View> {routineData.goal === 'custom' && ( <TextInput label="Custom Goal" value={routineData.customGoal} onChangeText={(text) => updateRoutineData('customGoal', text)} style={styles.input} mode="outlined" placeholder="Enter your custom goal" /> )} </View> ); const renderScheduleStep = () => ( <View> <Text style={styles.stepTitle}>Choose Your Workout Schedule</Text> <Text style={styles.inputLabel}>Workout Frequency</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('frequency', value)} items={[ { label: '1 day per week', value: '1' }, { label: '2 days per week', value: '2' }, { label: '3 days per week', value: '3' }, { label: '4 days per week', value: '4' }, { label: '5 days per week', value: '5' }, { label: '6 days per week', value: '6' }, { label: '7 days per week', value: '7' }, ]} placeholder={{ label: 'Select workout frequency', value: null }} value={routineData.schedule.frequency} style={pickerSelectStyles} /> <Text style={styles.inputLabel}>Workout Duration</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('duration', value)} items={[ { label: '30 minutes', value: '30' }, { label: '45 minutes', value: '45' }, { label: '60 minutes', value: '60' }, { label: '90 minutes', value: '90' }, ]} placeholder={{ label: 'Select workout duration', value: null }} value={routineData.schedule.duration} style={pickerSelectStyles} /> <Text style={styles.inputLabel}>Preferred Days</Text> <View style={styles.daysContainer}> {['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].map((day) => ( <Chip key={day} onPress={() => togglePreferredDay(day)} selected={routineData.schedule.preferredDays.includes(day)} style={styles.dayChip} > {day} </Chip> ))} </View> <Text style={styles.inputLabel}>Time of Day</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('timeOfDay', value)} items={[ { label: 'Morning', value: 'morning' }, { label: 'Afternoon', value: 'afternoon' }, { label: 'Evening', value: 'evening' }, ]} placeholder={{ label: 'Select time of day', value: null }} value={routineData.schedule.timeOfDay} style={pickerSelectStyles} /> <Text style={styles.inputLabel}>Intensity</Text> <RNPickerSelect onValueChange={(value) => updateSchedule('intensity', value)} items={[ { label: 'Low', value: 'low' }, { label: 'Medium', value: 'medium' }, { label: 'High', value: 'high' }, ]} placeholder={{ label: 'Select intensity level', value: null }} value={routineData.schedule.intensity} style={pickerSelectStyles} /> </View> ); const renderExercisesStep = () => ( <View> <Text style={styles.stepTitle}>Select Your Exercises</Text> {/* Placeholder for exercise selection UI */} <Text> Implement exercise selection here. You can include search functionality, categories, and selection of multiple exercises. </Text> </View> ); const renderRestRecoveryStep = () => ( <View> <Text style={styles.stepTitle}>Configure Rest & Recovery</Text> <Text style={styles.inputLabel}>Rest Days</Text> <View style={styles.daysContainer}> {['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].map((day) => ( <Chip key={day} onPress={() => toggleRestDay(day)} selected={routineData.rest.restDays.includes(day)} style={styles.dayChip} > {day} </Chip> ))} </View> <Text style={styles.inputLabel}>Cooldown Routine</Text> {/* Placeholder for cooldown routine selection */} <Text> Implement cooldown routine selection here. You can include predefined cooldowns or allow users to create their own. </Text> <Text style={styles.inputLabel}>Rest Between Sets (seconds)</Text> <TextInput label="Rest Between Sets" value={routineData.rest.restBetweenSets} onChangeText={(text) => updateRest('restBetweenSets', text)} style={styles.input} mode="outlined" keyboardType="numeric" placeholder="e.g., 30" /> </View> ); const renderReviewStep = () => ( <View> <Text style={styles.stepTitle}>Review Your Routine</Text> <Card style={styles.reviewCard}> <Card.Title title="Routine Name" /> <Card.Content> <Text>{routineData.routineName || 'N/A'}</Text> </Card.Content> </Card> <Card style={styles.reviewCard}> <Card.Title title="Fitness Goal" /> <Card.Content> <Text> {routineData.goal === 'custom' ? routineData.customGoal : fitnessGoals.find((goal) => goal.value === routineData.goal)?.label || 'N/A'} </Text> </Card.Content> </Card> <Card style={styles.reviewCard}> <Card.Title title="Schedule" /> <Card.Content> <Text>Frequency: {routineData.schedule.frequency} days/week</Text> <Text>Duration: {routineData.schedule.duration} minutes</Text> <Text>Preferred Days: {routineData.schedule.preferredDays.join(', ') || 'N/A'}</Text> <Text>Time of Day: {capitalizeFirstLetter(routineData.schedule.timeOfDay) || 'N/A'}</Text> <Text>Intensity: {capitalizeFirstLetter(routineData.schedule.intensity) || 'N/A'}</Text> </Card.Content> </Card> {/* Add Cards for Exercises and Rest & Recovery as they are implemented */} </View> ); // Helper Function to Capitalize const capitalizeFirstLetter = (string) => { if (!string) return ''; return string.charAt(0).toUpperCase() + string.slice(1); }; // Update routine data const updateRoutineData = (field, value) => { setRoutineData((prev) => ({ ...prev, [field]: value, })); }; // Update schedule data const updateSchedule = (field, value) => { setRoutineData((prev) => ({ ...prev, schedule: { ...prev.schedule, [field]: value, }, })); }; // Update rest data const updateRest = (field, value) => { setRoutineData((prev) => ({ ...prev, rest: { ...prev.rest, [field]: value, }, })); }; // Toggle preferred workout days const togglePreferredDay = (day) => { setRoutineData((prev) => { const currentDays = prev.schedule.preferredDays; const updatedDays = currentDays.includes(day) ? currentDays.filter((d) => d !== day) : [...currentDays, day]; return { ...prev, schedule: { ...prev.schedule, preferredDays: updatedDays, }, }; }); }; // Toggle rest days const toggleRestDay = (day) => { setRoutineData((prev) => { const currentDays = prev.rest.restDays; const updatedDays = currentDays.includes(day) ? currentDays.filter((d) => d !== day) : [...currentDays, day]; return { ...prev, rest: { ...prev.rest, restDays: updatedDays, }, }; }); }; // Handle Next Button Press const handleNext = () => { if (!validateCurrentStep()) return; if (currentStep < STEPS.REVIEW) { setCurrentStep(currentStep + 1); } else { // Handle routine creation logic here Alert.alert('Success', 'Routine created successfully!'); navigation.goBack(); } }; // Handle Back Button Press const handleBack = () => { if (currentStep > STEPS.FITNESS_GOALS) { setCurrentStep(currentStep - 1); } else { navigation.goBack(); } }; // Validate Current Step const validateCurrentStep = () => { switch (currentStep) { case STEPS.FITNESS_GOALS: if (!routineData.goal) { Alert.alert('Validation Error', 'Please select a fitness goal.'); return false; } if (routineData.goal === 'custom' && !routineData.customGoal.trim()) { Alert.alert('Validation Error', 'Please enter your custom goal.'); return false; } return true; case STEPS.SCHEDULE: const { frequency, duration, preferredDays, timeOfDay, intensity } = routineData.schedule; if (!frequency || !duration || preferredDays.length === 0 || !timeOfDay || !intensity) { Alert.alert('Validation Error', 'Please complete all schedule fields.'); return false; } return true; case STEPS.EXERCISES: if (routineData.exercises.length === 0) { Alert.alert('Validation Error', 'Please select at least one exercise.'); return false; } return true; case STEPS.REST_RECOVERY: const { restDays, restBetweenSets } = routineData.rest; if (restDays.length === 0 || !restBetweenSets) { Alert.alert('Validation Error', 'Please complete all rest & recovery fields.'); return false; } return true; case STEPS.REVIEW: if (!routineData.routineName.trim()) { Alert.alert('Validation Error', 'Please provide a name for your routine.'); return false; } return true; default: return true; } }; return ( <ScrollView style={styles.container} contentContainerStyle={styles.contentContainer}> <ProgressBar progress={(currentStep + 1) / Object.keys(STEPS).length} color={theme.colors.primary} style={styles.progressBar} /> {renderStepContent()} <View style={styles.navigationContainer}> <Button mode="outlined" onPress={handleBack} style={styles.navButton}> {currentStep === STEPS.FITNESS_GOALS ? 'Cancel' : 'Back'} </Button> <Button mode="contained" onPress={handleNext} style={styles.navButton}> {currentStep === STEPS.REVIEW ? 'Create Routine' : 'Next'} </Button> </View> </ScrollView> ); }; // Styles const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, contentContainer: { padding: 16, }, progressBar: { height: 8, borderRadius: 4, marginBottom: 24, }, stepTitle: { fontSize: 24, fontWeight: '600', marginBottom: 16, }, goalsContainer: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-between', }, goalChip: { margin: 4, paddingVertical: 8, paddingHorizontal: 12, borderRadius: 20, backgroundColor: '#f0f0f0', }, inputLabel: { fontSize: 16, marginTop: 16, marginBottom: 8, fontWeight: '500', }, input: { marginBottom: 16, }, daysContainer: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-between', }, dayChip: { margin: 4, paddingVertical: 8, paddingHorizontal: 12, borderRadius: 20, backgroundColor: '#f0f0f0', }, navigationContainer: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 32, }, navButton: { flex: 1, marginHorizontal: 4, }, reviewCard: { marginVertical: 8, }, }); // Picker Styles const pickerSelectStyles = StyleSheet.create({ inputIOS: { fontSize: 16, paddingVertical: 12, paddingHorizontal: 10, borderWidth: 1, borderColor: '#ccc', borderRadius: 8, color: 'black', paddingRight: 30, backgroundColor: '#fff', marginBottom: 16, }, inputAndroid: { fontSize: 16, paddingHorizontal: 10, paddingVertical: 8, borderWidth: 0.5, borderColor: '#ccc', borderRadius: 8, color: 'black', paddingRight: 30, backgroundColor: '#fff', marginBottom: 16, }, }); export default RoutineCreationScreen;
Key Enhancements Explained
-
Complete Step Implementations:
- Exercises: Placeholder text is included to guide further development. You can integrate exercise selection features such as searching and categorizing.
- Rest & Recovery: Added selection for rest days and rest between sets. Placeholder for cooldown routine selection is also provided.
- Review: Users can review their inputs before finalizing the routine. This includes routine name, fitness goal, and schedule details.
-
Custom Goal Handling:
- Added a "Custom Goal" option in the
fitnessGoalsarray. - When selected, a
TextInputappears for users to enter their custom goal.
- Added a "Custom Goal" option in the
-
Input Validation:
- Before moving to the next step, the
validateCurrentStepfunction checks if the necessary fields are filled. - Alerts notify users of missing information, ensuring data completeness.
- Before moving to the next step, the
-
Enhanced Styling:
- Improved spacing, padding, and margin for better layout.
- Consistent styling for
Chipcomponents with background colors and padding. - Progress bar provides visual feedback on the user's progress through the steps.
-
Responsive Layout:
- Used
flexWrapandjustifyContentto ensure chips and other elements adjust gracefully across different screen sizes.
- Used
-
Accessibility:
- Ensured that interactive elements like buttons and chips are clearly labeled.
- Used appropriate
placeholdertexts andlabelsforTextInputcomponents.
-
Helper Functions:
capitalizeFirstLetterensures that display texts are properly formatted.
-
Code Organization:
- Separated rendering of each step into dedicated functions for better readability and maintenance.
- Grouped related state updates and toggle functions.
Further Recommendations
-
Implement Exercise Selection:
- Create an interface where users can search and select exercises, possibly integrating an exercise database.
- Allow categorization by muscle groups, difficulty levels, etc.
-
Cooldown Routine:
- Provide predefined cooldown options or allow users to customize their own.
- Integrate selection similar to exercises.
-
Routine Naming:
- In the
REVIEWstep, prompt users to enter a name for their routine if it hasn't been done in previous steps.
- In the
-
Persisting Data:
- Upon successful routine creation, save the data to a backend or local storage as per your app's architecture.
-
Navigation Enhancements:
- Implement smoother transitions between steps.
- Optionally, add a step indicator to show users their current position in the workflow.
-
Localization:
- If targeting multiple languages, ensure all text elements support localization.
-
Error Handling:
- Enhance error handling for network requests or data persistence operations.
By incorporating these enhancements, your
RoutineCreationScreenwill provide a seamless and engaging experience for users looking to create personalized fitness routines. -