Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NextJS
  • Material UI
  • React Bootstrap
  • React Suite
  • Ant Design
  • Reactstrap
  • BlueprintJS
  • React Desktop
  • React Native
  • React Rebass
  • React Spring
  • React Evergreen
  • ReactJS
  • ReactJS
  • JS Formatter
  • Web Technology
Open In App
Next Article:
Create a Text Narrator App using React-Native
Next article icon

Create Memes Generator App using React-Native

Last Updated : 02 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The Me­me Generator App is a mobile­ application that allows users to effortlessly create memes. With its use­r-friendly interface, use­rs can choose from a wide collection of popular me­me templates and add their own customized text to the top and bottom. In this article, we will see how we can build a memes generator application using react native with the help of API.

Preview:

Prerequisites

  • Introduction to React Native
  • React Native Components
  • Expo CLI
  • Node.js and npm (Node Package Manager)

Steps to Create React Native Application

Step 1: Create a react native application by using this command

npx create-expo-app memesGeneratorApp

Step 2: After creating your project folder, i.e. memesGeneratorApp, use the following command to navigate to it:

cd memesGeneratorApp

Project Structure

package.json:

{
"dependencies": {
"react-native-paper": "4.9.2",
"@expo/vector-icons": "^13.0.0"
}
}

Approach:

The Me­me Generator App utilize­s a straightforward approach to allow users to effortlessly cre­ate a meme. It commences by retrie­ving a diverse compilation of meme­ templates from an exte­rnal API. Users can then choose a template and add their custom text to the top and bottom sections. By simply clicking the "Generate­ Meme" button, the app cle­verly merges the­ chosen template with the­ added text, promptly gene­rating a brand new meme.

Example: In this example,

  • State Management: The component manages state using the useState hook for meme-related data and API response.
  • API Call: It fetches meme data from an API using the fetch function and updates the state with the fetched data.
  • User Interaction: Users can enter top and bottom text, click a button to fetch a random meme, and see it displayed with the entered text.
  • Styling: The component uses inline and StyleSheet styling for layout, buttons, and text, including shadows and borders for aesthetics.
  • Conditional Rendering: It conditionally renders the meme image and text only when imgState is true, controlling the display of the generated meme.
JavaScript
//App.js  import React, { useState, useEffect } from "react"; import {     View,     Text,     TextInput,     Button,     Image,     StyleSheet,     TouchableOpacity,     SafeAreaView, } from "react-native";  export default function Form() {     const [allMemeData, setMemeAllImages] = useState({});     const [imgState, setImageState] = useState(false);     const [meme, setMeme] = useState({         topText: "",         bottomText: "",         randomImage: "",     });      useEffect(() => {         async function getMemesApi() {             try {                 const response = await fetch(                     "https://api.imgflip.com/get_memes");                 const data = await response.json();                 setMemeAllImages(data);             } catch (error) {                 console.error("Error fetching memes:", error);             }         }         getMemesApi();     }, []);      const handleClick = () => {         const memesArray = allMemeData.data.memes;         const randomIndex = Math.floor(Math.random() * memesArray.length);         const imgUrl = memesArray[randomIndex].url;         setImageState(true);         setMeme({             ...meme,             randomImage: imgUrl,         });     };      const handleChange = (name, value) => {         setMeme({             ...meme,             [name]: value,         });     };      return (         <SafeAreaView style={styles.container}>             <View style={styles.navbar}>                 <Text style={styles.navbarText}>                     Meme Generator                 </Text>             </View>             <View style={styles.formContainer}>                 <View style={styles.inputContainer}>                     <TextInput                         style={styles.inputText}                         onChangeText={(value) =>                             handleChange("topText", value)}                         value={meme.topText}                         placeholder="Enter top text"                     />                     <TextInput                         style={styles.inputText}                         onChangeText={(value) =>                             handleChange("bottomText", value)}                         value={meme.bottomText}                         placeholder="Enter bottom text"                     />                 </View>                 <TouchableOpacity style={styles.button}                     onPress={handleClick}>                     <Text style={styles.buttonText}>                         Get a new random meme                     </Text>                 </TouchableOpacity>             </View>             {imgState && (                 <View style={styles.imageContainer}>                     <Image source={                         { uri: meme.randomImage }}                         style={styles.memeImage} />                     <Text style={styles.memeTextTop}>                         {meme.topText}</Text>                     <Text style={styles.memeText}>                         {meme.bottomText}</Text>                 </View>             )}         </SafeAreaView>     ); }  const styles = StyleSheet.create({     container: {         flex: 1,         backgroundColor: "#f0f0f0",     },     navbar: {         backgroundColor: "green",         padding: 20,         alignItems: "center",     },     navbarText: {         color: "white",         fontSize: 24,         fontWeight: "bold",     },     formContainer: {         flex: 1,         justifyContent: "center",         alignItems: "center",         backgroundColor: "white",         margin: 20,         padding: 20,         borderRadius: 15,         elevation: 5,         shadowColor: "#000",         shadowOpacity: 1,         shadowOffset: { width: 3, height: 3 },     },     inputContainer: {         marginBottom: 20,     },     inputText: {         borderBottomWidth: 1,         borderBottomColor: "#333",         fontSize: 16,         paddingVertical: 10,     },     button: {         backgroundColor: "green",         padding: 12,         borderRadius: 10,         width: "100%",         alignItems: "center",     },     buttonText: {         color: "white",         fontSize: 18,         fontWeight: "bold",     },     imageContainer: {         flex: 1,         justifyContent: "center",         alignItems: "center",         marginTop: 20,     },     memeImage: {         width: 300,         height: 300,         resizeMode: "contain",         borderRadius: 10,         borderWidth: 3,         borderColor: "#333",         shadowColor: "#000",         shadowOpacity: 0.4,         shadowOffset: { width: 0, height: 4 },         marginBottom: 20,     },     memeTextTop: {         fontSize: 20,         fontWeight: "bold",         position: "absolute",         top: 30,         left: 50,         zIndex: 3,         color: "crimson",         textShadowColor: "rgba(0, 0, 0, 0.75)",         textShadowOffset: { width: -1, height: 1 },         textShadowRadius: 10,     },     memeText: {         fontSize: 20,         fontWeight: "bold",         position: "absolute",         bottom: 40,         left: 50,         zIndex: 3,         color: "crimson",         textAlign: "center",         textShadowColor: "rgba(0, 0, 0, 0.75)",         textShadowOffset: { width: -1, height: 1 },         textShadowRadius: 10,     }, }); 

