Setup
- Create a new Expo project
- Install eslint and prettier
- Run the app on your phone
- Try to run your app on a simulator
Exercise 1: Adding Navigation to an Expo App
Objective: Implement navigation in an Expo app using React Navigation.
Instructions:
- Create a new Expo app.
- Install React Navigation packages
- Create two screens:
HomeScreenandDetailsScreen. - Set up a Stack Navigator in your app to navigate between the screens.
- Configure the Stack Navigator to show the
HomeScreenas the initial route. - Add a button in the
HomeScreenthat navigates to theDetailsScreenwhen pressed.
Exercise 2: Creating Screens and Navigating Between Them
Objective: Create multiple screens and navigate between them using React Navigation.
Instructions:
- Add two more screens to your Expo app:
ProfileScreenandSettingsScreen. - Create a Bottom Tab Navigator to switch between the screens.
- Configure the Tab Navigator to show the
HomeScreenas the initial route. - Add buttons or icons to each screen that navigate to the corresponding screen when pressed.
Exercise 3: Passing Parameters to Routes and Configuring Header Bar
Objective: Pass parameters to routes and configure the header bar in a React Native app.
Instructions:
- Modify the
DetailsScreento receive a parameter when navigating to it. - Pass a parameter from the
HomeScreento theDetailsScreenwhen navigating. - Display the received parameter on the
DetailsScreen. - Configure the header bar of the
DetailsScreento display a title based on the received parameter. - Add a header button to the
DetailsScreenthat performs a specific action when pressed.
Exercise 4: Counter App
Objective: Create a simple counter application using React Native and the useState hook. The counter should display a number and have two buttons: one for incrementing the count and another for decrementing it.
Instructions:
- Create a new Expo app or use the current one.
- Create a functional component called
CounterApp. - Import the necessary React Native components (
Text,View,Button, etc.) from thereact-nativepackage. - Inside the
CounterAppcomponent, use theuseStatehook to define a state variable calledcountand a function calledsetCountto update it. - Render a
Viewcomponent that contains aTextcomponent displaying the current value ofcount. - Add two
Buttoncomponents below theTextcomponent: one with the label "+" and another with the label "-". - Attach
onPresshandlers to each button that call the appropriate function to increment or decrement thecountstate variable usingsetCount. - Style the components as desired to improve the user interface.
- Test the application in the Expo client or simulator.
Exercise 5: Toggle Switch
Objective: Create a toggle switch component using React Native and the useState hook. The toggle switch should have an initial state (on/off) and change its state when the user taps on it.
Instructions:
- Create a new Expo app or use the current one.
- Define a functional component called
ToggleSwitch. - Import the necessary React Native components (
Text,View,TouchableOpacity, etc.) from thereact-nativepackage. - Inside the
ToggleSwitchcomponent, use theuseStatehook to define a state variable calledisOnand a function calledsetIsOnto update it. - Render a
Viewcomponent that represents the toggle switch. - Inside the
Viewcomponent, render aTextcomponent displaying the current state (isOn). - Add a
TouchableOpacitycomponent inside theViewcomponent that wraps the entire toggle switch. - Attach an
onPresshandler to theTouchableOpacitycomponent that calls thesetIsOnfunction to toggle theisOnstate variable. - Style the components to create a visual representation of the toggle switch, such as using different colors or icons to represent the different states.
- Test the toggle switch component in the Expo client or simulator.
Exercise 6: Random Quote Generator
Objective: Create a simple random quote generator application using React Native and the useEffect hook. The application should fetch a random quote from an API and display it on the screen.
Instructions:
- Create a functional component called QuoteGenerator.
- Import the necessary React Native components (Text, View, etc.) from the react-native package.
- Inside the QuoteGenerator component, use the useState hook to define a state variable called quote and a function called setQuote to update it.
- Use the useEffect hook to fetch a random quote from the API https://type.fit/api/quotes when the component mounts. You can use the fetch function or a library like Axios to make the API call.
- Update the quote state variable with the fetched quote.
- Render a View component that contains a Text component displaying the current value of the quote state variable.
- Style the components as desired to improve the user interface.
- Test the application in the Expo client or simulator.
Exercise 7: Real-time Weather Updates
Objective: Create a real-time weather update application using React Native and the useEffect hook. The application should fetch weather data from an API and display it on the screen, updating the data at regular intervals.
Instructions:
- Create a new Expo app or use the current one.
- Define a functional component called WeatherApp.
- Import the necessary React Native components (Text, View, etc.) from the react-native package.
- Inside the WeatherApp component, use the useState hook to define a state variable called weatherData and a function called setWeatherData to update it.
- Use the useEffect hook to fetch weather data from the API https://open-meteo.com/ when the component mounts and at regular intervals (e.g., every 5 minutes). You can use the fetch function or a library like Axios to make the API call.
- Update the weatherData state variable with the fetched weather data.
- Render a View component that contains Text components displaying the relevant weather information from the weatherData state variable (e.g., temperature, humidity, etc.).
- Style the components as desired to improve the user interface.
- Test the application in the Expo client or simulator.