Skip to main content
Back to blog

8 min readEnglish

Trenord Infotainment: an app for people on regional trains

A React Native app for Trenord commuters. It keeps tracking the train in tunnels, draws motion cues against motion sickness, and splits into two columns on tablets.

#Mobile Engineering#React Native#Expo#Transit Tech#System Design#TypeScript

Also available in Italian: Versione in italiano.

Regional trains in Lombardy are a hard place for a phone app. The train goes through cuttings and tunnels where GNSS and mobile data drop out, it changes cell towers every few minutes, and many passengers get motion sick when they read on board.

Trenord Infotainment (GitHub repository(opens in a new tab)) was our final project for the Design and Implementation of Mobile Applications (DIMA) course of the M.Sc. in Computer Science and Engineering at Politecnico di Milano. We built it with Trenord(opens in a new tab), the largest regional rail operator in Lombardy. The team was Tommaso Morganti, Luca Suzani and me. The goal was an offline-first app that shows where the train is, helps with motion sickness, and keeps passengers busy when the network is gone.

Trenord Infotainment live journey tracking map and station stop timeline

The problems

Most mobile apps assume they are always online. On a regional train that assumption fails all the time:

  1. Tunnels and dead zones. An app that waits on a network request before it responds freezes as soon as the train enters a tunnel.
  2. Motion sickness. The inner ear feels the carriage sway and accelerate, while the eyes see a phone that does not move. The mismatch makes people sick.
  3. Scattered information. Delays, platform changes, weather at the destination and connections live on different sites or in station announcements you can barely hear.
  4. Different screens. Passengers use small phones, large phones and tablets on the seat tray. A phone layout stretched to a tablet wastes the space.

We answered each one in turn: everything the trip needs is cached on the device, motion cues run on the UI thread, and the layout switches to two columns on wide screens.

Starting a trip

The passenger either scans the 2D barcode or PNR code on the ticket, or types the train number (for example 24869).

Ticket scanning and destination station selection onboarding flow

The app then calls the Trenord timetable service and downloads:

The app saves this journey on the device. If the connection drops a few seconds later, the trip is still there.

Tracking the train, also in tunnels

When the sky is visible, the app reads GNSS fixes from a high-frequency location stream.

Home dashboard with live train telemetry, station countdown, and contextual feed

GPS inside a train is noisy: the metal carriage blocks part of the signal and the rest bounces around. To keep the speedometer from jumping, we pass each speed reading through an exponential moving average (EMA):

vsmooth,t=α⋅vmeasured,t+(1−α)⋅vsmooth,t−1v_{\text{smooth}, t} = \alpha \cdot v_{\text{measured}, t} + (1 - \alpha) \cdot v_{\text{smooth}, t-1}

with α=0.35\alpha = 0.35.

Dead reckoning

In a tunnel, GNSS fixes stop. Many transit apps then show a frozen position or a spinner. We added a small state machine instead:

  1. Detect the loss. If no new fix arrives within 5 seconds, the app leaves satellite mode and enters dead-reckoning mode.
  2. Estimate from the timetable. The app takes the cached timetable and the time elapsed since the last departure, and places the train at the matching point on the route between the two stations.
  3. Switch back. When the train leaves the tunnel and the fixes are good again, the position moves back to the GNSS reading without a jump or a reset of the screen.

Motion cues against motion sickness

On a curve the inner ear feels the train lean, but the eyes see a phone that stays still in your hands. That conflict causes motion sickness (kinetosis).

We added an overlay of motion cues.

Vehicle motion cues active with edge-aligned inertial particles

The overlay draws 40 small particles along the edges of the screen. When the train sways, accelerates or takes a curve, the particles drift opposite to the acceleration. Peripheral vision sees the movement the inner ear feels, like an artificial horizon.

Running on the UI thread

Doing this math on the JavaScript thread would drop frames. The motion code runs on the native UI thread as React Native Reanimated worklets:

Hardware sensor processing and kinematics pipeline

  1. useAnimatedSensor(SensorType.ACCELEROMETER) samples the accelerometer at the display refresh rate (about 60 Hz or 120 Hz).
  2. A low-pass filter (α=0.8\alpha = 0.8) separates gravity (1.0G1.0\text{G}) from the acceleration of the train.
  3. The remaining linear acceleration moves the particles, which wrap around the screen edges and fade with depth.
  4. The worklet never touches the JavaScript event loop, so the overlay holds 60 FPS.

We also added shake to report. If the phone detects a strong shake or a sudden deceleration (M>2.2GM > 2.2\text{G}, ΔM>1.2G\Delta M > 1.2\text{G}), the app opens the incident report sheet, so a passenger can report a delay, a fault or a medical emergency right away.

Offline games and media

Streaming video over train Wi-Fi or patchy LTE rarely works. The entertainment part of the app runs without the network.

Media hub showcasing film spotlights and background audio podcasts

The media hub has news, regional culture and entertainment:

Offline arcade games: Trenord Hop 60 FPS runner and Commuter Sudoku

Both games run on the device and make no network requests.

Arriving at the destination

Near the end of the trip, the app shows information about the arrival city:

Destination POI explore sheet and digital news magazine

Notifications timeline sheet and passenger settings controls

Tablets

Many commuters travel with a tablet. We did not want to stretch phone lists across a wide screen or keep a second codebase, so the layout changes at render time:

Tablet two-column simultaneous map and timeline layout on iPad

When the window is at least 768 px768\,\mathrm{px} wide:

Tablet multi-column home dashboard on iPad

Only the layout changes. App state, audio and running games are not interrupted when you rotate the device or resize the window.

Architecture and tests

The app is split into the containers shown in this C4 diagram:

C4 container topology diagram for Trenord Infotainment

Stack

AreaTechnologyWhat it does
RuntimeReact Native 0.83.10 / Expo SDK 55Runs the app on the React Native New Architecture
LanguageTypeScript 5.9Strict types for models, API payloads, stores and component props
StateZustand 5 + AsyncStorage11 domain stores, saved as JSON and cleared at the end of a trip
NavigationExpo Router v5File-based routes, tab bars and bottom sheets
AnimationReact Native Reanimated 3Runs the motion cue particles on the UI thread at 60 FPS
Sensorsexpo-sensors + expo-locationReads the 3-axis accelerometer and frequent GPS fixes for the speedometer
Audioexpo-audioBackground playback with lock screen controls
Device accessexpo-camera, expo-haptics, expo-notificationsTicket scanning, vibration feedback and arrival alerts
TestsJest 29 + React Native Testing Library + fast-check142 suites, 921 tests, property-based EMA tests and accessibility checks
APIsEdge proxy + OAuth 2.0 (RS256 JWT)Trenord B2B, OpenStreetMap routes, Open-Meteo, CurrentsAPI and Listen Notes
Languagesreact-i18nextEvery string is available in Italian and English

Tests

The project has 142 test suites with 921 unit tests:

Testing pyramid and automated quality gates diagram

Automated code coverage report showing over 90 percent coverage across 142 test suites

They cover:

What I learned

Trenord gave us real operational data and context about their network. That pushed the project past a typical CRUD app: we had to deal with noisy sensors, coverage gaps, battery use and passengers who feel sick on a moving train.

On a train, connectivity is a bonus, not something to count on. Keeping the trip on the device, running animations on the UI thread and adapting the layout to the screen were enough to make the app work in the middle of a mountain tunnel.

Thanks to my teammates Tommaso Morganti and Luca Suzani, to the Trenord engineering team for their time and context, and to the DIMA course staff at Politecnico di Milano.

The code and the documentation are open source on GitHub(opens in a new tab).