Skip to content

shuvojoseph/BlogPostReactNative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± BlogPost - React Native (TypeScript)

A simple yet complete React Native app built with TypeScript, demonstrating clean architecture using MVVM pattern, authentication, and CRUD functionality for managing blog posts.


πŸš€ Features

  • πŸ” Authentication (Register / Login / Logout)
  • πŸ“ Create, Edit, Delete, View Blogs
  • πŸ‘₯ Owner & Co-owner based blog access
  • πŸ“‘ API integration with Axios
  • πŸ’Ύ Persistent login with AsyncStorage
  • βœ… Form validation using Formik + Yup
  • πŸ§ͺ Unit Testing with Jest & Testing Library
  • 🧭 Navigation using React Navigation (Stack Navigator)
  • πŸ“± Works on both iOS and Android

πŸ—οΈ Project Setup

1️⃣ Create Project (React Native CLI + TypeScript)

Note: The traditional template command failed due to CLI deprecations.
The working solution used the community CLI.

# Install CLI (if not already)
npm install -g react-native-cli
npm install -g react-native

# Create project
npx @react-native-community/cli@latest init BlogPost
cd BlogPost

2️⃣ Fix Android SDK Issue

If Android build fails with:

β€œReact Native project's build process cannot locate the Android SDK”

Create android/local.properties and set SDK path:

sdk.dir=/Users/yourusername/Library/Android/sdk

3️⃣ Run the App

# Android
npx react-native run-android

# iOS (macOS)
cd ios
pod install
cd ..
npx react-native run-ios

βš™οΈ Installed Dependencies

🧭 Navigation

npm install @react-navigation/native @react-navigation/native-stack
npm install react-native-gesture-handler react-native-safe-area-context

🌐 Networking & Storage

npm install axios
npm install @react-native-async-storage/async-storage

🧾 Form Handling & Validation

npm install formik yup

🧰 TypeScript Types

npm install --save-dev @types/react @types/react-native @types/yup

🎨 Icons (optional)

npm install react-native-vector-icons

🧩 iOS CocoaPods

cd ios && pod install && cd ..

πŸ’‘ Development Tips

πŸ” Check TypeScript Compilation Errors

npx tsc --noEmit

🧠 JSX Comments

{/* This is a comment */}

πŸ–₯️ Android Emulator Localhost

Use 10.0.2.2 instead of localhost for local API calls.

βš™οΈ Android SDK Path Setup (macOS)

Add to your ~/.zshrc:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator

Then run:

source ~/.zshrc

πŸ§ͺ Unit Testing

🧩 Install Testing Dependencies

npm install --save-dev jest @testing-library/react-native @testing-library/jest-native jest-fetch-mock
npm install --save-dev ts-jest @types/jest

βš™οΈ Jest Configuration

Add the following in package.json (or jest.config.js):

"jest": {
  "preset": "react-native",
  "setupFiles": ["./jestSetup.js"],
  "transform": {
    "^.+\\.tsx?$": "ts-jest"
  },
  "testPathIgnorePatterns": [
    "/node_modules/",
    "/__tests__/App.test.tsx"
  ]
}

🧱 Mock AsyncStorage (jestSetup.js)

import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);

▢️ Run Tests

npm test

πŸ“Š View Test Coverage

npm test -- --coverage

βœ… Implemented Tests

  • authService.test.ts – Login & Register API
  • blogService.test.ts – CRUD operations
  • useAuth.test.tsx – Hook functionality
  • BlogItem.test.tsx – Component render and behavior

🎨 UI Overview

Screen Description
Login User authentication with Formik validation
Register Sign-up form with error handling
Home Displays all blogs, Add/Edit/Delete options
Add/Edit Blog Create or modify posts
Logout Clears AsyncStorage and session

Modern UI using built-in StyleSheet with rounded inputs, blue accent buttons, and card-based blog layout.


🧠 Architecture Overview

  • MVVM Pattern

    • viewmodels/ β†’ Contains hooks like useAuth, useBlogViewModel
    • services/ β†’ Handles API requests (authService, blogService)
    • components/ β†’ Reusable UI components (e.g., BlogItem)
    • screens/ β†’ Page-level views
    • navigation/ β†’ App stack and route configuration
    • utils/ β†’ Helper functions, storage

πŸ“± Screenshots

🧭 Login & Register Screens

iOS Android
iOS Login Android Login
iOS Register Android Register

🏠 Home Screen

iOS Android
iOS Home Android Home

🧰 Tech Stack

Category Library
Framework React Native (TypeScript)
Navigation React Navigation
Networking Axios
Storage AsyncStorage
Forms Formik + Yup
Testing Jest + React Native Testing Library

πŸ’» Commands Reference

Task Command
Run Metro Bundler npx react-native start
Run on Android npx react-native run-android
Run on iOS npx react-native run-ios
Check Type Errors npx tsc --noEmit
Run Tests npm test
See Test Coverage npm test -- --coverage

🏁 Final Notes

This project demonstrates:

  • Clean and maintainable React Native + TypeScript code.
  • Integration of MVVM pattern.
  • Modular architecture with separation of concerns.
  • Testable design using Jest and React Testing Library.

βœ… All tests passing βœ… Runs on iOS & Android βœ… Ready for public showcase


Backend Notes

  • The backend is hosted on Render and may go inactive after ~45 minutes of inactivity.
  • If the backend is inactive, it may take ~2 minutes to start again.
  • To activate the backend before using the app, open this link in a browser: https://blogpostspringboot.onrender.com/api/blogs
  • Once the backend is active, you can use the mobile app to fetch or post blogs.

πŸ“œ License

This project is open-source and available under the MIT License.

About

A cross-platform React Native app (iOS & Android) that allows users to register, log in, and manage blog posts through a secure REST API backend built with Spring Boot. Includes JWT authentication, form validation, and persistent login via AsyncStorage.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors