Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InstaFeed

A simplified Instagram-like feed for iOS demonstrating dynamic mixed media handling, optimized scrolling performance, and proper caching strategies.

Assignment Requirements

Requirement Implementation
Scrollable feed with posts List for efficient cell recycling
Single photo posts SingleMediaView with natural aspect ratio
Single video posts VideoPlayerView with auto-play support
Mixed photo + video posts TabView carousel with PageTabViewStyle
Auto-play videos when visible ✅ Visibility tracking via GeometryReader + PreferenceKey
Pause videos when scrolled out ✅ Hysteresis-based visibility algorithm in FeedViewModel
Caching mechanisms ImageCacheActor and VideoCacheActor using Swift actors
External data source ✅ Mock data from picsum.photos, pravatar.cc, and Google sample videos

Technical Stack

  • iOS: SwiftUI
  • Architecture: MVVM (Model-View-ViewModel)
  • Concurrency: Swift Concurrency (async/await, actor)
  • Video Playback: AVFoundation / AVKit

Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                        InstaFeedApp                         │
│                   (DependencyContainer)                     │
└─────────────────────────────────────────────────────────────┘
                              │
                    @Environment(\.dependencies)
                              │
┌─────────────────────────────────────────────────────────────┐
│                          FeedView                           │
│                       + FeedViewModel                       │
│              (visibility tracking, scroll logic)            │
└─────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────┐
│                          PostView                           │
│                       + PostViewModel                       │
│            (PostHeaderView, PostMediaContentView,           │
│             PostActionsView, PostCaptionView)               │
└─────────────────────────────────────────────────────────────┘
                              │
           ┌──────────────────┴──────────────────┐
           │                                     │
┌─────────────────────┐             ┌─────────────────────┐
│  CachedAsyncImage   │             │   VideoPlayerView   │
│ + ImageLoaderService│             │ + VideoPlayerVM     │
└─────────────────────┘             └─────────────────────┘
           │                                     │
┌─────────────────────┐             ┌─────────────────────┐
│  ImageCacheActor    │             │  VideoCacheActor    │
│   (thread-safe)     │             │   (thread-safe)     │
└─────────────────────┘             └─────────────────────┘

Key Features

1. Scrollable Feed with Cell Recycling

  • Uses List for efficient memory management through cell recycling
  • Handles hundreds of posts without memory bloat

2. Mixed Media Support

  • Single Image: Displays with natural aspect ratio
  • Single Video: Auto-plays with natural aspect ratio
  • Carousel: TabView with page indicator for multiple items

3. Video Auto-Play/Pause

  • Tracks visibility using GeometryReader and PreferenceKey
  • Hysteresis algorithm: Videos keep playing until < 30% visible, new videos start at > 50% visible
  • Prevents flickering during slow scrolling

4. Caching Strategy

Cache Type Purpose
ImageCacheActor actor Thread-safe in-memory image cache with LRU eviction
VideoCacheActor actor Thread-safe AVAsset cache to avoid reloading metadata
VideoPlayerCacheActor actor Reuses AVPlayer instances per URL

5. Dependency Injection

  • No singletons — all services created in DependencyContainer
  • Injected via @Environment(\.dependencies)

How to Run

  1. Open InstaFeed.xcodeproj in Xcode
  2. Select the InstaFeed scheme
  3. Choose a simulator or device
  4. Press Cmd + R to build and run

Note: Internet connection required for loading mock media from external URLs.

Data Sources

The app uses external services for mock data:

  • Images: picsum.photos (Lorem Picsum)
  • Avatars: pravatar.cc (Random avatars)
  • Videos: Google sample videos (Big Buck Bunny, Elephants Dream)

Future Improvements

  • Disk caching for offline support
  • Pull-to-refresh
  • Infinite scroll / pagination
  • Like/comment interactions
  • Local video/image assets as alternative data source

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages