Skip to content

Commit

Permalink
use pressable instead of touchableOpacity
Browse files Browse the repository at this point in the history
  • Loading branch information
Felioh committed May 5, 2024
1 parent 34cfe5b commit f528863
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
10 changes: 5 additions & 5 deletions frontend/app/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TouchableOpacity, Text, SafeAreaView } from 'react-native';
import { Text, SafeAreaView, Pressable } from 'react-native';
import { Stack, useRouter } from 'expo-router';
import React, { useState } from 'react';
import ProfileButton from '../components/ProfileButton';
Expand Down Expand Up @@ -50,18 +50,18 @@ const HomeScreen = () => {
showAllAction={() => router.navigate('workouts')}
>
{workouts.map((workout, index) => (
<TouchableOpacity
<Pressable
onPress={() => router.navigate(`/workout/${workout._id}`)}
key={index}
>
<Card key={index}>
<Text style={styles.buttonText}>{workout.name}</Text>
</Card>
</TouchableOpacity>
</Pressable>
))}
<TouchableOpacity onPress={() => router.navigate('workout/create')}>
<Pressable onPress={() => router.navigate('workout/create')}>
<AddCard />
</TouchableOpacity>
</Pressable>
</HorizontalScrollView>
</SafeAreaView>
</>
Expand Down
7 changes: 3 additions & 4 deletions frontend/app/login.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useRouter } from 'expo-router';
import { Text, TextInput, TouchableOpacity, SafeAreaView } from 'react-native';
import { Text, TextInput, Pressable, SafeAreaView } from 'react-native';
import instance from '../interceptors';
import styles from '../styles';

Expand Down Expand Up @@ -51,10 +51,9 @@ const LoginScreen = () => {
underlineColorAndroid="transparent"
autoCapitalize="none"
/>
{/* TODO: use Pressable */}
<TouchableOpacity style={styles.buttonContainer} onPress={handleLogin}>
<Pressable style={styles.buttonContainer} onPress={handleLogin}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</Pressable>
</SafeAreaView>
);
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/workout/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLocalSearchParams } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { SafeAreaView, Text, TouchableOpacity } from 'react-native';
import { SafeAreaView, Text, Pressable } from 'react-native';
import styles from '../../styles';
import ExerciseCard from '../../components/ExerciseCard';
import HorizontalScrollView from '../../components/HorizontalScollView';
Expand Down Expand Up @@ -36,9 +36,9 @@ const WorkoutPage = () => {
<ExerciseCard key={index} exercise={exercise} />
))}
</HorizontalScrollView>
<TouchableOpacity style={styles.buttonContainer}>
<Pressable style={styles.buttonContainer}>
<Text style={styles.buttonText}>Start Workout</Text>
</TouchableOpacity>
</Pressable>
</SafeAreaView>
);
};
Expand Down
17 changes: 7 additions & 10 deletions frontend/app/workout/create.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Text, TextInput, TouchableOpacity, SafeAreaView } from 'react-native';
import { Text, TextInput, Pressable, SafeAreaView } from 'react-native';
import styles from '../../styles';
import AddExerciseModal from '../../components/AddExerciseModal';
import AddCard from '../../components/AddCard';
Expand Down Expand Up @@ -76,20 +76,17 @@ const CreateWorkout = () => {
/>
<HorizontalScrollView title="Exercises">
{exercises.map((exercise, index) => (
<TouchableOpacity
key={index}
onPress={() => handleExerciseClick(exercise)}
>
<Pressable key={index} onPress={() => handleExerciseClick(exercise)}>
<ExerciseCard exercise={exercise} />
</TouchableOpacity>
</Pressable>
))}
<TouchableOpacity onPress={() => setModalVisible(true)}>
<Pressable onPress={() => setModalVisible(true)}>
<AddCard />
</TouchableOpacity>
</Pressable>
</HorizontalScrollView>
<TouchableOpacity style={styles.buttonContainer} onPress={handleSubmit}>
<Pressable style={styles.buttonContainer} onPress={handleSubmit}>
<Text style={styles.buttonText}>Create Workout</Text>
</TouchableOpacity>
</Pressable>
<AddExerciseModal
modalVisible={modalVisible}
onClose={() => setModalVisible(false)}
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/AddExerciseModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Modal, Text, TextInput, TouchableOpacity } from 'react-native';
import { Modal, Text, TextInput, Pressable } from 'react-native';
import styles from '../styles';
import { SafeAreaView } from 'react-native-safe-area-context';
import NumericInput from './NumericInput';
Expand Down Expand Up @@ -36,17 +36,17 @@ const AddExerciseModal = ({
/>
<NumericInput title="Reps" value={reps} onChange={setReps} />
<NumericInput title="Sets" value={sets} onChange={setSets} />
<TouchableOpacity
<Pressable
style={styles.buttonContainer}
onPress={() =>
onAddExercise({ exercise: { name: exerciseName }, reps, sets })
}
>
<Text style={styles.buttonText}>Add Exercise</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonContainer} onPress={onClose}>
</Pressable>
<Pressable style={styles.buttonContainer} onPress={onClose}>
<Text style={styles.buttonText}>Cancel</Text>
</TouchableOpacity>
</Pressable>
</SafeAreaView>
</Modal>
);
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/HorizontalScollView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ScrollView, View, Text, TouchableOpacity } from 'react-native';
import { ScrollView, View, Text, Pressable } from 'react-native';

import styles from '../styles';

Expand All @@ -19,9 +19,9 @@ const HorizontalScrollView: React.FC<HorizontalScrollViewProps> = ({
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<Text style={styles.subtitile}>{title}</Text>
{showAllAction && (
<TouchableOpacity onPress={showAllAction}>
<Pressable onPress={showAllAction}>
<Text style={styles.subtitile}>Show all</Text>
</TouchableOpacity>
</Pressable>
)}
</View>
<ScrollView
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/NumericInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { View, Text, TouchableOpacity } from 'react-native';
import { View, Text, Pressable } from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
import styles from '../styles';

Expand Down Expand Up @@ -28,27 +28,27 @@ const NumericInput = ({ title, value, onChange, min = 0, max = 100 }) => {
justifyContent: 'center',
}}
>
<TouchableOpacity style={styles.buttonContainer} onPress={handleMinus}>
<Pressable style={styles.buttonContainer} onPress={handleMinus}>
<MaterialIcons
style={{ padding: 10 }}
name="remove"
size={24}
color="black"
/>
</TouchableOpacity>
</Pressable>
<View
style={[styles.buttonContainer, { marginLeft: 0, marginRight: 0 }]}
>
<Text style={[styles.buttonText, { width: 100 }]}>{value}</Text>
</View>
<TouchableOpacity style={styles.buttonContainer} onPress={handlePlus}>
<Pressable style={styles.buttonContainer} onPress={handlePlus}>
<MaterialIcons
style={{ padding: 10 }}
name="add"
size={24}
color="black"
/>
</TouchableOpacity>
</Pressable>
</View>
</View>
);
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/ProfileButton.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import { TouchableOpacity } from 'react-native';
import { Pressable } from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
import styles from '../styles';

export default function ProfileButton({ onPress }) {
return (
<TouchableOpacity onPress={onPress}>
<Pressable onPress={onPress}>
<MaterialIcons
style={styles.headerButton}
name="person"
size={24}
color="black"
/>
</TouchableOpacity>
</Pressable>
);
}

0 comments on commit f528863

Please sign in to comment.