react native app movie stream in javascript

To create a movie streaming app in React Native, we can use the Expo CLI which provides a lot of helpful tools and features. Here are the steps to follow:

  1. Create a new React Native project with Expo CLI by running the following command in your terminal:

    index.tsx
    expo init movie-streaming-app
    
    30 chars
    2 lines
  2. Then install the required dependencies by running the following command:

    index.tsx
    npm install axios expo-av react-native-elements react-navigation
    
    65 chars
    2 lines
  3. Next, you need to create a file to hold your API baseURL. Create a file config.js in your project directory and add the following code:

    index.tsx
    export const baseURL = 'https://your-api-base-url.com';
    
    56 chars
    2 lines
  4. Now, you can create a screen to display the list of movies. Create a new file MoviesScreen.js under the screens folder of your project with the following code:

    index.tsx
    import React, { useState, useEffect } from 'react';
    import { View, Text, FlatList, StyleSheet, Image } from 'react-native';
    import { Card } from 'react-native-elements';
    import axios from 'axios';
    
    import { baseURL } from '../config';
    
    const MoviesScreen = () => {
      const [movies, setMovies] = useState([]);
    
      const fetchMovies = async () => {
        try {
          const response = await axios.get(`${baseURL}/movies`);
          setMovies(response.data);
        } catch (error) {
          console.log(error);
        }
      };
    
      useEffect(() => {
        fetchMovies();
      }, []);
    
      const renderMovie = ({ item }) => (
        <Card>
          <Card.Image source={{ uri: item.poster }} />
          <Text style={styles.title}>{item.title}</Text>
        </Card>
      );
    
      return (
        <View>
          <FlatList
            data={movies}
            renderItem={renderMovie}
            keyExtractor={(item) => item.id}
          />
        </View>
      );
    };
    
    const styles = StyleSheet.create({
      title: {
        textAlign: 'center',
        fontSize: 16,
        marginTop: 10,
      },
    });
    
    export default MoviesScreen;
    
    1041 chars
    51 lines
  5. In the file App.js, add the following code to set up navigation and render the MoviesScreen:

    index.tsx
    import React from 'react';
    import { NavigationContainer } from '@react-navigation/native';
    import { createStackNavigator } from '@react-navigation/stack';
    import { enableScreens } from 'react-native-screens';
    
    import MoviesScreen from './screens/MoviesScreen';
    
    enableScreens();
    
    const Stack = createStackNavigator();
    
    const App = () => {
      return (
        <NavigationContainer>
          <Stack.Navigator>
            <Stack.Screen name="Movies" component={MoviesScreen} />
          </Stack.Navigator>
        </NavigationContainer>
      );
    };
    
    export default App;
    
    545 chars
    23 lines
  6. Finally, run the app with the following command:

    index.tsx
    expo start
    
    11 chars
    2 lines

This will start the Expo development server and open the Expo client in your browser. You can then run the app on your device or emulator using the instructions provided by Expo.

Note: This is just a basic example of how to create a movie streaming app in React Native. Depending on your specific requirements, you may need to add more functionality such as authentication, search, movie details, etc.

gistlibby LogSnag