Reactive Responsive Design in Practice: Part 2

Michael Madsen
ngconf
Published in
5 min readNov 16, 2020

--

Photo by Taras Shypka on Unsplash

In my last article, I introduced the concept of Reactive Responsive Design (a term created by me), what it is, how it works, and why it’s important. Now let’s take a look at how we can use it to build a responsive UI. To start we need a service.

The purpose of the service is to provide unified breakpoints for screen sizes. This will unify the breakpoints an app cares about with code rather than convention. There are 3 things that will need to happen in the service.

  1. Define the sizes we want tracked
  2. Provide an observable with a standardized interface
  3. Define specific states we care about (like mobile or tablet)

rxrs provides a service (called the ScreenSizeService) with reasonable defaults for this. In Angular you will want to use the rxrs-ng library so everything plays nicely with Angular.

To get set up, first run:

npm install rxrs rxrs-ng

Then import the ScreenSizeService into your component.

--

--