Universal
Murray aims at being Alan's universal Design System, with components behaving and looking the same way on both mobile and web. As of July 2023, only a subset of components have been migrated to a universal implementation.
Benefits of having universal components
- Consistency: by leveraging a single codebase, we can ensure a consistent user interface (UI) and user experience (UX) across both web and mobile applications. This helps in maintaining brand identity and improves usability.
- Code Reusability: components can be implemented once, and be reused in both web and mobile features. This significantly reduces development time and effort required for maintaining separate codebases.
- Efficiency: changes made to the component library will be reflected simultaneously on both web and mobile platforms, enabling faster feedback loops and quicker deployment cycles.
Technical implementation
We rely on React Native for Web to implement universal components once while being able to target both React DOM and React Native.
react-native-web is an accessible implementaion of React Native's components and APIs. It is built on top of a set of sane principles:
- Accessible HTML: support different devices and input modes, render semantic tags.
- High-quality interactions: support gestures and multiple input modes (touch, mouse, keyboard)
- Reliable styles: rely on scoped styles and automatic vendor-prefixing
- Responsive containers: respond to element resize events
- Incremental adoption: interoperates with existing React DOM components. Bundle only what you use
It is battle-tested (powering Expo, Twitter, ...) and has significantly impacted the development of React Native (accessibility features were recently introduced thank to react-native-web)
Specificities
These specificities are mostly abstracted away by Murray's implementation. However they are interesting to know to better understand our systems
Styling
Web and mobile platforms have different styling and layout systems. While CSS is used for web styling, React Native relies on its own styling system, which encapsulates CSS-like properties. It's important to understand these styling differences and adapt the component library's styles and layouts accordingly to ensure consistent visual rendering.
DOM elements
Our Universal components are compatible with both web and mobile platforms. As such we can't rely on DOM abstraction such as html tags (div, span, ...). We instead use React Native primitives (View, Text, ...) which are then rendering DOM elements.
Accessibiltiy and semanticics
This doesn't mean that we don't care about semantics, on the contrary. We can benefit from a single accessibility implementation that will handle specificies of 3 platforms (web, iOS, Android). You can refer to React Native Web documentation on the matter.
Universal Murray components do implement accessibility best practices (e.g. rendering Heading as the proper <h{1|2|...}> tag on web).
Platform-specific behaviors
While components should mostly look and behave the same way on all platforms, there are platform-specific behaviors (due to OS guidelines, technical constraints, ...). In these situations we can rely on:
- the
Platformmodule (from "react-native), providing aPlatform.OSto know if we're onweb|iosorandroid - platform-specific files. Suffixing a file with
.web.tsxor.native.tsxwill make sure that it is only loaded on the specified platform
You can see such examples in the Loader implementation, which relies on different Lottie libraries for web and mobile.