Steps to Run: To run react native application use the following command:

npx expo start

To run on Android:

npx react-native run-android

To run on iOS:

npx react-native run-ios

Output:


Next Article
Create a Text Narrator App using React-Native
author
saurabhkumarsharma05
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • React-Native
  • Geeks Premier League 2023

Similar Reads

  • Create Jokes Generator App using React-Native
    In this article, we are going to build a jokes generator app using react native. React Native enables you to master the­ designing an elegant and dynamic use­r interface while e­ffortlessly retrieving joke­s from external APIs. Let's take a look at how our completed project will look Prerequisites /
    3 min read
  • Create a meme generator by using ReactJS
    In this tutorial, we’ll create a meme generator using ReactJS. In the meme generator, we have two text fields in which we enter the first text and last text. After writing the text when we click the Gen button, it creates a meme with an image and the text written on it. Preview Image: PrerequisiteTh
    3 min read
  • Create a Text Narrator App using React-Native
    In this project, we'll develop a Text Narrator application using React Native. The Text Narrator app is a valuable tool for improving accessibility. It allows users to input text, and the app will convert that text into audible speech. This can be incredibly helpful for individuals with visual impai
    2 min read
  • Create File Explorer App using React-Native
    Creating a File Explorer app using React Native provides a seamless way to explore and interact with the device's file system on both iOS and Android platforms. In this tutorial, we'll guide you through the process of building a simple yet functional File Explorer app. Output Preview: Prerequisites:
    3 min read
  • Create a Random Quote Generator using React-Native
    React Native is the most flexible and powerful mobile application development framework, which has various features embedded into it. Using this framework, we can create different interactive applications. Creating a Random Quote Generator using React Native is one of the interactive project which u
    4 min read
  • Create a 2048 Game using React-Native
    In this article, we are going to implement a 2048 Game using React Native. The 2048 game is a popular sliding puzzle game that involves combining tiles with the same number to reach the tile with the number 2048. Players can move the tiles in four directions: up, down, left, or right. PrerequisiteRe
    7 min read
  • Create a Dashboard App using React-Native
    A dashboard app using react native is a software application designed to provide a consolidated and visual representation of important information, data, or features in a single, easily accessible interface. Dashboards are commonly used in various industries to help users monitor, analyze, and manag
    6 min read
  • Create a Text Editor App using React-Native
    In this article, we are going to implement a text editor app using React Native. It will contain multiple text formatting functionalities like bold, italic, underline, etc. We will implement Editor with a library called "react-native-pell-rich-editor." Preview of final output: Let us have a look at
    3 min read
  • Create an Interactive Quiz App using React-Native?
    In this article, we are going to implement an Interactive Quiz App using React Native. Interactive Quiz App is a mobile application that allows users to take tests and view their quiz results to see how well they performed. This Interactive Quiz App consists of multiple questions and multiple-choice
    4 min read
  • Create a Memory Pair Game using React-Native
    In this article, we will build the interactive Memory Pair Game using the React Native language. We are displaying the 12 boxes to the user, in the user has to click on each box, and when the user clicks on the box the random icon will be shown. Users have to guess or find its match by clicking on t
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences