Skip to main content

Tab Context

Source: contexts/TabContext.tsx (131 lines) The TabProvider manages bottom tab navigator state, tracks tab visit history for performance optimization, persists per-tab state across tab switches, and provides analytics data for usage patterns.

Context API


Tab Visit Tracking

The provider initializes with the “commits” tab pre-marked as visited (since it’s the default landing tab). Each tab switch calls markTabVisited(), which:
  1. Adds the tab ID to the visitedTabs Set
  2. Increments the tabSwitchCount counter
  3. Updates lastActiveTab to the new tab ID

Per-Tab State Persistence

Each tab can save arbitrary state that survives tab switches:
State entries are timestamped on save. The getTabState() function automatically expires entries older than 24 hours, clearing stale state that no longer reflects the current data.

Preload Optimization

The shouldPreload() function determines which tabs should eagerly load their content:
The “commits” and “schedules” tabs are always preloaded. Other tabs are preloaded only after the user has visited them at least once this session.

AppState Integration

The provider listens to React Native’s AppState changes. When the app goes to background, it can persist critical tab state to AsyncStorage (currently a placeholder for future implementation).

Initialization

The tab system performs async initialization on mount with a 100ms delay before marking isTabReady as true. Components can gate rendering on this flag to prevent layout jumps during cold start.